How to start and stop Linux Apache web server

Home > Search > How-to
  by

The apachectl command 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 the web server

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

~]# web_server_root/bin/apachectl -k start

 


Restart the web server

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

~]# web_server_root/bin/apachectl -k restart

 


Stop the web server

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

~]# web_server_root/bin/apachectl -k stop

 


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

 

The -f option can be used to only 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

 


Verification

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

 

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