Friday, July 23, 2010

Opcode caching with eaccelerator — on shared hosts

* Make sure you have your own custom php-fcgi (notice that ‘f’ - cgi) compiled and running the site where you want to enable eaccelerator.
* get eaccelerator latest version and compile it
* add the settings to the relevant php.ini
* all set

For eaccelerator
The exports are for making sure you work with the right php. Again you will need autoconf, automake and php-devel(phpize) for the compile to work.

wget http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.tar.bz2
export TMPDIR=$HOME/executable/tmp
export PATH=$HOME/executable/bin:$PATH
export LD_LIBRARY_PATH=$HOME/executable/lib:/usr/local/lib:$LD_LIBRARY_PATH
export CPATH=$HOME/executable/include:/usr/local/include:$CPATH
export LIBRARY_PATH=$HOME/executable/lib:/usr/local/lib:$LIBRARY_PATH
tar -jxf eaccelerator-0.9.5.3.tar.bz2
cd eaccelerator-0.9.5.3
phpize
./configure --prefix=$HOME/executable/
make
make install

For the php.ini
These lines are for loading and configuring ea in the custom php you use. So add them to the php.ini that pops up on your phpinfo page.

extension="eaccelerator.so"
eaccelerator.shm_size = "20"
eaccelerator.cache_dir = "/home/user/tmp/eaccelerator"
eaccelerator.enable = "1"
eaccelerator.optimizer = "1"
eaccelerator.debug = 1
eaccelerator.log_file = "/home/user/log/httpd/eaccelerator_log"
eaccelerator.name_space = ""
eaccelerator.check_mtime = "1"
eaccelerator.filter = ""
eaccelerator.shm_max = "0"
eaccelerator.shm_ttl = "0"
eaccelerator.shm_prune_period = "0"
eaccelerator.shm_only = "0"
eaccelerator.compress = "1"
eaccelerator.compress_level = "9"
eaccelerator.allowed_admin_path = ""

This is what your .htaccess should look like (assuming you got the precompiled php bit right)

well if you got your custom php working right then this is not going to change any

[/]$ cat .htaccess
AddHandler phpFive .php
Action phpFive /cgi-bin/php.cgi

And here’s your php with eaccelerator in there

[/]$ php -v
PHP 5.2.3 (cli) (built: May  8 2009 09:08:36)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
    with eAccelerator v0.9.5.3, Copyright (c) 2004-2006 eAccelerator, by eAccelerator
    with the ionCube PHP Loader v3.1.32, Copyright (c) 2002-2007, by ionCube Ltd., and
    with Zend Extension Manager v1.2.2, Copyright (c) 2003-2007, by Zend Technologies
    with Zend Optimizer v3.3.0, Copyright (c) 1998-2007, by Zend Technologies
[/]$

Make sure that eaccelerator is also enabled in php by checking a phpinfo page.


Log should show hits also phpinfo page will show you the number of cached scripts.

Might want to benchmark it using something like phpspeed before and after the eaccelerator is plugged in….

Well this should ideally speed things up by around 60% so you’ll know when that happens :D

Enjoy!

No comments: