Improve performance and speed in Apache

We have given some ideas about how to gain performance in some Apache tasks such as redirection.

In this post, I would like to point out some basic ideas about improving performance with an Apache server. I will refer to version 2.2. running in Ubuntu server 12.04 32 bits.

1. Activate the Apache Cache

Apache has several modules that provide cache services. This guide explains a little bit the modules available: http://httpd.apache.org/docs/2.2/caching.html.

And DigitalOcean provides a more practical look at it with straightforward tips https://www.digitalocean.com/community/articles/how-to-configure-content-caching-using-apache-modules-on-a-vps

So the simplest approach is to enable the module:

sudo nano /etc/apache2/mods-available/mem_cache.conf

where you will see the configuration. I have not changed nothing for the moment.

And then, make it run:

sudo a2enmod mem_cache

service apache2 restart

This part so far is covering the Memory Cache. I will not talk about the Disk Cache, since I am using the WordPress SuperCache plugin and would not like to have a conflict between both.

2. Allow Override none Directive

If you have set “Allow Override none” then Apache will look in every folder to find an .htaccess file. But it is most likely that you only have one .htaccess file, and not a whole cascade of .htaccess files, so, why not put it in the configuration file and save time? the benchmark shown by the excellent post by ESchrade http://www.eschrade.com/page/why-you-should-not-use-htaccess-allowoverride-all-in-production/ is very convincing. This idea is also reinforced by this post https://www.tinywp.in/move-htaccess-rule-to-apache-conf/

This action is also recommended in this great post with tips for improving Apache speed https://servercheck.in/blog/3-small-tweaks-make-apache-fly

3. Use third party cache software

If you are using WordPress, it is highly recommended to use the WordPress SuperCache Plugin. More info here http://ocaoimh.ie/wp-super-cache/

There is also a more generic option, called Varnish, https://www.varnish-cache.org/, and also a nice configuration guide by Donncha Ó Caoimh http://ocaoimh.ie/2011/08/09/speed-up-wordpress-with-apache-and-varnish/.

4. Offload unused modules

This is thoroughly explained here https://www.digitalocean.com/community/articles/how-to-optimize-apache-web-server-performance. As well as other great ideas such as

5. Reduce number of connections

Same link as above.

6. Set the right number of MaxClients

In short, this is the formula that you have to use to calculate the number of MaxClients:

(Total RAM – RAM used for Linux, MySQL, etc.) / Average httpd process size

There is a script here that will help you to get this for your server: http://cloudinservice.com/tune-apache-performance-using-mpm-prefork-module/

More details on this can be found in this link: https://servercheck.in/blog/3-small-tweaks-make-apache-fly

7. KeepAlive On or KeepAlive Off?

This is not an easy one, I have turned it to KeepAlive Off, and the server works much better now. If you want a detail explanation check out:

https://servercheck.in/blog/3-small-tweaks-make-apache-fly

http://abdussamad.com/archives/169-Apache-optimization:-KeepAlive-On-or-Off.html

8. Define Spare Servers

In this post there is a useful guide for that: http://cloudinservice.com/tune-apache-performance-using-mpm-prefork-module/

******

Do you know of other ways of improving Apache performance? Please get in touch with us and help us complete this guide!

Advertisements

Disable autoindex in Apache

It is quite annoying and can be a security problem if visitors can see the content of a folder while browsing your site.

I have found three ways of managing this

1. Disabling the module globally

a2dismod autoindex
or
sudo a2dismod autoindex
if in Debian or Ubuntu

2. Changing it with a line in the .htaccess of the folder

two options:
Options -Indexes
that will show as forbidden

or

IndexIgnore *
that will show it as empty

3. Modifying the /etc/apache2/sites-enabled/default

where you see:


Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all

Remove “Indexes”

More info here:
http://www.mywebexperiences.com/2013/05/20/how-to-disable-directory-listing-in-apache/

mysql keeps crashing, how to solve it?

I am using a very simple digitalocean basic server with 512mb RAM, and using Ubuntu 12.04 64bits

I tried the recommendations here:

https://www.digitalocean.com/community/questions/mysql-on-ubuntu-keeps-crashing

But still keeps crashing, so I have looked for further information, and this one seems to be a good guide to tweak the server, both apache and mysql:

https://library.linode.com/troubleshooting/memory-networking#sph_apache-2-low-memory-settings

I think that the key point for me is that I chose Ubuntu 64 bits without being aware that 64 bits Ubuntu takes around 50% more memory than 32 bits

So now I guess the solution is to downgrade to a 32bit server, which will be a bit of a pain… but if this solves the performance issue, then I will surely do it.

 

 

optimizing the web

looking at this great tutorial by the Code School guys. I already had a lot of fun with the Rails for Zombies tutorial.

Check this one out here: http://discover-devtools.codeschool.com/

Some ideas I’m taking away:

– optimize javascript with google clojure

– consider making async call to javascript

In the server

– compression: use this for apache http://www.linux-faqs.info/apache/optimize-website-speed-with-mod-expire-and-mod-deflate

and this for rails http://stackoverflow.com/questions/10955771/why-is-my-jscss-not-compressed-in-production-on-rails-heroku (just add

use Rack::Deflater

And keep-alive… i leave this for another day!

Enabling Apache logs in MAMP Pro

MAMP Pro uses a template to configure the apache configuration file. So you have to open MAMP  Pro and open templates apache, as described here

http://documentation.mamp.info/en/mamp-pro/advanced-functions/edit-configuration-files

Then change the lines as explained here

http://documentation.mamp.info/en/mamp/faq/where-can-i-find-the-logs/how-can-i-enable-the-apache-access-logs

and restart apache!

You will now be able to see the logs in real time using
tail -f /Applications/MAMP/logs/apache_access.log