What are some basic Apache performance optimizations?

Hi, I installed a basic LAMP (Ubuntu 12.04 LTS, Apache 2.2.22, MySQL 5.5.24, PHP 5.3.10), and am running a MediaWiki installation here in addition to some mostly static content. Things are running fine since my traffic is modest, but I'd be interested in implementing whatever basic performance optimizations almost everybody should be running so users have a better experience.

For example, my MediaWiki page cut about 200ms off the ping of a page that needed to query the database after enabling PHP APC–as compared to no caching. Some of the Apache modules installed include:

-cloudflare_module

-deflate_module; installed by default, but I have not configured anything, so I'm not sure if it's actually sending compressed output

-expires_module; installed, and I tried to configure via /etc/apache2/sites-available/domain.com with "access plus 7 days" configuration, but it doesn't seem to have made an appreciable difference

-include_module

-rewrite_module

Suggestions for whatever modules and performance tweaks you always do would be very welcome--thanks!

6 Replies

Since you're running Ubuntu 12.04, you can use PHP-FPM to move PHP processing out of Apache. This is generally a very good idea.

Caching. Why load dynamic modules when the content you are generating is staying static? This should vastly improve page load times and reduce i/o, memory, and CPU footprints.

@hoopycat:

Since you're running Ubuntu 12.04, you can use PHP-FPM to move PHP processing out of Apache. This is generally a very good idea. Thanks. I'm giving it a shot, but I've misconfigured something. I've tried referring to the guides at

http://www.howtoforge.com/using-php5-fp … -12.04-lts">http://www.howtoforge.com/using-php5-fpm-with-apache2-on-ubuntu-12.04-lts and http://alexcabal.com/installing-apache- … -maverick/">http://alexcabal.com/installing-apache-mod_fastcgi-php-fpm-on-ubuntu-server-maverick/. Here are the steps I used:

sudo apt-get install libapache2-mod-fastcgi php5-fpm php5

sudo a2enmod actions fastcgi alias

sudo service apache2 restart

sudo nano /etc/apache2/sites-available/dryang.org

inserted this between and :

AddHandler php5-fcgi .php

Action php5-fcgi /php5-fcgi

Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi

FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization


Alternatively, I've also tried:

FastCgiExternalServer /srv/www/dryang.org/public_html/php5.external -host 127.0.0.1:9000

AddHandler php5-fcgi .php

Action php5-fcgi /usr/lib/cgi-bin/php5.external

Alias /usr/lib/cgi-bin/ /srv/www/dryang.org/public_html/


However, with either one, I still get "Server API: Apache 2.0 Handler." Can anyone pick out what mistake I've made? apache2ctl -M lists fastcgi_module (shared), so it seems that it's enabled, just not configured to be used.

ps aux shows that things are loaded up:

root     28362  0.0  0.7  77060  3928 ?        Ss   16:07   0:00 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)
www-data 28363  0.0  0.6  77060  3120 ?        S    16:07   0:00 php-fpm: pool www
www-data 28364  0.0  0.6  77060  3120 ?        S    16:07   0:00 php-fpm: pool www
www-data 28365  0.0  0.6  77060  3120 ?        S    16:07   0:00 php-fpm: pool www
www-data 28366  0.0  0.6  77060  3120 ?        S    16:07   0:00 php-fpm: pool www
www-data 28528  0.0  0.7  31456  4044 ?        S    16:34   0:00 /usr/sbin/fcgi-pm -k start

/var/log/php5-fpm.log shows:

[22-Jul-2012 16:08:00] NOTICE: fpm is running, pid 28362
[22-Jul-2012 16:08:00] NOTICE: ready to handle connections

Edit: Success! Thanks to heckman in IRC for pointing out that I needed to disable mod_php:

sudo a2dismod php5

Using the "Alternatively, I've also tried" lines and restarting Apache results in: Server API: FPM/FastCGI.

@A-KO:

Caching. Why load dynamic modules when the content you are generating is staying static? This should vastly improve page load times and reduce i/o, memory, and CPU footprints. Yep, I'd love to implement additional caching, but I don't know which direction to turn to. Is there a specific implementation or guide that you can suggest?

Thank you for your help!

What's the best way to optimize apache? By not using it. If you start getting any decent amount of traffic usually apache starts to fall apart.

If you need a drop in apache replacement I recommend Litespeed. Which is a commercial product.

Otherwise ngnx or lighttpd are other good options.

@yaz:

Edit: Success! Thanks to heckman in IRC for pointing out that I needed to disable mod_php:

sudo a2dismod php5

Using the "Alternatively, I've also tried" lines and restarting Apache results in: Server API: FPM/FastCGI.

Thank you for your help!

****Hi

Can you tell me how you disabled mod_php? I tried Googling and I found a website that explained how to do it, but when I tried their instructions, it did not work. I also noticed it is in a different language, so I may have to use someone's**** translation services *to translate it to English.*

@empoweringmedia:

If you start getting any decent amount of traffic usually apache starts to fall apart.
Define "decent".

With a properly configured LAMP stack, Apache does ok.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct