Wednesday, August 15, 2012

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

Extract it:
tar xvfj eaccelerator-

Change the directory to eAccelerator dir:
cd eaccelerator-

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

Let's install eAccelerator:
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

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
/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!