For some time now I've been wanting to install the Alternative PHP Cache (APC) on the Media Temple GS server upon which this website is hosted. Tantalised by the performance improvements that I've read about, APC became my Holy Grail. But I couldn't get it to install on the GS server, until now.
I've documented the steps I used to get APC running here, in case they're useful to anyone else.
extension_dir = /home/#####/data/lib/php/
extension = apc.soThat's it. APC should now be installed and you should be able to measure a significant improvement in your PHP script performance.
Last Revision: February 19th, 2010 at 00:26
Short URL: http://wp.me/phEOu-J8 (Tweet This!)
So does it need anything else doing to any other code on your site/app, or does it just magically speed everything up?
It’s all magic Matthew. At least as far as I can tell at the moment.
Thanks for this! Just a heads up for anyone cutting and pasting without being entirely sure what they are doing, the blog software seems to have screwed up step 8 slightly it should be -- before the enables and withs, with no space ie --enable
Sorry, It’s done it to my comment also.
Well spotted Alan, I completely missed that but have corrected it now. Thanks for posting.
Thanks.
I try to give the best settings to W3 Total Cache.
You have the idea for memcache and memcached ?
Hi Cristian. I’ve tried to get memcached installed on the MT GS but haven’t succeeded. My understanding is that memcached should NOT be installed on a shared server for security reasons - so I didn’t really pursue it.
Thanks again, np!
Might be worth also mentioning where your php.ini file is located - php.ini is in /home/#####/etc/ as a sample file that you can edit:
cd /home/#####/etc/
cp php.ini.sample php.ini
vi php.ini
Save the file for the settings to take immediate effect.
It certainly seems to have sped up my sites with no ill-effects.
That’s a good catch Matthew. I never thought to mention that - me and my assumptions eh?
There’s definitely a performance boost with APC. Combine it with a good caching system and your PHP applications really start to deliver.
Suddenly I can mention PHP and scalability in the same sentence without laughing.
OK, so I thought this was pretty amazing, until I found a front end for APC. Dont know if anyone else would like to give it a try, and tell me what kind of results you are getting, but i appear to be only caching one file. The front end file.
You can grab it here: http://iantearle.com/apc.zip
Grateful for your results and suggestions if I may have done something wrong.
@Ian Tearle: Personally I’m only using the APC to store database queries so your script doesn’t really reveal too much about my setup (other than that my cache is 127MB in size - wow!)
Absolutely GREAT step by step instructions!
Worked like a charm!
Thank you so much for posting this!
@Mike: I’m glad these instructions were useful to you. Thank you for commenting.
Would you mind clarifying something in Step 8? The Media Temple Knowledge Base includes “Installing PECL Extensions” instructions on the Grid Server. The command (your step
is different and so I asked them about APXS. This was the written reply:
“APXS is not available on the (gs) Grid-Service, and cannot be installed. I have confirmed this with our administrators. You should configure APC without that flag.” Earlier, on the phone, the tech had stated that it didn’t matter - that one could use either configuration command. I had asked for follow up confirmation of that because I have been getting contradictory info from them lately.
The “--enable-apc-mmap” flag is not part of the command in the Knowledge Base either.
I have seen your method come up in 3 different places in google search results. I just want to do it right the first time (and not kill the site) since I am a web content and business operations person flung into the technical side and just learning as demanded. Thank you.
Sarah, I can’t offer any guarantees. Nor can I state definitively that my way is the right way. All I can tell you is that the steps documented here are exactly as I entered them. This procedure worked for me, despite whatever Media Temple’s position is.
If you have any doubts, then don’t follow these instructions. That’s the safest advice I can give you. But I will state again, this worked for me and has worked for others.
I’m sorry I can’t be more positive.
Thank you. I hadn’t expected such a quick response. Tell me, did THEIR way fail for you when you first started trying to get the extension installed? Thank you, again, for taking the time.
I have to be honest Sarah, I don’t remember. I tried so many things in my attempts to get APC installed and running that it’s all a bit of a blur now.
I remember, very clearly, how thrilled I was when I finally cracked it, got the thing installed, then flicked through a few pages on my website. The immediate performance boost I saw brought a grin to my face. APC really does make that much of a difference.
Just wanted to thank you. This reduced my initial load time for my Joomla site to 1/5 of what it was. Great article!
@Brian
That’s awesome Brian. I’m delighted that this has made such a big difference to your site’s performance.
It seems to have sped up the php end of the equation. It now appears the SQL queries are taking forever to execute but the net effect is still a decrease in load time. Thanks again!
I went through your steps to install and it worked perfectly. Thanks for this!
Although when I move the apc.php file to my html directory and check it, the graph show nothing being cached (except the apc.php file). Any thoughs on this? It is running, just not doing anything based on the graphs.
I also ran Make test and it passed all 3 tests…
Any help would be appreciated.…Much thanks
@Adam
I wouldn’t worry too much about the apc.php output Adam. I get conflicting information from it too. If everything is installed and working correctly you’ll know it simply by the performance improvements you’ll witness.
If your website’s faster then APC is running!
@Brian
The database is usually the slowest part of a modern web-application unfortunately.
The science of DB optimisation and performance tuning is beyond the scope of a comment here. But some time with Google will yield a wealth of information. Be prepared for blood, sweat and tears along the way though.
You’ll be much better served Brian by a decent caching solution - I saw my biggest performance enhancement on this site when I implemented caching (for both the DB and page-generation).
Thanks Jonathan! Ran it by the letter and it works.
The only thing that remains is to, if possible, get it to work on the “Alternate” domains (as Mediatemple calls them), now it only works for the main domain.
If I run “apc_cache_info()” on an Alternate domain I get “Fatal error: Call to undefined function: apc_cache_info()”.
Do you (or somebody) have any idea on how this can be fixed?
Well, I found the problem, one of those you think couldn’t happen to yourself. The domain I had problems with was running on PHP 4 so I changed it to run on 5 and now APC runs fine there too.
Thanks!
@Bob
Glad it’s all working for you Bob. Thanks for the heads-up on the PHP 5 requirement.
I followed your instructions to a T but am getting a ton of erros in my server logs (see below). They are causing me to get 500 Internal Server Errors so I am having to diable APC. Any thoughts on why this would happen?
Thanks again!
[Wed Mar 10 12:05:13 2010] [error] [client 68.173.XX.XX] PHP Warning: PHP Startup: Unable to load dynamic library ‘/home/XXXXX/data/lib/php/xslt.so’ - /home/XXXXX/data/lib/php/xslt.so: cannot open shared object file: No such file or directory in Unknown on line 0