FreeKB - How to start and stop Linux Apache web server
How to start and stop Linux Apache web server

Home > Search > How-to


apachectl or systemctl can be used to start, restart, and stop an Apache web server. There are a number of different Apache web servers, such as Apache, HTTPD, and IBM IHS, just to name a few. As long as the web server contains the apachectl command, you should be able to use the apachectl command to restart the web server.

 


Start a single web server instance

Use the apachectl -k start command to start an Apache web server.

~]# web_server_root/bin/apachectl -k start

 


Restart a single web server instance

Use the apachectl -k restart command to restart an Apache web server.

~]# web_server_root/bin/apachectl -k restart

 


Stop a single web server instance

Use the apachectl -k stop command to stop an Apache web server.

~]# web_server_root/bin/apachectl -k stop

 


Stop / Start / Restart muliple web servers

If you have two or more web servers on the same machine, you should have an httpd conf file for each web server.

/opt/IBM/HTTPServer/conf/httpd.server1.conf
/opt/IBM/HTTPServer/conf/httpd.server2.conf

 

apachectl with the -f option can be used to stop / start / restart a single web server. In this example, only web server1 is started.

~]# /opt/IBM/HTTPServer/bin/apachectl -k start -f /opt/IBM/HTTPServer/conf/httpd.server1.conf

 

Or, the systemctl command can be used to stop / start / restart every web server instance. The "apache_client90" script simply invokes the ${ihs_install_root}/scripts/client90 script to start or stop an instance. In turn, the client90 script invokes apachectl to restart every instance in the httpdInstance90.lst file.

~]# systemctl stop apache_client90
~]# systemctl start apache_client90
~]# systemctl restart apache_client90

 

After issuing the "systemctl restart apache_client90" command, if systemctl status returns "Active: failed (Result: exit-code) since yyyy-mm-dd hh:mm:ss timezone; xs ago", check the logs for apache events.

journalctl | grep apache

 

I have seen instances where the logs have "address already in use" when the httpd server is configured to listen on a port other than 80. In this example, the httpd server is listening on port 18081. When I've seen this, using "systemctl stop apache_client90" and then "systemctl start apache_client90" resolves the issue. Perhaps the "restart" option does not give apache enough time to destroy the socket.

Address already in use: AH00072: make_sock: could not bind to address [::]:18081
Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:18081

 


Verification

Once started, you should be able to get your home page.

 

systemctl can be used to ensure all of the web server instances are running.

~]# systemctl status apache_client90
. . .
  Active: active (running) since yyyy-mm-dd hh:mm:ss timezone; xs ago

 

The ps command can be used to verify that the web server has started.  What you want to first check to is to see if there are one or more processes associated with the httpd.conf file. If not, the web server is not running. If so, you next want to see when the web server was started. In this example, the web server was started at 7:04 am today.

~]# ps -ef | grep httpd
nobody  12345  1234  0  07:04  ?  00:00:00 -f /path/to/httpd.conf -k start
nobody  12345  1234  0  07:04  ?  00:00:00 -f /path/to/httpd.conf -k start
nobody  12345  1234  0  07:04  ?  00:00:00 -f /path/to/httpd.conf -k start
nobody  12345  1234  0  07:04  ?  00:00:00 -f /path/to/httpd.conf -k start

 

If you've configured an admin server, there may also be processes for the admin server, which are identified by the admin.conf file. The admin server and apache web server are separate processes. Typically, you want to ignore the processes associated with the admin server.

~]# ps -ef | grep httpd
nobody  12345  1234  0  07:04  ?  00:00:00 -f /path/to/admin.conf -k start
nobody  12345  1234  0  07:04  ?  00:00:00 -f /path/to/admin.conf -k start
nobody  12345  1234  0  07:04  ?  00:00:00 -f /path/to/admin.conf -k start
nobody  12345  1234  0  07:04  ?  00:00:00 -f /path/to/admin.conf -k start

 

If the web server fails to start, use the nslookup command to determine if DNS is able to resolve the hostname to an IP address. If not, DNS will need to be configured.

C:\> nslookup www.example.com
Server:   ns1.example.com
Address:  10.80.140.51

Non-authoritative answer:
Name:    www.example.com
Address:  10.81.146.140

 

Also ensure the httpd.conf file is listening on port 80, and has the IP address of the operating system.

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




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




Comments