October 20, 2017

How to Install eAccelerator to Optimize PHP Performance on FreeBSD

FreeBSD Logo

With eAccelerator your can increase your PHP performance by up to 1000%. This PHP accelerator caches frequently used portions of PHP files in memory and delivers them with high-speed.
This is useful for high performance websites with loads of traffic.
In this tutorial we show you the steps to install and configure eAccelerator from the FreeBSD ports tree.

Root access is required to edit the following files and to execute commands. Log in as root (su) or simply prepend sudo to all commands that require root privileges.

Install eAccelerator

Navigate to the eAccelerator port, compile and install:

cd /usr/ports/www/eaccelerator
make install clean; rehash

Update: The port has not been updated for a while now. Please download and follow the install instructions on github if the port does not work with your current PHP version.

Configure PHP

Make the following modifications in the php.ini:

extension="eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/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"

Configure Zend PHP

If you are using Zend open the php.ini under the following location. Otherwise you can skip this step and continue with the cache directory step.

vi /usr/local/Zend/etc/php.ini

Make the following modifications in the php.ini. Please check the location of your eaccelerator.so and replace the zend_extension path in the php.ini.

zend_extension="/usr/local/lib/php/20120429/eaccelerator.so"
eaccelerator.shm_size="32"
eaccelerator.cache_dir="/tmp/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"

Comment out the following lines:

zend_extension_manager.optimizer=/usr/local/Zend/lib/Optimizer-2.5.7
zend_extension_manager.optimizer_ts=/usr/local/Zend/lib/Optimizer_TS-2.5.7

Cache directory

Create the cache directory.

mkdir /tmp/eaccelerator
chmod 0777 /tmp/eaccelerator

Final check

Finally you can check that eAccelerator is working by copying the eaccelerator.php file from the ports directory to your public directory. Open the file with your browser and check that everything runs smoothly.

cp /usr/ports/www/eaccelerator/work/eaccelerator/eaccelerator.php /var/www/domain.com/web/

Comments

  1. This method does not work in freebsd with php 5.4
    the port has not been updated in some time. it would be great to change this to instructions to get the source from git, as it works on 5.4

  2. eaccelerator is old, apc + memcache is the feature.

Speak Your Mind