You need to restart your Apache service for any changes you made to the config file to be effective. You must then test your Apache config for errors before restarting the service, as it could fail to start and disrupt the availability of the websites it is hosting.

Apache has a built-in feature to test the validity of the config file that you can use to catch errors or warnings. You can repeatedly check the configuration files until all the errors and warnings are gone before restarting the service.

You can use both apachectl and httpd tools to test your Apache configuration from the terminal.

Steps to test Apache configuration without restarting service:

  1. Launch your preferred terminal application.
  2. Edit Apache configuration file using your preferred text editor.
    $ sudo vi /etc/apache2/apache2.conf
  3. Test Apache configuration file syntax using apachectl or similar binaries.
    $ sudo apachectl configtest
    AH00543: apache2: bad user name username
    Action 'configtest' failed.
    The Apache error log may have more information.

    Use -t option instead of configtest if you're using httpd or apache and not apachectl

  4. Continue editing and testing your Apache configuration until the configtest option reports no error.
    $ sudo apachectl configtest
    Syntax OK
  5. Restart Apache service for the changes to take effect.
    $ sudo systemctl restart apache2 # Ubuntu, Debian, openSUSE and SLES
    $ sudo systemctl restart httpd # CentOS and Red Hat
Discuss the article:

Comment anonymously. Login not required.

Share!