How do I find out syntax errors in my Apache web server configuration file?

Apache web server support special syntax checking. You can run syntax tests for configuration files only. Following two are important syntax checker option you can pass to apache binary program httpd (Red Hat/ Fedora Linux) or apache-perl (Debian Linux apache binary):

ADVERTISEMENTS

Executing the following command, that will detect syntax errors:

If you are using Debian Linux:

# /usr/sbin/apache-perl -t

Syntax OK

If you are using Red Hat Linux:

# /usr/sbin/httpd -t

Syntax OK

Where,

  • -t : The program immediately exits after these syntax parsing with either a return code of 0 (i.e. Syntax OK message) or return code not equal to 0 (i.e. Syntax Error message).

Consider following example:

# /usr/sbin/apache-perl -t

Warning: DocumentRoot [/data/network/www/blogs] does not exist
Syntax OK

Replace it with -T option:

/usr/sbin/apache-perl -T

Syntax OK

The option -T is same as option -t but does not check the configured document roots (warning message disappeared).

Another example:

# /usr/sbin/apache-perl -t -S

Syntax error on line 1059 of /etc/apache-perl/httpd.conf:
Invalid command ‘CustomLogl’, perhaps mis-spelled or defined by a module not included in the server configuration

As you see error on line number 1059 need to be fixed. Use vi text editor:

# vi +1059 /etc/apache-perl/httpd.conf

After correction again retype command:

# /usr/sbin/apache-perl -t –S

Output:

VirtualHost configuration:
192.168.1.1:80         is a NameVirtualHost
                      default server cyberciti.biz (/etc/apache-perl/httpd.conf:1053)
                      port 80 namevhost cyberciti.biz (/etc/apache-perl/httpd.conf:1053)
                      port 80 namevhost apps.cyberciti.biz (/etc/apache-perl/httpd.conf:1062)
                      port 80 namevhost dl.cyberciti.biz (/etc/apache-perl/httpd.conf:1069)
                      port 80 namevhost blogs.cyberciti.biz (/etc/apache-perl/httpd.conf:1076)
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.