Integrating eAccelerator Into PHP5 And Lighttpd (OpenSUSE 11.2)
Author: Falko Timme
Follow me on Twitter
Last edited 06/28/2010
This guide explains how to integrate eAccelerator into PHP5 and lighttpd on an OpenSUSE 11.2 system. From the eAccelerator project page: "eAccelerator is a free open-source PHP accelerator, optimizer, and dynamic content cache. It increases the performance of PHP scripts by caching them in their compiled state, so that the overhead of compiling is almost completely eliminated. It also optimizes scripts to speed up their execution. eAccelerator typically reduces server load and increases the speed of your PHP code by 1-10 times."
This document comes without warranty of any kind! I do not issue any guarantee that this will work for you!
1 Preliminary Note
I have tested this on an OpenSUSE 11.2 server with the IP address 192.168.0.100 where lighttpd and PHP5 are already installed and working (e.g. as shown in this tutorial: Installing Lighttpd With PHP5 And MySQL Support On OpenSUSE 11.2). I'll use lighttpd's default document root /srv/www/htdocs in this tutorial for demonstration purposes. Of course, you can use any other vhost as well, but you might have to adjust the path to the info.php file that I'm using in this tutorial.
2 Checking PHP5's Current State
First, before we install eAccelerator, let's find out about our PHP5 installation. To do this, we create the file info.php in our document root /srv/www/htdocs:
<?php phpinfo(); ?>
Afterwards, we call that file in a browser: http://192.168.0.100/info.php
As you see, we have PHP 5.3.2 installed...
... but eAccelerator isn't mentioned anywhere on the page:
3 Installing eAccelerator
Unfortunately, there's no eAccelerator package for OpenSUSE 11.2 in the official repositories, therefore we must compile and install it from the sources. Before we can do this, we need to install some prerequisites:
yast2 -i gcc flex wget gcc-c++ make php5-devel
Now we can download and install eAccelerator like this (make sure that you get the latest version from the eAccelerator web site):
tar xvfj eaccelerator-0.9.6.1.tar.bz2
Next we copy eaccelerator.ini to the /etc/php5/conf.d directory:
cp eaccelerator.ini /etc/php5/conf.d
Now we must configure eAccelerator by editing /etc/php5/conf.d/eaccelerator.ini:
[eaccelerator] ;;;;;;;;;;;;;;;;;;; ; About this file ; ;;;;;;;;;;;;;;;;;;; ; ; eAccelerator is compatible with Zend Optimizer's loader. Zend Optimizer ; must be installed after eAccelerator in php.ini. If you don't use scripts ; encoded with Zend Encoder then we do not recommend you install Zend Optimizer ; with eAccelerator. ; You must uncomment one (and only one) line from the following to load ; eAccelerator extension. extension="eaccelerator.so" ;zend_extension="/usr/lib/php/modules/eaccelerator.so" ;zend_extension_ts="/usr/lib/php/modules/eaccelerator.so" ;extension="eaccelerator.dll" ;zend_extension_ts="c:\php4\eaccelerator.dll" ;zend_extension="c:\php4\eaccelerator.dll" ; The amount of shared memory (in megabytes) that eAccelerator will use. ; "0" means OS default. Default value is "0". eaccelerator.shm_size = "0" ; The directory that is used for disk cache. eAccelerator stores precompiled ; code, session data, content and user entries here. The same data can be ; stored in shared memory also (for more quick access). Default value is ; "/tmp/eaccelerator". eaccelerator.cache_dir = "/var/cache/eaccelerator" ; Enables or disables eAccelerator. Should be "1" for enabling or ; "0" for disabling. Default value is "1". eaccelerator.enable = "1" ; Enables or disables internal peephole optimizer which may speed up code ; execution. Should be "1" for enabling or "0" for disabling. ; Default value is "1". eaccelerator.optimizer = "1" ; Enables or disables debug logging. Setting this to 1 will print information ; to the log file about the cach hits of a file. eaccelerator.debug = 0 ; Set the log file for eaccelerator. When this option isn't set then the data ; will be logged to stderr eaccelerator.log_file = "/var/log/lighttpd/eaccelerator_log" ; A string that's prepended to all keys. This allows two applications that use the ; same key names to run on the same host by setting this in .htaccess or in the main ; configuration file for the whole webserver. eaccelerator.name_space = "" ; Enables or disables PHP file modification checking. Should be "1" ; for enabling or "0" for disabling. You should set it to "1" if you want ; to recompile PHP files after modification. Default value is "1". eaccelerator.check_mtime = "1" ; Determine which PHP files must be cached. You may specify the number of ; patterns (for example "*.php *.phtml") which specifies to cache or ; not to cache. If pattern starts with the character "!", it means to ignore ; files which are matched by the following pattern. Default value is "" that ; means - all PHP scripts will be cached. eaccelerator.filter = "" ; When eAccelerator fails to get shared memory for new script it removes ; all scripts which were not accessed at last "shm_ttl" seconds from shared ; memory. Default value is "0" that means - don't remove any files from ; shared memory. eaccelerator.shm_ttl = "0" ; When eAccelerator fails to get shared memory for new script it tries to ; remove old script if the previous try was made more then "shm_prune_period" ; seconds ago. Default value is "0" that means - don't try to remove any ; files from shared memory. eaccelerator.shm_prune_period = "0" ; Enables or disables caching of compiled scripts on disk. It has no effect ; on session data and content caching. ; Default value is "0" that means - use disk and shared memory for caching. eaccelerator.shm_only = "0" ; The script paths that are allowed to get admin information and do admin ; controls eaccelerator.allowed_admin_path = ""
I've changed two settings in the above file: eaccelerator.cache_dir = "/var/cache/eaccelerator" and eaccelerator.log_file = "/var/log/lighttpd/eaccelerator_log".
(You can read up on the various configuration settings on this page: http://www.eaccelerator.net/wiki/Settings.)
As you see, we are using the disk cache directory /var/cache/eaccelerator which we must create now and make it world-writable:
mkdir -p /var/cache/eaccelerator
chmod 0777 /var/cache/eaccelerator
Afterwards, we restart lighttpd so that our new PHP configuration takes effect:
Afterwards, open info.php again in a browser: http://192.168.0.100/info.php
You should now see eAccelerator mentioned on the page which means it has successfully been integrated and is working as expected (I've marked the eAccelerator line in the below screenshot for better visibility):
- eAccelerator: http://www.eaccelerator.net/
- PHP: http://www.php.net/
- lighttpd: http://www.lighttpd.net/
- OpenSUSE: http://www.opensuse.org/