Make Apache Faster
Posted by Nessa | Posted in apache,php,tutorials,uncategorized | Posted on May 9, 2007
5
Apparently someone thinks that my website is too slow in its load time. I never really thought it was that bad, but his little handy danty Firefox plugin claims that it takes my site approximately 6-7 seconds to load initially, which kinda sucks. I know that I’ve written some stuff on optimizing php performance and I tell customers on a daily basis how to keep their sites from bogging down our servers, but I never really cared to optimize my own site because I have a v-dedicated server. So anyways, I’ve made a few modifications to both my site and the server environment to help speed things up a bit.
You might want to read my article on Optimizing PHP as well.
Enable Compression with Apache
If you are running on Apache 2, mod_deflate should already be installed on your system — all you have to do is enable it. I recently downgraded my server back to Apache 1.3.37 (mainly because of cPanel) so I’m using the mod_gzip alternative. Basically, mod_gzip compresses the contents of your site server-side and then passes the file onto your compression-enabled browser to decompress the file. The overhead on the server may be slightly higher during heavier traffic times, but you’ll find yourself saving bandwidth and load time since the server is passing less data between it and your clients.
To install mod_gzip on Apache:
wget http://easynews.dl.sourceforge.net/sourceforge/mod-gzip/mod_gzip-1.3.26.1a.tgz
tar -zxvf mod_gzip-1.3.26.1a.tgz
cd mod_gzip-1.3.26.1a
If you’re on a cPanel system, you’ll need to modify the path to apxs:
pico Makefile
Change APXS?=/usr/local/sbin/apxs to APXS?=/usr/local/apache/bin/apxs
Then just do the normal make && make install
Now enable the dynamic modules in the Apache config:
pico /usr/local/apache/conf/httpd.conf
Uncomment out these lines:
#LoadModule gzip_module libexec/mod_gzip.so
#AddModule mod_gzip.c
Now all you need to do is restart Apache as normal. To see if compression is working on your site, just hop on over to this page and run the test.
Change The KeepAliveTimeout
By default your Apache configuration will probably have keep connections alive for up to 15 seconds before they die off. For busier sites this can be a little too long. I suggest setting this to 3 or 5 seconds in your httpd.conf.
Adjust the PHP Output Handler
Your PHP scripts are constantly recompiiling themselves every time a page is loaded. If your site is heavily reliant on PHP, you may find it beneficial to have PHP send its output to a compression function in your php.ini
output_handler = ob_gzhandler
Check Your resolv.conf
It’s obvious that your settings are fine if your site and email are working, but your resolver may not be set to do the fastest lookups. If you have a caching or local nameserver, you will want that listed first in /etc/resolve.conf . I’ve seen a drastic decrease in performance on some customer VPS’s because the servers were doing DNS lookups through external nameservers. I have dedicated nameservers, so my resolve.conf looks like this:
search v-nessa.net
nameserver 205.134.252.71
nameserver 4.2.2.1
nameserver 4.2.2.3
Optimize!
One of the major changes I made on my site was to the image and page sizes… I did a lot of code and image compression to decrease the amount of time it takes to load my site. A majority of this consisted of simply saving my images in .gif or .png formats and removing plugins and includes that were not needed.
No related posts.














Just a thought. Gzip, while it will often help, also takes tons of CPU horses. So on a busy server, this could end up being a real problem.
Likewise, basic optimization of MySQL and Apache will help you, but out of the box configs are usually enough for average sites. However if you have permissions to optiize httpd.conf or my.cnf, chances are you have enough traffic to justify significant boosts.
Lately, I’ve taken more of the approach of optimizing httpd requests as well as third party sources. Javascript files can be compressed by removing whitespace. CSS can also be streamlined in this way, though you may want to hack around more in that for the future so this might not be the best solution.
If you run a WordPress blog, having WP-Cache is going to do crazy amounts for speed. In fact, any way you can cache stuff on the server end, is usually a good bet.
Great write up, though!
Is this possible to do if you are running apache 1 or you need to have apache 2 a requirement?
At the time I wrote this post I was on Apache 1, but this would apply to Apache 2 as well. Only I think gzip was replaced with mod_deflate.
Can anyone suggest a reliable Dedicated Server hosting that is not very expensive?’-`
If you want reliable dedicated hosting, you’d need to expect to pay a little bit more. See http://inmotion.net/dedicated_servers.html .
Most hosts I’ve see that charge less than $200 a month for a dedicated server either use crappy generic servers, or make you pay for extras like cPanel, OS installation, support, etc.