ManyCodes.com – codes & scripts Get free programming codes and tutorials!

10Aug/090

Ubuntu Linux Start / Restart / Stop Apache 2.2 Web Server

Q. How to restart or stop Apache 2.2 web server under Ubuntu Linux?

Task: Start Apache 2.2 Server

# /etc/init.d/apache2 start

or

$ sudo /etc/init.d/apache2 start

Task: Restart Apache 2.2 Server

# /etc/init.d/apache2 restart

or

$ sudo /etc/init.d/apache2 restart

Task: Stop Apache 2.2 Server

# /etc/init.d/apache2 stop

or

$ sudo /etc/init.d/apache2 stop
10Aug/091

Apache performance tips

If you run the command top on your box and the CPU is mostly idle and there is plenty of memory available, and yet Apache seemed sluggish. Here are a couple of things I would recommend to speed things up.

1. Increase MaxClients and ServerLimit

This is a well-known Apache performance optimization tip. Its effect is to increase the number of httpd processes available to service the HTTP requests.

However, when I tried to increase MaxClients over 256 in the prefork.c directives and I restarted Apache, I got a message such as:

WARNING: MaxClients of 1000 exceeds ServerLimit value of 256 servers, lowering MaxClients to 256. To increase, please see the ServerLimit directive.

There is no ServerLimit entry by default in httpd.conf, so I proceeded to add one just below the MaxClients entry. I restarted httpd, and I still got the message above. The 2 entries I had in httpd.conf in the IfModule prefork.c section were:
ServerLimit 1000
MaxClients 1000
(make sure that serverlimit comes before maxclients)

At this point I resorted to all kinds of Google searches in order to find out how to get past this issue, only to notice after a few minutes that the number of httpd processes HAD been increased to well over the default of 256!

Note: It turns out that the new MaxClient and ServerLimit values take effect only if you stop httpd then start it back again. Just doing a restart doesn't do the trick...

So, lesson learned? Always double-check your work and, most importantly, know when to ignore warnings 🙂

Now I have a procedure for tuning the number of httpd processes on a given box:

1. Start small, with the default MaxClients (150).
2. If Apache seems sluggish, start increasing both MaxClients and ServerLimit; restart httpd every time you do this.
3. Monitor the number of httpd processes; you can use something like:

ps -def | grep httpd | grep -v grep | wc -l

If the number of httpd processes becomes equal to the MaxClients limit you specified in httpd.conf, check your CPU and memory (via top or vmstat). If the system is not yet overloaded, go to step 2. If the system is overloaded, it's time to put another server in the server farm behind the load balancer.

That's it for now. There are many other Apache performance tuning tips that you can read from the official Apache documentation here.

8Aug/090

Star / Stop / Restart Apache 2 Web Server

Q. How do I restart Apache 2 Web Server under Debian / Ubuntu Linux?


A. Apache is primarily used to serve both static content and dynamic Web pages on the World Wide Web. Many web applications are designed expecting the environment and features that Apache provides.

First, login to server using ssh. To ssh to your server, you will need to a ssh client like putty (download putty from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html).

The ssh client will need you to enter the IP, username and password of your server. Choose port as 22.
Once logged in type the following commands as need be.

How To start Apache 2 web server, enter:

# /etc/init.d/apache2 start

OR

$ sudo /etc/init.d/apache2 start

Linux Command to restart Apache 2 web server, enter:

# /etc/init.d/apache2 restart

If you are using Ubuntu use sudo:

$ sudo /etc/init.d/apache2 restart

How To stop Apache 2 web server, enter:

# /etc/init.d/apache2 stop

OR

$ sudo /etc/init.d/apache2 stop