APC is a PHP cache. It will work under both shared and PS environments, but we recommend that you use DreamHost PS (testing on DreamHost PS with a semi-large MediaWiki install increased php's resource usage to 55M).
|The instructions provided in this article or section are considered advanced.|
You are expected to be knowledgeable in the UNIX shell.
Introduction to APC
APC (Alternative PHP Cache) is an open source framework for both optimizing and caching intermediate PHP code. It is currently supported by PHP.net (the developers of PHP). APC provides support for all versions of PHP until version 5.5, after which Zend Opcache will be a built in replacement.
- Grab the source code: wget http://pecl.php.net/get/APC-3.1.13.tgz (or whatever the latest version is!)
- Unpack the download: tar xvf APC-3.1.13.tgz
- Go the unpacked download: cd APC-3.1.13
- Run phpize (PHP 5.3 domains: /usr/local/php53/bin/phpize, PHP 5.4 domains: /usr/local/php54/bin/phpize)
- ./configure; make (for PHP 5.3 domains: ./configure --with-php-config=/usr/local/php53/bin/php-config; make or for PHP 5.4 domains: ./configure --with-php-config=/usr/local/php54/bin/php-config; make)
- Copy modules/apc.so from the APC directory somewhere else.
- Setup a custom PHP.ini.
- Add the line extension = /home/YOURUSER/WHERE/APC/IS/apc.so to the custom php.ini along with any other APC config lines you need.
- Run ps x to see if any php5.cgi or php53.cgi processes are running that need to be ended (existing PHP processes will not recognize APC until they are restarted).
- If there are PHP processes to end, and you DON'T use FastCGI, run killall php5.cgi; killall php53.cgi (if you DO use FastCGI, do not use killall right away! See APC#Troubleshooting APC (first question) for instructions on killing existing FastCGI PHP processes).
- APC is now installed and available for use. (To check, create a php file that calls phpinfo();, visit the file, and check for "apc" or run php-5.4 -i | grep apc)
- To make sure APC is working on your site, copy apc.php from your unpacked download folder to a location on your site visible from the internet. Then simply go to the apc.php page from any web browser to see the reports.
Q: I've done all the above and APC still doesn't work! Please help!
A: If you're running PHP under FCGI then this will definitely pose a problem as the changes you've just made won't always take affect until after your FCGI processes are killed and restarted. The most effective way to kill your FCGI processes is to first switch over to standard CGI mode and then kill each FCGI process from the shell. It is recommended you kill processes in the shell via their PID. Please also note that the use of the killall command is strongly discouraged and may break things!
Once you've managed to kill your FCGI processes, load one of your PHP pages in a browser, switch back to FCGI, and then verify APC is working by using the phpinfo() method. Run php-5.4 -i | grep apc (or php-5.3 depending upon your domain set up) to see if you get any errors.
Q: I've done all the above and APC work! phpinfo() show the APC enabled but if I modify php.ini file width apc.rfc1867=On and apc.mmap_file_mask=/home/username/tmp/apc.XXXXXX, when I upload the file, I can't read the upload status(/home/username/tmp/apc.XXXXXX file don't exist). why?
A: See Bug #13607, "apc.rfc1867 Doesn't Work On FCGI" (http://pecl.php.net/bugs/bug.php?id=13607). Perhaps try http://pecl.php.net/package/uploadprogress
Q: I'm getting an internal server error (Server error 500)!
A: That's because the folder you specified at the end of you php.ini file(this line: apc.mmap_file_mask=/home/username/tmp/apc.XXXXXX) either doesn't exist OR you don't have access to it. To fix it you need to change the permissions or make a new folder/change the folder location.
Pecl APC Homepage
General and Runtime Configuration Information
APC In Comparison
Install PECL on Ubuntu/CentOS
SQL Based Performance Review
Setup APC (Alternative PHP Cache) on Dreamhost Shared Hosting - A good step-by-step tutorial.