Bootstrap FreeKB - Apache (Web Server) - Start Stop Restart web server using the apachectl command
Apache (Web Server) - Start Stop Restart web server using the apachectl command

Updated:   |  Apache (Web Server) articles

The apachectl or command can be used to start, stop, and restart an Apache web server.

<web_server_root>/bin/apachectl -k restart
<web_server_root>/bin/apachectl -k start
<web_server_root>/bin/apachectl -k stop
<web_server_root>/bin/apachectl -k graceful
<web_server_root>/bin/apachectl -k graceful-stop

 

The above command will use the <web_server_root>/conf/httpd.conf file. The -f option can be used to specify some other conf file, like this.

<web_server_root>/bin/apachectl -k start -f conf/foo.conf

 

The -e option followed by a log level (such as debug) can be used to output additional details to the console and to the error_log.

<web_server_root>/bin/apachectl -e debug -k restart

 

Likewise, you can use the -X flag to debug a web server instance.

]# <web_server_root> -k start -X
/opt/IBMIHS90/bin/apachectl: line 96: 34966 Segmentation fault      (core dumped) $HTTPD "$@"

 

The ps command can be used to determine if the web server is running. If the web server is running, the ps command should return processes associated with the web server. If the ps command fails to return any output, check the web server error_log.

Note

Notice the ps command returns "httpd" processes. apachectl is a wrapper script that invokes the httpd command to start, stop, or restart the web server, thus you could use the httpd command instead.

ps -ef | grep httpd
. . .
root      2330     1  0 21:41 ?        00:00:00 /path/to/bin/httpd -d /path/to -k start
nobody    2333  2330  0 21:41 ?        00:00:00 /path/to/bin/httpd -d /path/to -k start
nobody    2334  2330  0 21:41 ?        00:00:00 /path/to/bin/httpd -d /path/to -k start
nobody    2335  2330  0 21:41 ?        00:00:00 /path/to/bin/httpd -d /path/to -k start

 

When the ps command displays processes associated with the web server, you should be able to request resources from the web server. By default, the httpd.conf file has the following.

ServerName localhost:80
Listen 80

 

With this configuration, you should be able to enter the hostname of your web server in a browser and the following should be displayed.

 


Multiple web server

If you have two or more web servers on the same machine, you will have a unique conf file for each web server, like this.

<web_server_root>/conf/httpd1.conf
<web_server_root>/conf/httpd2.conf

 

The -f option can be used to target a specific web server. In this example, only the web server using httpd1.conf will be restarted.

<web_server_root>/bin/apachectl -k restart -f <web_server_root>/conf/httpd1.conf

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 822117 in the box below so that we can be sure you are a human.