Installing eAccelerator in Ubuntu Server
The latest version of the PHP cache eAccelerator has been released… one of the more popular PHP extensions that attempts to speed up PHP performance. This is first non-beta of eAccelerator that supports PHP 5.1 and PHP 5.2.
It so happens that Ubuntu Server 6.06 ships with PHP 5.1.2 so I thought I’d install the lastest eAccelerator to see if it helps speed up the performance of PHP. So here’s a quick-n-dirty guide to compiling and installing eAccelerator Release-0.9.5 on Ubuntu 6.06:
Before you begin, you’ll need GCC and other compiler tools installed (installing the build-essentials package is a good start). To build PHP extensions you’ll also need the php5-dev package and it’s dependencies.
Download the eAccelerator 0.9.5-release source code to a temporary directory (/usr/local/src is a good location) and unpack the archive in the usual way:
tar xvjf eaccelerator-0.9.5.tar.bz2
Change to the eaccelerator-0.9.5 directory and run configure as follows:
/usr/bin/phpize
./configure --enable-eaccelerator \
--with-php-config=/usr/bin/php-config
Assuming the above results in no error messages, you are ready to compile and install:
make
make install
You should now have a file named eaccelerator.so in directory /usr/lib/php5/20051025/ (or whatever directory was printed when you did ‘make install’).
Now the extension must be activated in PHP. Add the following to the bottom of file /etc/php5/apache2/php.ini:
zend_extension="/usr/lib/php5/20051025/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/apache2-default/control.php"
The eAccelerator extension caches compiled PHP scripts both in shared memory and on disk. 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
Finally, check that Apache accepts the extension and the changes you made to php.ini:
apache2ctl configtest
If the above doesn’t complain, it should be safe to restart Apache to activate the accelerator:
/etc/init.d/apache2 restart
At this points it’s a good idea to test a few PHP web pages to make sure Apache and PHP are happy.
Control panel
eAccelerator provides a "control panel" of sorts that is useful to see what pages are being cached and usage of shared memory. To install the control panel, first copy file control.php into the web server document root:
cd /usr/local/src/eaccelerator-0.9.5
cpcontrol.php /var/www/apache2-default
Edit control.php to change the $user and $pw settings to a user name and password of your choosing. Don’t leave them as the default or attackers will be able to disrupt the cache.
View the control panel at http://your-server-url/control.php
Note: if you rename or move control.php you must update the eaccelerator.allowed_admin_path setting in php.ini
Performance tuning
Since eAccelerator first stores compiled PHP pages in shared memory, then on disk when that runs out, the size of the shared memory pool will likely have the largest impact on performance.
By default, eAccelerator uses the maximum shared memory available which on Ubuntu 6.06 seems to be around 33 MB, regardless of installed memory. That may be too large for a server with limited RAM… in low memory situations it’s better to leave more memory for applications and the Linux disk cache. You can reduce shared memory usage by setting eaccelerator.shm_size to something other than zero.
Conversely, if your server is dedicated to serving PHP pages and has lots of installed memory, increasing shared memory might improve performance. See the eAccelerator release notes for info on increasing available shared memory in the Linux kernel.
On a very busy server where PHP code doesn’t change often, performance might be improved by setting eaccelerator.check_mtime="0" to disable checking of source files for changes. Beware if you do this that when php files change you’ll have to clear the eAccelerator cache (via the control panel or using ‘apache2ctl graceful‘ at the command line) for changes to become visible.
Does it help?
After tuning and testing on both a small development server and a large dual-core production server, eAccelerator is providing about a 50% raw performance improvement over plain old PHP. Less than I expected but still faster than what I was able to get with either APC and XCache.
Related posts:
- Installing Apache mod_evasive in Ubuntu Server
- Upgrading to Ubuntu Server 6.10 (edgy)
- Thoughts on moving from Debian to Ubuntu Server
8 Responses to “Installing eAccelerator in Ubuntu Server”:
January 3rd, 2007 at 11:21 pm
[...] Since the server is under-powered, it has a little bit of trouble handling even these modest webserving tasks. So I just finished up with two modifications that should make the server run a little bit faster. For one, I changed DNS servers. There were some sort of DNS resolution issues with the router, so I changed the DNS servers this server is configured to connect to (strictly speaking this doesn’t have anything to do with the speed of the server). I also installed eAccelerator, which caches compiled PHP scripts. I can already feel the increased responsiveness of the server. In particular, the connection won’t seem to hang as long after the post comment button is clicked (SpamKarma2 is fairly computationally expensive). Incidentally, if anyone wants to know how to install eAccelerator on Ubuntu Linux, this is a good tutorial. [...]
January 4th, 2007 at 5:20 pm
As a newbie to the linux world I found this tutorial extreamly helpful in speeding up my php for my website. It is primarily a php website and a lot of my users have already commented on the boost in speed. The bad part however is now they’re less likely to donate to a new server.
January 4th, 2007 at 5:32 pm
Mark: Thanks very much for the feedback… glad you found this useful.
An opcode cache like eAccelerator is absolutely essential for every PHP installation… PHP should really include one as part of the source code distribution.
April 22nd, 2007 at 2:52 pm
Just installed eAccelerator on Ubuntu 7.04 Server with PHP 5.2.1 per instructions given. Great instructions.
Beware, if you are running Zend Optimizer and/or ionCube they should be started after eAccelerator (placed in lines after eAccelerator) in the php.ini file for proper operation.
April 22nd, 2007 at 4:47 pm
Aurora: Glad to hear the instructions were helpful. And thanks for the tip.
Last time I looked, the author of eAccelerator recommended not installing Zend Optimizer at all because of potential conflicts. I’d think the same advice applies to other opcode systems like ioncube. Running additional opcode caches really shouldn’t provide any additional speed… multiple caches could even slow things down since both basically are doing the same thing but the system has the extra overhead of managing both cache systems.
December 19th, 2007 at 3:58 am
[...] at all difficult despite it not being just a simple apt-get. I just mostly followed the directions here, though I would’ve been fine just following the official install [...]
March 28th, 2008 at 1:20 am
[...] Installing eAccelerator in Ubuntu Server | Security Viewpoints [...]
February 17th, 2009 at 4:07 pm
[...] Ver link: http://advosys.ca/viewpoints/2006/10/installing-eaccelerator-in-ubuntu-server/ [...]