Speed up your website for better search enigine results
Nobody likes a slow website. Visitors leave early and add revenue decreases. Fortunately computers are fast and can serve websites with great speed provided they are properly configured. In this paper we will give you tips on how to squeeze the most out of your hardware
We assume that your primary webserver is apache and your scripting language is PHP. However this guide will work for other (or no) scripting languages.
Webserver
Apache is the most used webserver and it is one of the fastest, best documented and secure webservers. However it has it's flaws. If apache gets too bust your entire website will slow down. Therefor the first thing that you will need to do is get rid of everything that you do not need.
- Disable htaccess override
- Remove all unused mods (/etc/apache/mods_enabled)
- Disable logging
- Disable nslookups
- Use http compression (unless you are using a reverse proxy, in wich case the proxy should compress http data)
Dynamic content
Apache is great for serving dynamic content. The fastest way of serving your dynamic content (PHP or Python) is by using mod PHP or mod Python. These mods will load the entire php/pyhton executable into your apache webserver. This has the advantage that no new processes have to be created with each request (since apache has allready stated running, probably several times). On the scripting side however a few simple improvements can speed up your website by more the a 1000%
- Cache generated pages !
- Use an opcache accelarator (apc)
- Procedural code is faster then object oriented code (but hard to maintain). There is no shame in rewriting high traffic pages to procedural code.
- Take a good look at your database queries. Database abstraction allmost allways handles database requests in a suboptimal way.
Static content
Static content should not be served by apache. Apache is big and consumes large amounts of memory. Any of the smaller webservers (nginx, lighttpd) can serve static content in a fraction of time and can handle lots more simultanious requests. There are a few ways of accompleshing this.
- Use another domain/server/port for static content
- Use a caching proxy
- Set an expiration date far in the future (1 year)
A live example
For one of our custimers we were asked to improve their page speed. With the following simple changes wich were no more then 15 minuted work we cut the page loading time in half
- We used nginx as a reverse caching proxy for apache on port 80
- We reassigned apache to port 8080 listening to 127.0.0.1 (localhost)
- We let nginx handle all static requests
- All php requests were forwarded to apache on port 8080
- We served all static content from a cookieless domain
- We disabled apache logging
- We disabled apache rewrite, content negotiation, fastcgi and a few others
- We let nginx handle all rewrites, compression and static content expiration
Analyse your website !
| Please enter your domain name |