Everything in Linux is a file.
All software and hardware devices are configured with the .conf
file to work.
If you make any changes to it, you have to restart a service to take the changes effect.
If you make changes incorrectly, it will not allow you to restart the associated service.
When you try to restart them, it will result in an error and it will not allow you to bring up the related service.
So when you make any changes to the configuration file, it is advisable to back up the configuration file.
If you want to install Apache on Linux, see the following article.
If you have a backup, it allows you to restore them into the previous state If something went wrong.
Do not place the backup file in the same location as the actual configuration file, which may cause some other problems, so move it elsewhere.
Apache is offering a small syntax checking tool. It allows you to run a configuration file syntax test.
It parses the configuration files and either reports Syntax Ok or detailed information about the particular syntax error.
The apachectl script returns a 0 exit value on success, and >0 if an error occurs.
1) How to Find Apache Configuration Syntax on CentOS/Red Hat/Fedora Systems
Use the following command to check for Apache syntax errors on RHEL-based systems such as Centos and Fedora.
This can be done using the httpd command or the apachectl command.
How to Check Apache Configuration Syntax on Linux Using the httpd Command.
# httpd -t Syntax OK
How to Check Apache Configuration Syntax on Linux Using the apachectl Command.
# apachectl configtest Syntax OK # apachectl -t Syntax OK
1a) How to Find Apache Virtual Host Definitions on CentOS/Red Hat/Fedora Systems
It has another option to check all virtual hosts on the server, their options, and the file names and line numbers that they defined.
This will display an error message with the line number, which is very useful for troubleshooting the configuration file.
It can be done using the httpd command or the apachectl command.
How to Check Apache Configuration Syntax on Linux Using the httpd Command.
# httpd -S VirtualHost configuration: ServerRoot: "/etc/httpd" Main DocumentRoot: "/srv/http" Main ErrorLog: "/var/log/httpd/error_log" Mutex default: dir="/run/httpd/" mechanism=default PidFile: "/run/httpd/httpd.pid" Define: DUMP_VHOSTS Define: DUMP_RUN_CFG User: name="http" id=33 not_used Group: name="http" id=33 not_used
How to Check Apache Configuration Syntax on Linux Using the apachectl Command.
# apachectl configtest or # apachectl -S VirtualHost configuration: 192.168.1.6:80 is a NameVirtualHost default server ns1.2daygeek.com (/etc/apache2/conf/httpd.conf:301) port 80 namevhost ns1.2daygeek.com (/etc/apache2/conf/httpd.conf:301) port 80 namevhost magesh.co.in (/etc/apache2/conf/httpd.conf:362) alias mail.magesh.co.in alias www.magesh.co.in port 80 namevhost linuxtechnews.com (/etc/apache2/conf/httpd.conf:431) alias mail.linuxtechnews.com alias www.linuxtechnews.com . . 192.168.1.6:443 is a NameVirtualHost default server magesh.co.in (/etc/apache2/conf/httpd.conf:14467) port 443 namevhost magesh.co.in (/etc/apache2/conf/httpd.conf:14467) alias mail.magesh.co.in alias www.magesh.co.in alias webmail.magesh.co.in alias cpanel.magesh.co.in alias webdisk.magesh.co.in port 443 namevhost linuxtechnews.com (/etc/apache2/conf/httpd.conf:14581) alias mail.linuxtechnews.com alias www.linuxtechnews.com alias webmail.linuxtechnews.com alias cpanel.linuxtechnews.com alias webdisk.linuxtechnews.com . . ServerRoot: "/etc/apache2" Main DocumentRoot: "/etc/apache2/htdocs" Main ErrorLog: "/etc/apache2/logs/error_log" Mutex mpm-accept: using_defaults Mutex rewrite-map: dir="/run/apache2" mechanism=fcntl Mutex ssl-stapling-refresh: using_defaults Mutex ssl-stapling: using_defaults Mutex proxy: using_defaults Mutex ssl-cache: dir="/run/apache2" mechanism=fcntl Mutex default: dir="/var/run/apache2/" mechanism=sysvsem PidFile: "/run/apache2/httpd.pid" Define: DUMP_VHOSTS Define: DUMP_RUN_CFG Define: MODSEC_2.5 Define: MODSEC_2.9 User: name="nobody" id=99 Group: name="nobody" id=99
2) How to Find Apache Configuration Syntax on Ubuntu and Debian Systems
Use any of one below command to check apache syntax error on Debian based systems such as Ubuntu and LinuxMint.
It can be done using the apachectl command or the apache2ctl command.
How to Check Apache Configuration Syntax on Linux Using the apachectl Command.
# apachectl configtest Syntax OK # apachectl -t Syntax OK
How to Check Apache Configuration Syntax on Linux Using the apache2ctl Command.
# apache2ctl configtest Syntax OK # apache2ctl -t Syntax OK
2a) How to Find Apache Virtual Host Definitions on Linux
The similar way that we can check it on Debina and Ubuntu systems.
It can be done using the apachectl command or the apache2ctl command.
How to Check Apache Configuration Syntax on Linux Using the apachectl Command.
# apachectl configtest or # apachectl -S
How to Check Apache Configuration Syntax on Linux Using the apache2ctl Command.
# apache2ctl configtest or # apache2ctl -S