Jun 14
eAccelerator, PHP 5, and Dreamhost
Alright, so after spending the last 3 nights trying to successfully make eAccelerator work with php5 on my new Dreamhost accout, i finally have it working! So, for the sake of remembering how to do it myself, and to help out all the rest of you out there — I’ve assembled this guide for you. Citing my references and extending my thanks — I probably wouldn’t have figured this all out without the wonderful, yet slightly dated guide at robinz.info.
To begin with — I read many tutorials reporting that to make this possible you HAD to roll your own php binary, meaning compiling it from source and using some ugly shell scripts from the dreamhost wiki to even think about getting this to work — however — I have found that this was not the case — rather — gave me many more problems than the alternative — using the default php5.cgi provided by dreamhost, and directing it to a different, local customized php.ini.
First, we have to get and build eAccelerator. Of course — we cant just ‘apt-get install eAccelerator’ or anything slick like that (i do like my ubuntu ) — so were going to have to acquire the sources and build it from scratch.
Building Dependencies
eAccelerator requires autoconf, automake, libtool, and m4. Of these, libtool and m4 are already provided on our host by default — the other two — you guessed it — were building from source.
All of the following must be performed while logged in with a shell account.
Install autoconf
- wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.61.tar.gz
- tar -xvzf autoconf-2.61.tar.gz
- cd autoconf-2.61
- ./configure –prefix=$HOME/gnu
- make
- make install
- export PATH=$PATH:$HOME/gnu <– this is so automake and eAccelerator can find the new autoconf binaries
Install automake
- wget http://ftp.gnu.org/gnu/automake/automake-1.9.tar.gz
- tar -xvzf automake-1.9.tar.gz
- ./configure –prefix=$HOME/gnu
- make
- make install
Installing eAccelerator
- wget http://bart.eaccelerator.net/source/0.9.5.1/eaccelerator-0.9.5.1.tar.bz2
- tar -xjf eaccelerator-0.9.5.1.tar.bz2
- cd eaccelerator-0.9.5
- export PHP_PREFIX=/usr/local/php5/bin
- $PHP_PREFIX/phpize
- ./configure –prefix=$HOME/gnu –enable-eaccelerator-shared –with-php-config=$PHP_PREFIX/php-config
- make
- mkdir $HOME/phpini
- mkdir $HOME/phpini/lib
- cp modules/eaccelerator.so $HOME/phpini
Getting our own php.ini
- cp /etc/php5/cgi/php.ini $HOME/phpini/php.ini
- thats it!
Modifying our own php.ini
- open php.ini in a text editor (VIM) — this wont be covered here — many other great tutorials for using vim are available
- modify the ‘extension_dir’ setting to point to /home/YOUR_USER_NAME/phpini/lib
- under the ‘dynamic extensions section — add the following lines of code
- extension=”eaccelerator.so”
- eaccelerator.shm_size=”16″
- eaccelerator.cache_dir=”/home/YOUR_USER_NAME/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=”0″
- eaccelerator.compress_level=”9″ <– not completely necessary since we set compress=”0″ (off). Necessary if you wish to enable cache compression
- run mkdir -p $HOME/tmp/eaccelerator to create your tmp folder
Getting your site to use fastcgi (eaccelerator wont cache anything under reguler cgi)
- cd $HOME/YOUR_DOMAIN_NAME
- create a new text file named ‘fastcgi.fcgi’ and put the following lines of code in it containing the following lines:
- #!/bin/sh
- export PHPRC=/home/YOUR_USER_NAME/phpini
- export PHP_FCGI_CHILDREN=3 <– this may have to change from 3 to 2 — determines how many process of fastcgi wait idle
- exec /dh/cgi-system/php5.cgi
- save the file — it must stay in the root of your webroot ( $HOME/YOUR_DOMAIN_NAME )
- create a new text file named ‘.htaccess’ (note the ‘.’ (dot) — its important)
- place the following lines in this file
- AddHandler fastcgi-script fcg fcgi fpl
- AddHandler php5-fastcgi .php
- Action php5-fastcgi /fastcgi.fcgi
- Options +ExecCGI
- save this file
Now all that is left is to kill any existing fastcgi process that may be running (in case you were happening to mess with this earlier — or got part way and something didn’t work.
execute this command ‘killall php5.cgi’
and all processes named ‘php5.cgi’ under your username should be terminated.
create a phpinfo.php file under your document root for the site you just configured — putting the following in it
<?php phpinfo() ?>
save the file — open a web browser and point it to http://YOUR_DOMAIN/phpinfo.php
IF there is a section for eAccelerator — and it says there are scripts cached — congratulations! It worked! (You may have to open a few other php pages on your site first to make sure the number grows past the single file that is phpinfo.php.
Good Luck — and if you can get it to work like I did — enjoy your significantly faster web hosting experience!
-neverland

September 12th, 2007 at 12:31 pm
I just found out Dreamhost is running Zend optimizer and has been doing so since January:
http://wiki.dreamhost.com/V9.1_January_2007
Two questions: 1) would this interfere with eaccel?
2) Does this make eaccel unnecessary?
Also, even though Zend optimizer is installed (for PHP5), strangely, big PHP/Mysql applications seem very slow.
What’s your experience?
September 12th, 2007 at 12:58 pm
From my understanding — the Zend Optimizer does optimizations on your php code, and allows the execution of close source scripts compiled with their proprietary Zend Guard application. I do not believe that it actually caches the compiled opcodes which is what eaccelerator does. As for interfering, it may? I havent looked into this in awhile, and there may need to be significant changes to the guide due to changes in the server config. Dreamhost runs a bot that will kill all unapproved resident processes. I’ve read that if you name them something specific, they wont be shut down, but I’ve never personally tested it. If you find out more — let me know!
October 24th, 2007 at 2:38 pm
Thank you for taking the time to write a how-to on using eAccelerator at DreamHost. When I followed the instructions above I encountered what I think it a minor error. The instructions suggest the extension_dir be set to $HOME/phpini/lib, but, the extension it self is copied to $HOME/phpini. It seems like, “cp modules/eaccelerator.so $HOME/phpini” should be changed to “cp modules/eaccelerator.so $HOME/phpini/lib”.
Thanks again,
Eric
January 20th, 2008 at 10:43 am
Wonderful wonderful tutorial, just a few notes on how I got it to work for anyone else that might be struggling:
EDIT: when setting your path after installing autoconf -> set your path to this:
export PATH=$PATH:$HOME/gnu/bin
instead of just
export PATH=$PATH:$HOME/gnu
1) the comment above (from the other Eric) is correct. in the “Installing EAccelerator” step the command: cp modules/eaccelerator.so $HOME/phpini => cp modules/eaccelerator.so $HOME/phpini/lib
2)Login to your dreamhost control panel -> go to your domain -> edit -> and select “FastCGI Enabled”
3) When creating the .fcgi file, dreamhost suggests naming this to dispatch.fcgi (see note from Dreamhost)
Warning: FCGI processes use more memory than usual CGI ones. Due to this, FCGI-enabled application may be killed by process watchdog due to high memory usage. To prevent this, it’s recommended (by DreamHost support) to rename wrapper script to dispatch.fcgi. This way it will be allowed to use more memory.
4) When adding the rules to .htaccess (if you’ve already got one in place) be sure to add the new rules to the TOP of the file.
4a) Not sure if this is required, but it worked for me. when editing the .htaccess file in your site root (/home/USER_NAME/DOMAIN_NAME) leave out the “+Options +ExecCGI” portion and rather place his command in a new (or existing) .htaccess file in your Home root (/home/USER_NAME). be sure permissions are correct for new .htaccess (should be 644)
5) http://wiki.dreamhost.com/PHP_FastCGI
Review this page before you get to the step where you create the .fcgi file. I outlined most of the important parts in the steps above, but it’s a helpful page. also be sure to see the section “Check Your Work”
OK, I hope this helps someone. Thanks Quickstorm, you rock!
February 18th, 2008 at 9:30 am
Compiling PHP5 and eAccelerator for Litespeed on Dreamhost PS…
The standard PHP4 installation that comes with Litespeed may be missing important libraries that you require for your PHP applications. Also, the bundled APC accelerator is not always enabled. Chances are that you will want to compile PHP5 and eAcceler…
July 5th, 2008 at 2:10 am
Champion! I knew there was a much easier way. Thanks for the guide.