Over the last few days I started digging into how to optimize my VPS and WP Blog for speed.
I am normally a MS guy, I have been supporting MS Windows and IIS at work for more then 10 years. Optimizing the OS and IIS for speed comes pretty easily, on Windows. I don’t have a lot of experience with Linux. So I started out by trying to map the different components.
OS – Linux Kernel
Apache
PHP
WP
MySQL
For the OS I am running the hosting providers default install of CentOS, with Virtualmin\Webmin installed for management. I have all ready followed several different guides on locking it down via firewall, removing unneeded virtualmin\webmin modules, etc.. So I figured the OS was all ready somewhat optimized. (I know, not really and I do need to re-visit this someday.)
For Apache I started digging around and found several great guides. In the end I followed advice from a few different places. Namely I followed this site.
The only issue I had is when trying to restart Apache I had several errors regarding missing modules. I just went through and re-enabled the modules one at a time as they gave errors. It turns out that the default install of Cent-OS and Virtualmin\Webmin required some additional modules above and beyond those that the article suggested.
Beyond that I had gone through several other forums and guides, etc. regarding what values to actually use for the MPM prefork module. I ended just playing with it. Since my site does not get a lot of visitors or hits I tweaked the settings to attempt to use as little resources as possible, but would still serve my homepage fast enough for my liking after restarting the Apache service. I played with both, restarting the Apache service and letting the server sit idle for a few minutes between visits. I can not remember what settings I ended up with, but I think I ended up close to the suggested ones in the guide.
Next came PHP. I could not find any good guides on optimizing PHP. There were several that pointed back to a guide that they claimed showed how to optimize PHP but really it discussed the same MPM settings in Apache and talked in detail about how PHP and Apache work together, but gave no real guides or points to actually optimizing PHP itself. In the end about all I could do is fine opcode cache services. I found three, eAccelerator, XCache, and Zen. After looking at several different comparisons (I would link to them, but I spent hours scouring through google and I doubt if I really could go back now and find them all, besides it would be a ton of links.) For WP it seemed that eAccelerator performed slightly better, so I ended up installing it, per the instructions found here.
Now for WP. I had tried several different plugins. PHP Speedy, and several other WP cache plugins, as well as an eAccelerator plugin. I could not get the eAccelerator plugin to see that eAccelerator was in fact installed, so it kept wanting to just run normal WP Caching. I double, and triple checked my eAccelerator config, and just could not get it, so I removed the plugin. I ended up removing PHP Speedy too. I finally came upon the WP SuperCache plugin. The only thing I have not fixed yet is the Random Picture Widget on my Sidebar. The SuperCache plugin caches complete pages. I tried adding their trick about setting a certain variable name to true in order to not cache the page. I added this line in the php file for the widget, but it caused the whole page to not be cached. Since this widget appears on every page it defeated the whole purpose of caching. I am now looking into something I saw the other night (but was too late to mess with) regarding modifying the the code to add additional scripts or something to get the SuperCache plugin to not cache it. (I am not sure, at that point I may have been hallucinating…)
For WP I also went through and downloaded all of my pictures and images used, ran them through Yahoo’s SmushIt and then re-uploaded them. I then installed this plugin WP Smush.it, hoping that for now on all of my images will be successfully smushed.
Then on to MySQL. I dug and dug and dug. I found so many contradictory guides on how to optimize MySQL that I gave up. One would say do this, then another would say don’t ever do that… Then another would be totally different. In the end I did find one thing that helped. I disabled InnoDB. This cut a huge amount of resources being used by MySQL. Since this VPS will only ever host (as far as I know) this WP blog, and maybe a WPMU or Joomla site on another Apache Virtual Server, I don’t need it.
Overall I learned more then I wanted to about Apache, PHP, WP, and MySQL. But in the end my site loads a good 10x faster, and I have cut the memory utilization of my VPS (at idle) down from 400MB of RAM down to around 220MB.
So, the site is back up, it is faster then ever, but for now if you want a new set of random pics on the right, wait 6 minutes and refresh (Chances are you are the only one looking anyway…)