If you have a small server for your own use (such as your personal page) or have a busy server servicing a lot of php requests you might find it a good idea to install some goodies in order to optimize the performance of your machine. A really good start might be installing the eAccelerator.

The eAccelerator extension caches compiled PHP scripts both in shared memory and on disk. By this it reduces the time needed for a server to service a php request for a page that has been already cached.

The latest version of eAccelerator is completely compatible with PHP 5.1 and PHP 5.2, so if you run Ubuntu 7.10 you should not experience any difficulties to install the php accelerator. Before you actually start with the installation you will need to install some packages in advance which are requested by the eAccelerator. This can be really accomplished by the following commands:

apt-get install build-essentials

and

apt-get install php5-dev




I assume that the installation of these packages is successfully completed on your end, thus, you should be able to proceed with the eAccelerator. You can execute the commands below:

cd /usr/local/src/

wget http://bart.eaccelerator.net/source/0.9.5.2/eaccelerator-0.9.5.2.zip

unzip eaccelerator-0.9.5.2.zip

mv eaccelerator-0.9.5.2 eaccelerator

cd eaccelerator

By here we have the eAccelerator downloaded and unzipped under /usr/local/src/eaccelerator. You should be in this directory and execute the following commands:

/usr/bin/phpize5

./configure -enable-eaccelerator \

Hit the enter button. :)

Something like this should be the last 2 lines of the output:

Build complete.
Don’t forget to run ‘make test’.

Then execute the following commands:

make
make install

The second command should provide you with an output like this one:

Installing shared extensions: /usr/lib/php5/20060613+lfs/

Please remember this path which will be needed for your php.ini file.Create a directory writable by Apache for eAccelerator to write cache files to:

mkdir /var/local/eaccelerator
chown root:www-data /var/local/eaccelerator
chmod u=rwx,g=rwx,o= /var/local/eaccelerator

The eAccelerator provides some sort of control panel. In order to be able to use it a control.php file should be placed on a place that can be accessed via a browser. In order to do this you can use the following commands:

cd /usr/local/src/eaccelerator

mkdir /var/www/eace

cp control.php /var/www/eace/index.php

In this way we have the control.php file moved to a directory called eace and the control panel will be accessible on: http://yourdomain.tld/eace/




I strongly recommend you to edit this file in order to change the default username and password that will be used for administrative access to this control panel. This can be easily done by:

vim /var/www/eace/index.php

The lines that you should edit are as follows:

/** config **/
$user = “*****”;
$pw = “*****”;
/** /config **/

As soon as you have this done you have only one last step to complete the installation. You should open your php.ini file under: /etc/php5/apache2/php.ini and put the following lines on the top/bottom of the file:

zend_extension=”/usr/lib/php5/20060613+lfs/eaccelerator.so”
eaccelerator.shm_size=”0″
eaccelerator.cache_dir=”/var/local/eaccelerator”
eaccelerator.enable=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”1″
eaccelerator.debug=”0″
eaccelerator.shm_only=”0″
eaccelerator.compress=”1″
eaccelerator.compress_level=”9″
eaccelerator.allowed_admin_path=”/var/www/eace/index.php”

Please don`t forget to change the zend_extension path to the one that has been given as output of the make install command earlier. As soon as you have this done you can simply use the config test command:

apache2ctl configtest

If the following output is given you can safely restart your Apache service: Syntax OK. To restart your Apache service you can use:

/etc/init.d/apache2 restart




To test if everything works properly, please check your eAccelerator control panel at http://yourdomain.tld/eace/ by using your login credentials.

If you liked this post, buy me a beer. ($3 for a beer or $7.5 for a pitcher)