Difference between revisions of "EAccelerator"

From DreamHost
Jump to: navigation, search
m (For those who didn't realize a tilde meant the user's home directory...)
m (End-of-install bug killed.)
Line 12: Line 12:
 
set -e
 
set -e
  
# Version 1.0c, 2007-07-20
+
# Version 1.0d, 2007-09-19
 
#
 
#
# - Initial Release by Chris Shymanik (chris@chipsncheese.com)
+
# - Updated 2007-09-19 by Chris Shymanik (chris@chipsncheese.com)
 +
#  - Minor revision 1.0d to fix an end-of-install bug.
 +
#
 +
# - Initial Release on 2007-07-20 by Chris Shymanik (chris@chipsncheese.com)
 
#
 
#
 
#### User Configuration Options
 
#### User Configuration Options
Line 221: Line 224:
  
 
# Post install clean-up.
 
# Post install clean-up.
 +
sleep 2s
 +
cd ${HOME} && clear
 +
 
rm -rf $SRCDIR
 
rm -rf $SRCDIR
 
if [ ${DISTDEL} == "Yes" ]; then
 
if [ ${DISTDEL} == "Yes" ]; then

Revision as of 10:13, 19 September 2007

The instructions provided in this article or section are considered advanced.

You are expected to be knowledgeable in the UNIX shell.
Support for these instructions is not available from DreamHost tech support.
Server changes may cause this to break. Be prepared to troubleshoot this yourself if this happens.
We seriously aren't kidding about this.

Introduction to eAccelerator

eAccelerator is a free, open source PHP accelerator based off of the MMCache extension. eAccelerator provides a PHP-based content caching and encoding mechanism that allocates its cache either on disk or in shared memory. Once installed, upon subsequent access to a PHP script, eAccelerator will serve up the cached version of the script rather than have PHP re-compile it, thus saving time, memory, and CPU power.

Installing eAccelerator

The installation process for eAccelerator requires a Custom PHP install (See: Installing_PHP4 or Installing_PHP5). Once you have a fully functional custom PHP install you can simply proceed by creating the script below in a text editor, making it executable from the shell (chmod +x eacinstall.sh), and then execute it ( ./eacinstall.sh ). This should give you a functional eAccelerator install. Please note the php.ini modifications BELOW the install script before you continue!

eacinstall.sh

#!/bin/sh
set -e

# Version 1.0d, 2007-09-19
#
# - Updated 2007-09-19 by Chris Shymanik (chris@chipsncheese.com)
#   - Minor revision 1.0d to fix an end-of-install bug.
#
# - Initial Release on 2007-07-20 by Chris Shymanik (chris@chipsncheese.com)
#
#### User Configuration Options
# Temporary source directory
SRCDIR=${HOME}/source
# Download temporary DIST files to which directory?
DISTDIR=${HOME}/dist
# Delete contents of DISTDIR after installation? (Default: Yes)
DISTDEL="Yes"
# Install eAccelerator to which directory?
# Note: This *MUST* be set to your PHP5 installation directory!
INSTALLDIR=${HOME}/php5
# Nice Level for Processes. (Depreciated)
# Higher is nicer, lower is less nice and could get your install process killed!
NICE=19

## Program Version Configuration
# Don't touch unless you know what you're doing!
AUTOCONF="autoconf-2.61"
AUTOMAKE="automake-1.10"
EAC="eaccelerator-0.9.5.1"
# What features do you want enabled?
EACFEATURES="--prefix=${INSTALLDIR} \
--enable-eaccelerator=shared \
--with-eaccelerator-info \
--with-php-config=${INSTALLDIR}/bin/php-config \
--with-eaccelerator-content-caching"

#### END User Configuration Options

########## DO NOT MODIFY BELOW ##########

echo "Installation commencing..." `date +%r`
echo ""
sleep 1s

# Push the install dir's bin directory into the path
export PATH=${INSTALLDIR}/bin:$PATH

# Clear and/or create the source directory.
if [ -d ${SRCDIR} ]; then
		  echo "Source directory already exists! Cleaning it..."
		  rm -rf $SRCDIR/*
else
		  echo "Creating source directory..."
		  mkdir -p ${SRCDIR}
fi
# Create the dist files directory if it doesn't exist
# optionally cleaning it if it does exist already.
if [ -d ${DISTDIR} ]; then
	echo ""; echo "Distribution directory already exists!"; echo "Clean it?"
	if [ ${DISTDEL} == "Yes" ]
	then
		echo ""; echo "Yes!"; echo "Cleaning now..."; echo ""
		rm -rf $DISTDIR/*
	else
		echo ""; echo "No!"; echo "Leaving the distribution directory intact."; echo ""
	fi
else
		  echo "Creating distribution directory..."
		  mkdir -p ${DISTDIR}
fi
# Make sure the extensions directory exists.
if [ -d ${INSTALLDIR}/lib/php/extensions ]; then
		  echo "lib/php/extensions folder already exists! Doing nothing..."
else
		  mkdir -p ${INSTALLDIR}/lib/php/extensions
fi

# Detect how many processors the system has (for more optimal compliation).
cores=2   # the number of cores/procs to use when building
if [ $cores -a $cores -gt 1 ]; then
		  j="-j$cores "
fi
		  OS=`uname -s`
if [ "Darwin" = $OS ]; then
		  sed=gnused
		  makefile=makefile.macosx
else
		  makefile=makefile.linux_x86_ppc_alpha
		  sed=sed
fi

for i in $sed wget; do
		  $i --version >/dev/null 2>&1
done

## Check if packages already exist and get packages the ones that don't.
cd ${DISTDIR}
# Do not abort on errors.
set +e
# Wget options
WGETOPT="-t1 -T10 -w5 -q -c"

# Do some of our own error checking here too.
if [ -a ${DISTDIR}/${AUTOCONF}.tar.gz ]; then
		  echo "Skipping wget of ${AUTOCONF}.tar.gz"
else
		  wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${AUTOCONF}.tar.gz
		  # If primary mirror fails, use the alternative mirror.
		  if [ -a ${DISTDIR}/${AUTOCONF}.tar.gz ]; then
			echo "Got ${AUTOCONF}.tar.gz"
		  else
				wget $WGETOPT ftp://ftp.gnu.org/gnu/autoconf/${AUTOCONF}.tar.gz
				# Check to make sure the alternative mirror worked.
				if [ -a ${DISTDIR}/${AUTOCONF}.tar.gz ]; then
					echo "Got ${AUTOCONF}.tar.gz"
				else
					echo "Failed to get ${AUTOCONF}.tar.gz. Aborting install!"
					exit 0
				fi
		  fi
fi
if [ -a ${DISTDIR}/${AUTOMAKE}.tar.bz2 ]; then
		  echo "Skipping wget of ${AUTOMAKE}.tar.bz2"
else
		  wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${AUTOMAKE}.tar.bz2
		  # If primary mirror fails, use the alternative mirror.
		  if [ -a ${DISTDIR}/${AUTOMAKE}.tar.bz2 ]; then
			echo "Got ${AUTOMAKE}.tar.bz2"
		  else
				wget $WGETOPT ftp://ftp.gnu.org/gnu/automake/${AUTOMAKE}.tar.bz2
				# Check to make sure the alternative mirror worked.
				if [ -a ${DISTDIR}/${AUTOMAKE}.tar.bz2 ]; then
					echo "Got ${AUTOMAKE}.tar.bz2"
				else
					echo "Failed to get ${AUTOMAKE}.tar.bz2. Aborting install!"
					exit 0
				fi
		  fi
fi

if [ -a ${DISTDIR}/${EAC}.tar.bz2 ]; then
		  echo "Skipping wget of ${EAC}.tar.bz2"
else
		  ftp://ftp.ussg.iu.edu/pub/array2/linux/gentoo/distfiles/${EAC}.tar.bz2
		  # If primary mirror fails, use the alternative mirror.
		  if [ -a ${DISTDIR}/${EAC}.tar.bz2 ]; then
		  	echo "Got ${EAC}.tar.bz2"
		  else
				wget -c http://bart.eaccelerator.net/source/0.9.5.1/${EAC}.tar.bz2
				# Check to make sure the alternative mirror worked.
				if [ -a ${DISTDIR}/${EAC}.tar.bz2 ]; then
					echo "Got ${EAC}.tar.bz2"
				else
					echo "Failed to get ${EAC}.tar.bz2. Aborting install!"
					exit 0
				fi
		  fi
fi

set -e

# Extract the source files into the source directory.
cd ${SRCDIR}
echo "Extracting ${AUTOCONF}..."
tar xzf ${DISTDIR}/${AUTOCONF}.tar.gz > /dev/null
echo "Done."
echo "Extracting ${AUTOMAKE}..."
tar xjf ${DISTDIR}/${AUTOMAKE}.tar.bz2 > /dev/null
echo "Done."
echo "Extracting ${EAC}..."
tar xjf ${DISTDIR}/${EAC}.tar.bz2 > /dev/null
echo "Done."

# Required exports
export PATH=${SRCDIR}/bin:$PATH
export PHP_PREFIX=${INSTALLDIR}/bin

## Compile deps and install eAccelerator
#AUTOCONF
cd ${SRCDIR}/${AUTOCONF}
./configure --prefix=${SRCDIR}
# make clean
nice -n ${NICE} make
make install

#AUTOMAKE
cd ${SRCDIR}/${AUTOMAKE}
./configure --prefix=${SRCDIR}
# make clean
nice -n ${NICE} make
make install

#EAC
cd ${SRCDIR}/${EAC}
${INSTALLDIR}/bin/phpize
./configure ${EACFEATURES}
# make clean
nice -n ${NICE} make

## Install eAccelerator now by copying the lib file over to the PHP extension dir.
cp modules/eaccelerator.so ${INSTALLDIR}/lib/php/extensions/eaccelerator.so

# Create temp directory for cache (check if exists first!)
if [ -d ${HOME}/tmp/eaccelerator ]; then
		  echo "Re-creating eAccelerator temp cache directory..."
		  rm -rf ${HOME}/tmp/eaccelerator
		  mkdir -p ${HOME}/tmp/eaccelerator
		  echo "Done."
else
		  echo "Creating eAccelerator temp cache directory..."
		  mkdir -p ${HOME}/tmp/eaccelerator
		  echo "Done."
fi

# Post install clean-up.
sleep 2s
cd ${HOME} && clear

rm -rf $SRCDIR
if [ ${DISTDEL} == "Yes" ]; then
	rm -rf $DISTDIR
elif [ ${DISTDEL} == "No" ]; then
	echo "Your DISTDIR will not be cleaned."
else
	echo "Unknown DISTDEL option! Cleaning your DISTDIR by default."
fi

## End of Install
echo "Installation completed!" `date +%r`

#EOF

php.ini modifications

Locate the following line(s) in your php.ini file:

; Directory in which the loadable extensions (modules) reside.
extension_dir = "./"

Modify the extension_dir line to look like this, replacing username with the username of your account:

; Directory in which the loadable extensions (modules) reside.
extension_dir = "/home/username/php5/lib/php/extensions"


Now add the following near the very end of your existing php.ini file.
Please Note: You'll need to change username to the username of your account.
You'll also need to change domain.tld to whatever domain you wish to activate eAccelerator for.
If you wish to use eAccelerator for more than one domain, just add another eaccelerator.allowed_admin_path="..." line for each domain you wish to use it for.

[eaccelerator]
extension="eaccelerator.so"
eaccelerator.allowed_admin_path="/home/username/domain.tld"
eaccelerator.shm_size="20"
eaccelerator.cache_dir="/home/username/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="5"

Troubleshooting eAccelerator

Q: I've done all the above and PHP still doesn't recognize eAccelerator. Please help!
A: If you're running PHP under FCGI then this will definitely pose a problem as the changes you've just made won't always take affect until after your FCGI processes are killed and restarted. The most effective way to kill your FCGI processes is to first switch over to standard CGI mode and then kill each FCGI process from the shell. It is recommended you kill processes in the shell via their PID. Please also note that the use of the killall command is strongly discouraged and may break things!
Once you've managed to kill your FCGI processes, load one of your PHP pages in a browser, switch back to FCGI, and then verify eAccelerator is working by using the phpinfo() method.

External Links

eAccelerator Homepage
SourceForge Project Page
SQL Based Performance Review