Config Server Firewall

Using apachectl to Control Apache Web Server in Linux

In this tutorial we will learn how to use apachectl command to manage Apache HTTP Server on Linux. The apachectl commands include with the Apache installation in all major Linux distributions, including Debian, Ubuntu, CentOS 7, Red Hat and Fedora. With it, you can start, stop, and restart the HTTP daemon on your web server.

Command Options

start Start the Apache HTTP Server.
stop Stop the Apache HTTP Server.
restart Restart the Apache Web Server, If the Server is not running apachectl will start the server.
fullstatus Display Full status report.
status Display brief status of the web server.
graceful graceful restart, reload the apache configuration without interrupting currently established connections.
graceful-stop Stop the server without aborting currently open connections.
configtest Check the Apache configuration files for the syntax errors.

Examples

To start Apache, open the terminal and type:

sudo apachectl start

To restart the Web Server, run:

sudo apachectl restart

The graceful command will restart the apache web server without interrupting current open connections and Open connections are allowed to complete before being shut down. This is A better way to restart the web server after a change to the configuration file.

sudo apachectl graceful

Even though you can start and restart apache server with apachectl command, I would highly recommend to use systemctl command instead.

On debian, Ubuntu Linux:

systemctl start|restart|stop apache2.service

On Red Hat, CentOS 7 and Fedora:

systemctl start|restart|stop httpd.service

Apachectl Configtest: Test configuration files for errors

One important use of apachectl is the configtest command. The configtest command will cause Apache to read the config files and report any configuration errors.

The apache server will not start if you have syntax errors in your configuration files. Same with the restart, it will ignore the restart signal and continue running with old configuration. So it is highly recommended to run apachectl configtest each time you make changes to configuration files.

To run config test with apachectl, type:

sudo apachectl configtest

If everything is ok, the configtest command will return the message Syntax OK.

If there is a syntax error, configtest will output the invalid configuration option with the filename and the line number.

Apachectl Configtest: Test configuration files for errors

The configtest function is also used by the restart and graceful commands to validate the configuration before shutting down the httpd process.

Could not reliably determine the server's fully qualified domain name

You may receive an error message reporting that "Could not reliably determine the server's fully qualified domain name". This not an error just a warning message, you may ignore this and will not cause any problem for your web server.

Could not reliably determine the server's fully qualified domain name

If you want to get rid of this warning, set the ServerName directive to localhost in the main configuration file.

ServerName localhost

In Debian and Ubuntu Linux, main configuration file is /etc/apache2/apache2.conf. In Red Hat, CentOS and Fedora, main configuration file is /etc/httpd/conf/httpd.conf.

Note that, apachectl command need root or sudo privileges to perform administrative tasks such as start and restarting the web server.