eAccelerator On Linux - Reduce Memory Usage On PHP Script

PHP eAccelerator on Linux.

eAccelerator is a free open-source PHP accelerator and optimizer. It speeds up the script execution by caching the compiled PHP script in shared memory or in disk and eliminating the need of compiling again on each request. By using PHP eAccelerator, the speed of PHP scripts may increase over 1-10 times. This project has been derived from PHP MMCache extension. In this article, we will go through the installation and configuration of PHP eAccelerator.

Requirements for eAccelerator:

• php4 or php5 (support for php5.4 is available).
• autoconf.
• automake.
• libtool.
• m4.
• PHP should be compiled as either mod_php or in fastcgi mode. It can't be used in CGI or CLI because eAccelerator needs to set up shared memory and this can only be done when all PHP instances that need to access it are forks of the first process.

Installation.

Here, we will go through the installation from source package.

1. Download the source package.

You can download the source packages from https://github.com/eaccelerator/eaccelerator/downloads:

wget https://github.com/downloads/eaccelerator/eaccelerator/eaccelerator-0.9.6.1.tar.bz2

2. Unpack the source package.

tar –jxzf eaccelerator-0.9.6.1.tar.bz2

3. Compile it using ‘phpize’ and install.

Use the following steps, if there is only one PHP is available in the server.

cd eaccelerator-0.9.6.1
phpize
./configure
make
make install

If you want to use eAccelerator with PHP which is not the default one (more than one PHP installation available, say /opt/php), then you need to mention the exact path as follows:

cd eaccelerator-0.9.6.1
/opt/php/bin/phpize
./configure --enable-shared --with-php-config=/opt/php/bin/php-config
make
make install

After installation, it will display the folder where eaccelerator.so has been created.

4. Configuring eAccelerator.

Next, you need to edit the PHP configuration file, php.ini to load the newly installed eAccelerator module. You can find the path to php.ini file by executing the following

php –i | grep php.ini

eAccelerator can be installed both as Zend or PHP extension. Here, we will install it as a zend extension. For that, we need to add the following directives to php.ini file. Don’t forget to modify the “path_to_extension_folder” with the proper one.

zend_extension="/path_to_extension_folder/eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/var/cache/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"

5. Finally, you need to create the cache directory and set the ownership and permissions properly.

mkdir /var/cache/eaccelerator
chown apache.apache /var/cache/eaccelerator

Now, you can check it using a phpinfo script and verify the loaded eAccelerator module.

Bobbin Zachariah 8:46 am

About Bobbin Zachariah

Founder of LinOxide, passionate lover of Linux and technology writer. Started his career in Linux / Opensource from 2000. Love traveling, blogging and listening music. Reach Bobbin Zachariah about me page and google plus page.

Author Archive Page

Have anything to say?

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

All comments are subject to moderation.