How to install eAccelerator on linux

php eaccelerator

 eAccelerator works in a way that whenever there is request to a webpage, eAccelerator will parse all the php files and cache them in a shared memory in their compiled state. This way, anytime a request is made, eAccelerator will serve those compiled files from the memory, and thus will almost eliminate the entire parsing process.
eAccelerator is a very useful extension to reduce the CPU overloads, serve the requests faster, and optimize the php performance.
According to php eAccelerator official website, eAccelerator can speed up the php code by 1-10 times and reduce server load.
Installing eaccelerator is an easy process, just follow the below steps to install your eaccelerator on  linux.
In this tutorial, I will be installing eAccelerator on a CentOS.
First, make sure you have the php extension php-devel installed, you can install it using yum (More about linux commands here):
yum install php-devel

Now let’s download eAccelerator to a temporary directory

cd /tmp
wget http://acelnmp.googlecode.com/files/eaccelerator-0.9.6.1.tar.bz2

Extract it:

tar xvfj eaccelerator-0.9.6.1.tar.bz2

Change the directory to eAccelerator dir:

cd eaccelerator-0.9.6.1

Now let’s use PHPize to prepare a PHP extension for compiling:

phpize
./configure

Let’s install eAccelerator:

make
make install

eAccelerator should now be installed.
Let’s tell php to read it and start caching:
In this step, we can either create a separate file for the eaccelerator configuration or we can append them to php.ini, I will use the first method in this example.
We create the eaccelerator ini file:

vi /etc/php.d/eaccelerator.ini

and we write the following

extension=”eaccelerator.so”
eaccelerator.shm_size=”64″
eaccelerator.cache_dir=”/var/cache/eaccelerator”
eaccelerator.enable=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”1″
eaccelerator.debug=”0″
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″

In the above example, I’m allowing eAccelerator to allocate up 64MB in memory. If you want to allow it to allocate less or more, change the value of eaccelerator.shm_size, setting it to 0 will use the default value.

Now we need to define a directory to be used for eAccelerator caching.
Let’s create a new directory:

mkdir -p /var/cache/eaccelerator

and change permissions to read, write and execute:

chmod 0777 /var/cache/eaccelerator

Now let’s restart apache:

service httpd restart

or

/etc/init.d/httpd restart

Congratulations, you now have eAccelerator installed. You can check in your phpinfo() for the eaccelerator section.

If you are unable to restart Apache server, and you receive an error, make sure your server allows you to allocate enough memory. Check this article for more details: Increase shared memory on linux (shmmax)

Follow us on facebook or twitter for the latest updates!

 

Leave a Reply

Your email address will not be published. Required fields are marked *