Installing PHP5
From DreamHost
Contents |
Using DreamHost's PHP 5
PHP 5 was added to all plans by DreamHost as of June 2005. As of September 2008, support for PHP4 was discontinued, so you can no longer switch between PHP 4 and PHP 5 from the panel.
- Log into the DreamHost Control Panel.
- Click Domains, then Manage Domains.
- Click the wrench icon next to the domain you want to activate PHP 5 on.
- Select PHP 5.x.x from the dropdown menu.
- Click Change fully hosted settings now! at the bottom of the section.
- Repeat steps 3-5 for each additional domain you want to activate.
It will take a few minutes for the changes to take effect.
If you've previously installed your own copy of PHP (for example, by following the instructions below), you'll also need to remove the appropriate AddHandler and Actions directives from your .htaccess file.
If you're using DreamHost's installed PEAR modules, make sure you watch out for this: PEAR breaks on upgrading to PHP5.
Some PHP applications like MediaWiki includes scripts that must be executed from the shell account, and since version 1.7 MediaWiki requires PHP 5.x. PHP5 can be used from:
/usr/local/dh/cgi-system/php5.cgi
Compiling a Customized PHP 5
| The instructions provided in this article or section are considered advanced. You are expected to be knowledgeable in the UNIX shell. |
If you configure your site to use your own custom PHP installation, your version of PHP will no longer automatically upgrade when DreamHost upgrades their version of PHP.
It is your responsibility to reinstall new versions of PHP! Leaving old versions of PHP installed can possibly be a security hazard!
This wiki contains two separate pages describing different ways to install PHP5. Before following these instructions, consider also the Advanced PHP configuration method. That method will allow you to run PHP4 and PHP5 on the same site, you can customize your php.ini, and you can configure PHP to be updated automatically. If it meets your needs it should be easier than the methods on this page.
Custom PHP 5
Note for PHP 5.2.5 - The below scripts should be modified to handle PHP 5.2.5 in the following ways:
--with-curl-dir=/usr/local/lib => --with-curl --with-gd-dir=/usr/local/lib => --with-gd --with-xml => --with-libxml-dir=/usr/local/lib --with-zip => --enable-zip --enable-track-vars => php 5.2.4 track-vars is always enabled (--enable-track-vars removed) --enable-memory-limit => php 5.2.4 memory-limit is always enabled (--enable-memory-limit removed)
Also, the scripts should be modified to more clearly indicate which line to comment/uncomment based on whether you will be running PHP as CGI, which is almost always the case (running as CGI).
WARNING if you use PHP 5.2.3 (and maybe others) the scripts below will copy the php binary when you need them to copy the php-cgi binary!!
Preparations
If you want to compile your own copy of PHP 5, the following script will download and compile it with some commonly-used additional extensions. You can also custom compile PHP 4. Please be aware that:
- you need around 500Mbyte free disk space for the whole process to complete, and
- the script can take more than an hour to complete, so don't get impatient!
Install/Compile PHP 5
- Copy the PHP5_installscript into a text editor and replace YOUR DOMAIN HERE on the 4th line with your site's domain name. MAKE SURE YOU USE THE SAME CASE THAT APPEARS IN THE DIRECTORY LISTING (UPPER or lower).
- Copy the new contents to your clipboard.
- Log in to your account using SSH
- Create a new file in your SSH by entering the command:
vim installscript
- Hit i for insert mode, then right-click to paste your clipboard (the install script) contents, then hit Esc, type :wq (that's 'colon', 'w', 'q'), and press Enter to save and exit.
- Make the file executable by entering the command:
chmod +x installscript
- Run the script by entering the command:
./installscript
- After it has finished you will need to edit your htaccess file appropriately. Add the following:
Options +ExecCGI AddHandler php-cgi .php Action php-cgi /cgi-bin/php.cgi <FilesMatch "^php5?\.(ini|cgi)$"> Order Deny,Allow Deny from All Allow from env=REDIRECT_STATUS </FilesMatch>
to a file called .htaccess and place it in the root folder of your domain you specified above (/home/YOUR USERNAME/YOUR DOMAIN HERE/.htaccess)
Editing your new Php.ini file
Your new php.ini file is located here:
/home/YOURUSERNAME/php5/etc/php5/YOURDOMAINNAME
To see if your site is running the new version of php. Create a file in your web root (public_html) called "phpinfo.php"
Inside the file have the following code: <?php phpinfo(); ?>
Now browse to that file at YOURDOMAIN.COM/phpinfo.php
If you used the above install script - you should be running Php 5.2.0
Instructions To Add More Domains
- Go to the domain directory where you want to use the Custom PHP5 Compile (Example: /abc.com/)
- Type: ln -s /home/USERNAME/DOMAIN_NAME/cgi-bin /home/USERNAME/SUB.DOMAIN_NAME/cgi-bin (Replace USERNAME with your actual username, Replace DOMAIN_NAME with your actual domain name where the custom php5.cgi in stored. Example abc.com. Replace SUB.DOMAIN_NAME with the actual sub domain you want to use for the custom php5)
- Press Enter And You Are Done.
- Upload the .htaccess with the AddHandler/Action methods as listed above to (Example: /abc.com/)
- Upload the same .htaccess with the AddHandler/Action methods to the subdomain (Example: subdomain.abc.com)
Notes
This script has been updated to compile both MySQL [1] and mysqli [2] libraries. mysqli is required to work with new features in MySQL 4.1.3 (client) and up. As Dreamhost is using MySQL 4.1.8 (client) and MySQL 4.0.24 (server), it is suggested to use mysqli. However, if you run into any problems compiling mysqli, feel free to remove '--with-mysqli' from the php configure line.
The complete script can also be found here: Template:PHP5_installscript (for editing)
read this first: Installing PHP5
Main PHP 5 install script
This is the "main" PHP 5 install script. (Below it is a more-recent, alternate PHP 5 install script that may help users who find that the script keeps getting automatically "killed" by DreamHost.)
This script does not work if you are compiling PHP version < 5.2.3. To make this script work when compiling PHP versions before 5.2.3, look for the line in the script that say to uncomment them and do just that. Change from:
cp ${INSTALLDIR}/bin/php-cgi ${HOME}/${DOMAIN}/cgi-bin/php.cgi
...to this...
cp ${INSTALLDIR}/bin/php ${HOME}/${DOMAIN}/cgi-bin/php.cgi
If your downloads fails on kent.dl.sourceforge.net, change
wget -c http://kent.dl.sourceforge.net/sourceforge/freetype/${FREETYPE}.tar.gz
to
wget -c http://voxel.dl.sourceforge.net/sourceforge/freetype/${FREETYPE}.tar.gz
After using this script below and not the alternate script remember to add the below or php5 dies with "malformed header from script. Bad header=" to the .htaccess file in the ${DOMAIN} directory
Action application/x-httpd-php5 /cgi-bin/php5.cgi
AddType application/x-httpd-php5 .php5
#!/bin/sh
# Script updated 2006-12-25 by Carl McDade (hiveminds.co.uk) to allow memory limit and freetype
#
# Script updated 2007-11-24 by Andrew (ajmconsulting.net) to allow 3rd wget line to pass
# LIBMCRYPT version information (was set as static download file name previously.)
#
# Save the code to a file as *.sh
# Abort on any errors
#
set -e
# The domain in which to install the PHP CGI script.
export DOMAIN="your.domain.com"
# Where do you want all this stuff built? I'd recommend picking a local
# filesystem.
# ***Don't pick a directory that already exists!*** We clean up after
# ourselves at the end!
SRCDIR=${HOME}/source
# And where should it be installed?
INSTALLDIR=${HOME}/php5
# Set DISTDIR to somewhere persistent, if you plan to muck around with this
# script and run it several times!
DISTDIR=${HOME}/dist
# Pre-download clean up!!!!
rm -rf $SRCDIR $DISTDIR
# Update version information here.
PHP5="php-5.2.5"
LIBICONV="libiconv-1.11"
LIBMCRYPT="libmcrypt-2.5.7"
LIBXML2="libxml2-2.6.27"
LIBXSLT="libxslt-1.1.18"
MHASH="mhash-0.9.7.1"
ZLIB="zlib-1.2.3"
CURL="curl-7.14.0"
LIBIDN="libidn-0.6.8"
CCLIENT="imap-2004g"
CCLIENT_DIR="imap-2004g" # Another pest!
FREETYPE="freetype-2.2.1"
# What PHP features do you want enabled?
PHPFEATURES="--prefix=${INSTALLDIR} \
--with-config-file-path=${INSTALLDIR}/etc/php5/${DOMAIN} \
--enable-fastcgi \
--enable-force-cgi-redirect \
--with-xml \
--with-libxml-dir=${INSTALLDIR} \
--with-freetype-dir=${INSTALLDIR} \
--enable-soap \
--with-openssl=/usr \
--with-mhash=${INSTALLDIR} \
--with-mcrypt=${INSTALLDIR} \
--with-zlib-dir=${INSTALLDIR} \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-gd \
--enable-gd-native-ttf \
--enable-memory-limit
--enable-ftp \
--enable-exif \
--enable-sockets \
--enable-wddx \
--with-iconv=${INSTALLDIR} \
--enable-sqlite-utf8 \
--enable-calendar \
--with-curl=${INSTALLDIR} \
--enable-mbstring \
--enable-mbregex \
--enable-bcmath \
--with-mysql=/usr \
--with-mysqli \
--without-pear \
--with-gettext \
--with-imap=${INSTALLDIR} \
--with-imap-ssl=/usr"
# ---- end of user-editable bits. Hopefully! ----
# Push the install dir's bin directory into the path
export PATH=${INSTALLDIR}/bin:$PATH
# set up directories
mkdir -p ${SRCDIR}
mkdir -p ${INSTALLDIR}
mkdir -p ${DISTDIR}
cd ${DISTDIR}
# Get all the required packages
wget -c http://us.php.net/get/${PHP5}.tar.gz/from/this/mirror
wget -c http://mirrors.usc.edu/pub/gnu/libiconv/${LIBICONV}.tar.gz
wget -c http://easynews.dl.sourceforge.net/sourceforge/mcrypt/${LIBMCRYPT}.tar.gz
wget -c ftp://xmlsoft.org/libxml2/${LIBXML2}.tar.gz
wget -c ftp://xmlsoft.org/libxml2/${LIBXSLT}.tar.gz
wget -c http://superb-west.dl.sourceforge.net/sourceforge/mhash/${MHASH}.tar.gz
wget -c http://www.zlib.net/${ZLIB}.tar.gz
wget -c http://curl.haxx.se/download/${CURL}.tar.gz
wget -c http://kent.dl.sourceforge.net/sourceforge/freetype/${FREETYPE}.tar.gz
wget -c ftp://alpha.gnu.org/pub/gnu/libidn/${LIBIDN}.tar.gz
wget -c ftp://ftp.cac.washington.edu/imap/old/${CCLIENT}.tar.Z
echo ---------- Unpacking downloaded archives. This process may take several minutes! ----------
cd ${SRCDIR}
# Unpack them all
echo Extracting ${PHP5}...
tar xzf ${DISTDIR}/${PHP5}.tar.gz
echo Done.
echo Extracting ${LIBICONV}...
tar xzf ${DISTDIR}/${LIBICONV}.tar.gz
echo Done.
echo Extracting ${LIBMCRYPT}...
tar xzf ${DISTDIR}/${LIBMCRYPT}.tar.gz
echo Done.
echo Extracting ${LIBXML2}...
tar xzf ${DISTDIR}/${LIBXML2}.tar.gz
echo Done.
echo Extracting ${LIBXSLT}...
tar xzf ${DISTDIR}/${LIBXSLT}.tar.gz
echo Done.
echo Extracting ${MHASH}...
tar xzf ${DISTDIR}/${MHASH}.tar.gz
echo Done.
echo Extracting ${ZLIB}...
tar xzf ${DISTDIR}/${ZLIB}.tar.gz
echo Done.
echo Extracting ${CURL}...
tar xzf ${DISTDIR}/${CURL}.tar.gz
echo Done.
echo Extracting ${LIBIDN}...
tar xzf ${DISTDIR}/${LIBIDN}.tar.gz
echo Done.
echo Extracting ${CCLIENT}...
uncompress -cd ${DISTDIR}/${CCLIENT}.tar.Z |tar x
echo Done.
echo Extracting ${FREETYPE}...
tar xzf ${DISTDIR}/${FREETYPE}.tar.gz
echo Done.
# Build them in the required order to satisfy dependencies.
#libiconv
cd ${SRCDIR}/${LIBICONV}
./configure --enable-extra-encodings --prefix=${INSTALLDIR}
# make clean
make
make install
#libxml2
cd ${SRCDIR}/${LIBXML2}
./configure --with-iconv=${INSTALLDIR} --prefix=${INSTALLDIR}
# make clean
make
make install
#libxslt
cd ${SRCDIR}/${LIBXSLT}
./configure --prefix=${INSTALLDIR} \
--with-libxml-prefix=${INSTALLDIR} \
--with-libxml-include-prefix=${INSTALLDIR}/include/ \
--with-libxml-libs-prefix=${INSTALLDIR}/lib/
# make clean
make
make install
#zlib
cd ${SRCDIR}/${ZLIB}
./configure --shared --prefix=${INSTALLDIR}
# make clean
make
make install
#libmcrypt
cd ${SRCDIR}/${LIBMCRYPT}
./configure --disable-posix-threads --prefix=${INSTALLDIR}
# make clean
make
make install
#libmcrypt lltdl issue!!
cd ${SRCDIR}/${LIBMCRYPT}/libltdl
./configure --prefix=${INSTALLDIR} --enable-ltdl-install
# make clean
make
make install
#mhash
cd ${SRCDIR}/${MHASH}
./configure --prefix=${INSTALLDIR}
# make clean
make
make install
#freetype
cd ${SRCDIR}/${FREETYPE}
./configure --prefix=${INSTALLDIR}
# make clean
make
make install
#libidn
cd ${SRCDIR}/${LIBIDN}
./configure --with-iconv-prefix=${INSTALLDIR} --prefix=${INSTALLDIR}
# make clean
make
make install
#cURL
cd ${SRCDIR}/${CURL}
./configure --with-ssl=${INSTALLDIR} --with-zlib=${INSTALLDIR} \
--with-libidn=${INSTALLDIR} --enable-ipv6 --enable-cookies \
--enable-crypto-auth --prefix=${INSTALLDIR}
# make clean
make
make install
# c-client
cd ${SRCDIR}/${CCLIENT_DIR}
make ldb
# Install targets are for wusses!
cp c-client/c-client.a ${INSTALLDIR}/lib/libc-client.a
cp c-client/*.h ${INSTALLDIR}/include
#PHP 5
cd ${SRCDIR}/${PHP5}
./configure ${PHPFEATURES}
# make clean
make
make install
#copy config file
mkdir -p ${INSTALLDIR}/etc/php5/${DOMAIN}
cp ${SRCDIR}/${PHP5}/php.ini-dist ${INSTALLDIR}/etc/php5/${DOMAIN}/php.ini
#copy PHP CGI
mkdir -p ${HOME}/${DOMAIN}/cgi-bin
chmod 0755 ${HOME}/${DOMAIN}/cgi-bin
cp ${INSTALLDIR}/bin/php ${HOME}/${DOMAIN}/cgi-bin/php.cgi
rm -rf $SRCDIR $DISTDIR
echo ---------- INSTALL COMPLETE! ----------
Alternative PHP 5 install scripts
These are alternative PHP 5 install scripts created by Charles Wiltgen, who created them to work around problems he was having with the "main" PHP 5 install script.
First, run php5-install-prep.sh to download and unpack all prerequisite packages.
Then, run php5-install.sh to compile and install PHP 5 and all prerequisites.
php5-install-prep.sh
#!/bin/sh
# Version 0.7, 2008-08-20
#
# - Updated 2008-08-20 by Beau -
# -Updated pretty much every package.
# - Updated 2007-12-16 by AskApache
# - Implemented functions to fetch the URI and decompress it
# - Added a couple more error-checks
# - Replaced wget with cURL
# - Added more to help keep it from getting killed
# - Updated to php-5.2.3, curl-7.17.1, freetype-2.3.5
# - Updated 2007-01-15 by Charles Wiltgen (charles@wiltgen.net)
# - Make "nicer" to help keep it from getting killed by DreamHost
# - Make less verbose to keep signal-to-noise level high
# - Updated 2006-12-25 by Carl McDade (hiveminds.co.uk)
# - Allow memory limit and freetype
# Abort on any errors
set -e
# The domain in which to install the PHP CGI script.
export DOMAIN="your-root-domain.com"
# Where do you want all this stuff built? I'd recommend picking a local filesystem.
# ***Don't pick a directory that already exists!***
SRCDIR=${HOME}/source
# And where should it be installed?
INSTALLDIR=${HOME}/php5
# Set DISTDIR to somewhere persistent, if you plan to muck around with this
# script and run it several times!
DISTDIR=${HOME}/dist
# Update version information here.
PHP5="php-5.2.6"
LIBICONV="libiconv-1.12"
LIBMCRYPT="libmcrypt-2.5.8"
LIBXML2="libxml2-2.6.32"
LIBXSLT="libxslt-1.1.24"
MHASH="mhash-0.9.9"
ZLIB="zlib-1.2.3"
CURL="curl-7.18.2"
LIBIDN="libidn-1.9"
OPENSSL="openssl-0.9.8h"
CCLIENT="imap"
CCLIENT_DIR="imap-2007b"
FREETYPE="freetype-2.3.7"
# Push the install dir's bin directory into the path
export PATH=${INSTALLDIR}/bin:$PATH
function aa_unpack () {
# compressed, tar and gzip files to DISTDIR
if [ -f $DISTDIR/$1* ] ; then
echo Extracting "$1";
zcat ${DISTDIR}/$1* | tar -xvf - &>/dev/null;
echo Done.; echo; wait
fi
}
function aa_grab () {
#saves file to SRCDIR
echo `basename $1`
curl -L --retry 20 --max-time 1800 --retry-delay 30 -# -f --max-redirs 4 --remote-name "$1"
}
echo
echo --------------------------------------------------
echo -- Run this script before php5-install.sh --
echo --------------------------------------------------
echo
echo - Downloads and unpacks all prerequisite packages
echo - **SRCDIR and DISTDIR will be deleted**
echo
read -p " (Press any key to continue)" temp;
echo;echo
# cleanup to remove source and dist directories if present
if [ -d "$SRCDIR" ] || [ -d "$DISTDIR" ];then
echo
echo --- Cleaning up any previous attempts ---
rm -rf $SRCDIR $DISTDIR &>/dev/null
echo Done.
echo
wait
fi
# set up directories
mkdir -p ${SRCDIR} ${INSTALLDIR} ${DISTDIR} &>/dev/null
# Get all the required packages
echo;echo
echo --- Downloading all required packages ---
echo
cd ${DISTDIR}
aa_grab http://us.php.net/distributions/${PHP5}.tar.gz
aa_grab http://mirrors.usc.edu/pub/gnu/libiconv/${LIBICONV}.tar.gz
aa_grab http://umn.dl.sourceforge.net/sourceforge/mcrypt/${LIBMCRYPT}.tar.gz
aa_grab ftp://xmlsoft.org/libxml2/${LIBXML2}.tar.gz
aa_grab ftp://xmlsoft.org/libxml2/${LIBXSLT}.tar.gz
aa_grab http://umn.dl.sourceforge.net/sourceforge/mhash/${MHASH}.tar.gz
aa_grab http://www.zlib.net/${ZLIB}.tar.gz
aa_grab http://curl.haxx.se/download/${CURL}.tar.gz
aa_grab http://download.savannah.gnu.org/releases/freetype/${FREETYPE}.tar.gz
aa_grab ftp://alpha.gnu.org/pub/gnu/libidn/${LIBIDN}.tar.gz
aa_grab http://www.openssl.org/source/${OPENSSL}.tar.gz
aa_grab ftp://ftp.cac.washington.edu/imap/${CCLIENT}.tar.Z
wait
echo Done.
# Extract the files from the required packages.
echo;echo;echo
echo --- Unpacking downloaded archives. This process may take several minutes! ---
echo
cd ${SRCDIR}
aa_unpack ${PHP5}
aa_unpack ${LIBICONV}
aa_unpack ${LIBMCRYPT}
aa_unpack ${LIBXML2}
aa_unpack ${LIBXSLT}
aa_unpack ${MHASH}
aa_unpack ${ZLIB}
aa_unpack ${CURL}
aa_unpack ${LIBIDN}
aa_unpack ${OPENSSL}
aa_unpack ${CCLIENT}
aa_unpack ${FREETYPE}
wait
echo --------------------------------------------------
echo -- Done downloading and unpacking prerequisites --
echo --------------------------------------------------
exit 0;
php5-install.sh
#!/bin/sh
echo php5-install.sh
echo - This script compiles and installs PHP 5 and all prerequisites
echo - Run php5-install-prep.sh before running this script
echo
read -p "(Press any key to continue)" temp;
echo
date
# Version 0.7, 2008-08-20
#
# - Updated 2008-08-20 by Beau - (tesseract@hush.com)
# -Updated pretty much every package.
# - Updated 2008-04-05 by Tom Ransom (transom@well.com)
# - Added missing continuation slash to line #81 (after enable-memory-limit)
# - updated 2008-01-16 by osha (osha@iqresearch.com)
# - fixed some typos and made more explicit what the domain variable is
# - Updated 2007-12-20 by David Szpunar (infotech.lakeviewchurch.org)
# - Update versions of freetype, curl, php5 to match php5-install-prep.sh
# - Updated 2007-01-15 by Charles Wiltgen (charles@wiltgen.net)
# - Make "nicer" to help keep it from getting killed by DreamHost
# - Make less verbose to keep signal-to-noise level high
# - Updated 2006-12-25 by Carl McDade (hiveminds.co.uk)
# - Allow memory limit and freetype
# Abort on any errors
set -e
##################################
# User-editable settings (start) #
##################################
# The domain in which to install the PHP CGI script
# this is the name of the folder that your domain reads files from
# (no "www" unless it is in the folder name)
export DOMAIN="your-domain-here.com"
# Where do you want all this stuff built? I'd recommend picking a local
# filesystem.
# ***Don't pick a directory that already exists!*** We clean up after
# ourselves at the end!
SRCDIR=${HOME}/source
# And where should it be installed?
INSTALLDIR=${HOME}/php5
# Set DISTDIR to somewhere persistent, if you plan to muck around with this
# script and run it several times!
DISTDIR=${HOME}/dist
# Update version information here.
PHP5="php-5.2.6"
LIBICONV="libiconv-1.12"
LIBMCRYPT="libmcrypt-2.5.8"
LIBXML2="libxml2-2.6.32"
LIBXSLT="libxslt-1.1.24"
MHASH="mhash-0.9.9"
ZLIB="zlib-1.2.3"
CURL="curl-7.18.2"
LIBIDN="libidn-1.9"
OPENSSL="openssl-0.9.8h"
CCLIENT="imap"
CCLIENT_DIR="imap-2007b"
FREETYPE="freetype-2.3.7"
# What PHP features do you want enabled?
PHPFEATURES="--prefix=${INSTALLDIR} \
--with-config-file-path=${INSTALLDIR}/etc/php5/${DOMAIN} \
--enable-fastcgi \
--enable-force-cgi-redirect \
--with-xml \
--with-libxml-dir=${INSTALLDIR} \
--with-freetype-dir=${INSTALLDIR} \
--enable-soap \
--with-openssl=${INSTALLDIR} \
--with-mhash=${INSTALLDIR} \
--with-mcrypt=${INSTALLDIR} \
--with-zlib-dir=${INSTALLDIR} \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-gd \
--enable-gd-native-ttf \
--enable-memory-limit \
--enable-ftp \
--enable-exif \
--enable-sockets \
--enable-wddx \
--with-iconv=${INSTALLDIR} \
--enable-sqlite-utf8 \
--enable-calendar \
--with-curl=${INSTALLDIR} \
--enable-mbstring \
--enable-mbregex \
--with-mysql=/usr \
--with-mysqli \
--without-pear \
--with-gettext \
--with-imap=${INSTALLDIR} \
--with-imap-ssl=/usr"
################################
# User-editable settings (end) #
################################
echo ------------------------------------------------------
echo -- Compiling and installing PHP 5 and prerequisites --
echo ------------------------------------------------------
# Pre-prep cleanup
rm -rf $INSTALLDIR
# Build packages in the required order to satisfy dependencies.
#
# libiconv
#
echo
echo --- Building libiconv
echo
cd ${SRCDIR}/${LIBICONV}
echo " Configuring..."
./configure --enable-extra-encodings --prefix=${INSTALLDIR} \
> /dev/null 2>&1
echo " Making..."
nice -n 19 make > /dev/null 2>&1
echo " Installing..."
make install > /dev/null 2>&1
echo " Done!"
#
# libxml2
#
echo
echo --- Building libxml2
echo
cd ${SRCDIR}/${LIBXML2}
echo " Configuring..."
./configure --with-iconv=${INSTALLDIR} --prefix=${INSTALLDIR} \
> /dev/null 2>&1
echo " Making..."
nice -n 19 make > /dev/null 2>&1
echo " Installing..."
make install > /dev/null 2>&1
echo " Done!"
#
# libxslt
#
echo
echo --- Building libxslt
echo
cd ${SRCDIR}/${LIBXSLT}
echo " Configuring..."
./configure --prefix=${INSTALLDIR} \
--with-libxml-prefix=${INSTALLDIR} \
--with-libxml-include-prefix=${INSTALLDIR}/include/ \
--with-libxml-libs-prefix=${INSTALLDIR}/lib/ \
> /dev/null 2>&1
echo " Making..."
nice -n 19 make > /dev/null 2>&1
echo " Installing..."
make install > /dev/null 2>&1
echo " Done!"
#
# zlib
#
echo
echo --- Building: zlib
echo
cd ${SRCDIR}/${ZLIB}
echo " Configuring..."
./configure --shared --prefix=${INSTALLDIR} \
> /dev/null 2>&1
echo " Making..."
nice -n 19 make > /dev/null 2>&1
echo " Installing..."
make install > /dev/null 2>&1
echo " Done!"
#
# libmcrypt
#
echo
echo --- Building: libmcrypt
echo
cd ${SRCDIR}/${LIBMCRYPT}
echo " Configuring..."
./configure --disable-posix-threads --prefix=${INSTALLDIR} \
> /dev/null 2>&1
echo " Making..."
nice -n 19 make > /dev/null 2>&1
echo " Installing..."
make install > /dev/null 2>&1
echo " Done!"
#libmcrypt lltdl issue!!
cd ${SRCDIR}/${LIBMCRYPT}/libltdl
echo " Configuring..."
./configure --prefix=${INSTALLDIR} --enable-ltdl-install \
> /dev/null 2>&1
echo " Making..."
nice -n 19 make > /dev/null 2>&1
echo " Installing..."
make install > /dev/null 2>&1
echo " Done!"
#
# mhash
#
echo
echo --- Building: mhash
echo
cd ${SRCDIR}/${MHASH}
echo " Configuring..."
./configure --prefix=${INSTALLDIR} \
> /dev/null 2>&1
echo " Making..."
nice -n 19 make > /dev/null 2>&1
echo " Installing..."
make install > /dev/null 2>&1
echo " Done!"
#
# freetype
#
echo
echo --- Building: freetype
echo
cd ${SRCDIR}/${FREETYPE}
echo " Configuring..."
./configure --prefix=${INSTALLDIR} \
> /dev/null 2>&1
echo " Making..."
nice -n 19 make > /dev/null 2>&1
echo " Installing..."
make install > /dev/null 2>&1
echo " Done!"
#
# libidn
#
echo
echo --- Building: libidn
echo
cd ${SRCDIR}/${LIBIDN}
echo " Configuring..."
./configure --with-iconv-prefix=${INSTALLDIR} --prefix=${INSTALLDIR} \
> /dev/null 2>&1
echo " Making..."
nice -n 19 make > /dev/null 2>&1
echo " Installing..."
make install > /dev/null 2>&1
echo " Done!"
#
# cURL
#
echo
echo --- Building: cURL
echo
cd ${SRCDIR}/${CURL}
echo " Configuring..."
./configure --with-ssl=${INSTALLDIR} --with-zlib=${INSTALLDIR} \
--with-libidn=${INSTALLDIR} --enable-ipv6 --enable-cookies \
--enable-crypto-auth --prefix=${INSTALLDIR} \
> /dev/null 2>&1
echo " Making..."
nice -n 19 make > /dev/null 2>&1
echo " Installing..."
make install > /dev/null 2>&1
echo " Done!"
#
# OpenSSL
#
echo
echo --- Building: OPENSSL
echo
cd ${SRCDIR}/${OPENSSL}
echo " Configuring..."
./config --prefix=${INSTALLDIR} \
> /dev/null 2>&1
echo " Making..."
nice -n 19 make > /dev/null 2>&1
echo " Installing..."
make install
echo " Done!"
#
# c-client
#
echo
echo --- Building: c-client
echo
cd ${SRCDIR}/${CCLIENT_DIR}
echo " Making..."
make ldb > /dev/null 2>&1
echo " Installing..."
cp c-client/c-client.a ${INSTALLDIR}/lib/libc-client.a
cp c-client/*.h ${INSTALLDIR}/include
echo " Done!"
#
# PHP 5
#
echo
echo --- Building PHP 5 ---
echo
cd ${SRCDIR}/${PHP5}
echo " Configuring..."
./configure ${PHPFEATURES} \
> /dev/null 2>&1
echo " Making..."
nice -n 19 make > /dev/null 2>&1
echo " Installing..."
make install > /dev/null 2>&1
echo " Copying configuration file (PHP.INI)"
mkdir -p ${INSTALLDIR}/etc/php5/${DOMAIN}
cp ${SRCDIR}/${PHP5}/php.ini-dist ${INSTALLDIR}/etc/php5/${DOMAIN}/php.ini
echo " Copying PHP CGI"
mkdir -p ${HOME}/${DOMAIN}/cgi-bin
chmod 0755 ${HOME}/${DOMAIN}/cgi-bin
cp ${INSTALLDIR}/bin/php-cgi ${HOME}/${DOMAIN}/cgi-bin/php.cgi
# uncomment the line below for *older* versions of php5 (<5.23)
# cp ${INSTALLDIR}/bin/php ${HOME}/${DOMAIN}/cgi-bin/php.cgi
echo
echo --- Cleaning up
echo
rm -rf $SRCDIR $DISTDIR
echo ---------------------------------------
echo ---------- INSTALL COMPLETE! ----------
echo ---------------------------------------
# Finally, you need to add this to your site's .htaccess file to use
# the version of PHP that you've just compiled:
#
# AddHandler phpFive .php
# Action phpFive /cgi-bin/php.cgi
Another Alternative PHP 5 install script
This is a modified version of the original install script, that Skwerl used to successfully install his own PHP5 on bonnano on September 23rd, 2008. Being provided for whatever it's worth. Be sure to set your domain.
php5-skwerl.sh
#!/bin/sh
# Script updated 2008-09-23 by Skwerl (antiquiet.com) to work with dreamhost's debian etch
# Script updated 2007-11-24 by Andrew (ajmconsulting.net) to allow 3rd wget line to pass
# Script updated 2006-12-25 by Carl McDade (hiveminds.co.uk) to allow memory limit and freetype
#
# LIBMCRYPT version information (was set as static download file name previously.)
#
# Save the code to a file as *.sh
# Abort on any errors
#
set -e
# The domain in which to install the PHP CGI script.
export DOMAIN="YOURDOMAIN.TLD"
# Where do you want all this stuff built? I'd recommend picking a local
# filesystem.
# ***Don't pick a directory that already exists!*** We clean up after
# ourselves at the end!
SRCDIR=${HOME}/source
# And where should it be installed?
INSTALLDIR=${HOME}/php5
# Set DISTDIR to somewhere persistent, if you plan to muck around with this
# script and run it several times!
DISTDIR=${HOME}/dist
# Pre-download clean up!!!!
rm -rf $SRCDIR $DISTDIR
# Update version information here.
PHP5="php-5.2.5"
LIBICONV="libiconv-1.11"
LIBMCRYPT="libmcrypt-2.5.7"
LIBXML2="libxml2-2.6.27"
LIBXSLT="libxslt-1.1.18"
MHASH="mhash-0.9.7.1"
ZLIB="zlib-1.2.3"
CURL="curl-7.14.0"
LIBIDN="libidn-0.6.8"
CCLIENT="imap-2004g"
CCLIENT_DIR="imap-2004g" # Another pest!
FREETYPE="freetype-2.2.1"
OPENSSL="openssl-0.9.8i"
# What PHP features do you want enabled?
PHPFEATURES="--prefix=${INSTALLDIR} \
--with-config-file-path=${INSTALLDIR}/etc/php5/${DOMAIN} \
--enable-fastcgi \
--enable-force-cgi-redirect \
--with-xml \
--with-libxml-dir=${INSTALLDIR} \
--with-freetype-dir=${INSTALLDIR} \
--enable-soap \
--with-openssl=${INSTALLDIR} \
--with-mhash=${INSTALLDIR} \
--with-mcrypt=${INSTALLDIR} \
--with-zlib-dir=${INSTALLDIR} \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-gd \
--enable-gd-native-ttf \
--enable-memory-limit \
--enable-ftp \
--enable-exif \
--enable-sockets \
--enable-wddx \
--with-iconv=${INSTALLDIR} \
--enable-sqlite-utf8 \
--enable-calendar \
--with-curl=${INSTALLDIR} \
--enable-mbstring \
--enable-mbregex \
--enable-bcmath \
--with-mysql=/usr \
--with-mysqli \
--without-pear \
--with-gettext \
--with-imap=${INSTALLDIR} \
--without-imap-ssl"
# ---- end of user-editable bits. Hopefully! ----
# Push the install dir's bin directory into the path
export PATH=${INSTALLDIR}/bin:$PATH
# set up directories
mkdir -p ${SRCDIR}
mkdir -p ${INSTALLDIR}
mkdir -p ${DISTDIR}
cd ${DISTDIR}
# Get all the required packages
wget -c http://us.php.net/get/${PHP5}.tar.gz/from/this/mirror
wget -c http://mirrors.usc.edu/pub/gnu/libiconv/${LIBICONV}.tar.gz
wget -c http://easynews.dl.sourceforge.net/sourceforge/mcrypt/${LIBMCRYPT}.tar.gz
wget -c ftp://xmlsoft.org/libxml2/${LIBXML2}.tar.gz
wget -c ftp://xmlsoft.org/libxml2/${LIBXSLT}.tar.gz
wget -c http://superb-west.dl.sourceforge.net/sourceforge/mhash/${MHASH}.tar.gz
wget -c http://www.zlib.net/${ZLIB}.tar.gz
wget -c http://curl.haxx.se/download/${CURL}.tar.gz
wget -c http://kent.dl.sourceforge.net/sourceforge/freetype/${FREETYPE}.tar.gz
wget -c ftp://alpha.gnu.org/pub/gnu/libidn/${LIBIDN}.tar.gz
wget -c ftp://ftp.cac.washington.edu/imap/old/${CCLIENT}.tar.Z
wget -c http://www.openssl.org/source/${OPENSSL}.tar.gz
echo ---------- Unpacking downloaded archives. This process may take several minutes! ----------
cd ${SRCDIR}
# Unpack them all
echo Extracting ${PHP5}...
tar xzf ${DISTDIR}/${PHP5}.tar.gz
echo Done.
echo Extracting ${LIBICONV}...
tar xzf ${DISTDIR}/${LIBICONV}.tar.gz
echo Done.
echo Extracting ${LIBMCRYPT}...
tar xzf ${DISTDIR}/${LIBMCRYPT}.tar.gz
echo Done.
echo Extracting ${LIBXML2}...
tar xzf ${DISTDIR}/${LIBXML2}.tar.gz
echo Done.
echo Extracting ${LIBXSLT}...
tar xzf ${DISTDIR}/${LIBXSLT}.tar.gz
echo Done.
echo Extracting ${MHASH}...
tar xzf ${DISTDIR}/${MHASH}.tar.gz
echo Done.
echo Extracting ${ZLIB}...
tar xzf ${DISTDIR}/${ZLIB}.tar.gz
echo Done.
echo Extracting ${CURL}...
tar xzf ${DISTDIR}/${CURL}.tar.gz
echo Done.
echo Extracting ${LIBIDN}...
tar xzf ${DISTDIR}/${LIBIDN}.tar.gz
echo Done.
echo Extracting ${CCLIENT}...
uncompress -cd ${DISTDIR}/${CCLIENT}.tar.Z |tar x
echo Done.
echo Extracting ${FREETYPE}...
tar xzf ${DISTDIR}/${FREETYPE}.tar.gz
echo Done.
echo Extracting ${OPENSSL}...
tar xzf ${DISTDIR}/${OPENSSL}.tar.gz
echo Done.
# Build them in the required order to satisfy dependencies.
#libiconv
cd ${SRCDIR}/${LIBICONV}
./configure --enable-extra-encodings --prefix=${INSTALLDIR}
# make clean
make
make install
#libxml2
cd ${SRCDIR}/${LIBXML2}
./configure --with-iconv=${INSTALLDIR} --prefix=${INSTALLDIR}
# make clean
make
make install
#libxslt
cd ${SRCDIR}/${LIBXSLT}
./configure --prefix=${INSTALLDIR} \
--with-libxml-prefix=${INSTALLDIR} \
--with-libxml-include-prefix=${INSTALLDIR}/include/ \
--with-libxml-libs-prefix=${INSTALLDIR}/lib/
# make clean
make
make install
#zlib
cd ${SRCDIR}/${ZLIB}
./configure --shared --prefix=${INSTALLDIR}
# make clean
make
make install
#libmcrypt
cd ${SRCDIR}/${LIBMCRYPT}
./configure --disable-posix-threads --prefix=${INSTALLDIR}
# make clean
make
make install
#libmcrypt lltdl issue!!
cd ${SRCDIR}/${LIBMCRYPT}/libltdl
./configure --prefix=${INSTALLDIR} --enable-ltdl-install
# make clean
make
make install
#mhash
cd ${SRCDIR}/${MHASH}
./configure --prefix=${INSTALLDIR}
# make clean
make
make install
#freetype
cd ${SRCDIR}/${FREETYPE}
./configure --prefix=${INSTALLDIR}
# make clean
make
make install
#libidn
cd ${SRCDIR}/${LIBIDN}
./configure --with-iconv-prefix=${INSTALLDIR} --prefix=${INSTALLDIR}
# make clean
make
make install
#cURL
cd ${SRCDIR}/${CURL}
./configure --with-ssl=${INSTALLDIR} --with-zlib=${INSTALLDIR} \
--with-libidn=${INSTALLDIR} --enable-ipv6 --enable-cookies \
--enable-crypto-auth --prefix=${INSTALLDIR}
# make clean
make
make install
# c-client
cd ${SRCDIR}/${CCLIENT_DIR}
make -i ldb SSLTYPE=none
# Install targets are for wusses!
cp c-client/c-client.a ${INSTALLDIR}/lib/libc-client.a
cp c-client/*.h ${INSTALLDIR}/include
#OpenSSL
cd ${SRCDIR}/${OPENSSL}
./config --prefix=${INSTALLDIR} --openssldir=${INSTALLDIR}
make
make install
echo - about to build php5...
echo
read -p "(Press any key to continue)" temp;
echo
#PHP 5
cd ${SRCDIR}/${PHP5}
./configure ${PHPFEATURES}
# make clean
make
make install
#copy config file
mkdir -p ${INSTALLDIR}/etc/php5/${DOMAIN}
cp ${SRCDIR}/${PHP5}/php.ini-dist ${INSTALLDIR}/etc/php5/${DOMAIN}/php.ini
#copy PHP CGI
mkdir -p ${HOME}/${DOMAIN}/cgi-bin
chmod 0755 ${HOME}/${DOMAIN}/cgi-bin
cp ${INSTALLDIR}/bin/php ${HOME}/${DOMAIN}/cgi-bin/php.cgi
rm -rf $SRCDIR $DISTDIR
echo ---------- INSTALL COMPLETE! ----------
be sure to add this to an .htaccess file:
Options +ExecCGI AddHandler php-cgi .php Action php-cgi /cgi-bin/php.cgi <FilesMatch "^php5?\.(ini|cgi)$"> Order Deny,Allow Deny from All Allow from env=REDIRECT_STATUS </FilesMatch>
if you get 500 errors, run this from the shell:
cp ~/php5/bin/php-cgi ~/DOMAIN.TLD/cgi-bin/php.cgi
Also note that when using shell access, do not create a new shell account. Simply edit your existing username for this domain.
Possible Errors
Update to above configure command 04/21/08
I was not able to compile php5 using the script above. At first I ran into problems where it could not find header files (easy.h for example), which turned out to be that you had to use absolute paths and not ~/ for home. I also had to remove some things like calender since they are no longer options! Here is the command line that the script should probably be using:
./configure --prefix=$HOME/php5 --with-config-file-path=$HOME/etc/ --enable-fastcgi --enable-force-cgi-redirect --with-libxml-dir=$HOME/php5 --with-libxml-dir=$HOME/php5 --with-freetype-dir=$HOME/php5 --with-openssl=/usr --with-mhash=$HOME/php5 --with-mcrypt=$HOME/php5 --with-zlib-dir=$HOME/php5 --with-jpeg-dir=/usr --with-png-dir=/usr --with-gd --enable-gd-native-ttf --enable-ftp --enable-exif --enable-sockets --enable-wddx --with-iconv=$HOME/php5 --with-curl=$HOME/php5 --enable-mbstring --enable-mbregex --with-mysql=/usr --without-pear --with-gettext --with-imap=$HOME/php5 --with-imap-ssl=/usr
Step 6 Error
If you receive the error export: Command not found when you run step 6 then you are using a shell other than Bash. To get around this, follow these steps:
- edit the file by entering the command:
vim installscript
- hit i for insert mode, then enter the following (must be the first line):
#!/bin/bash
- then hit Esc, type :wq (that's 'colon', 'w', 'q'), and press Enter to save and exit.
- repeat step 6 from above.
Troubleshooting
All user comments should be confined to talk pages, and writing should not be done from the perspective of the author.
We are hoping to create articles that meet certain standards. Please discuss this issue on the talk page. Editing help is available.
If you run in trouble, try to go trough the process step by step. It's no bad idea to run "make clean" just before a "make" command. If nothing else (Google, skilled son/daughter) can help. Feel free to post your problem(s) to the discussion page.
imap-2004g Errors without SSL set up
The problems I ran into while installing both php4 and 5 was with imap-2004g. Most people don't have or need SSL installed in every directory, but if you don't have it set up you will get an error using the script above which says:
If you get No such file error messages for files x509.h, ssl.h, pem.h, buffer.h, bio.h, and crypto.h, that means that OpenSSL is not installed on your system. Either install OpenSSL first or build with command: make lnx SSLTYPE=none
So then I went into my new /home/USERNAME/source/imap-2004g directory (created by the install script) typed:
install clean make lnx SSLTYPE=none
But that didn't work because Dreamhost uses: slx. So you need to type
make slx SSLTYPE=none
Which is great. But then you have to go back into the install script and change the php preference references to openssl to:
--without-openssl \
--without-imap-ssl"
Also take out the wgets and untarring that you've already done, save the script again and it should work for you.
UPDATE
With the new version of the alternate install script, you should be able to get by with only changing --with-imap-ssl=/usr to --without-imap-ssl but leaving the openssl alone.
Also, if the c-client install hangs on you, try changing this in the script and running it again:
make ldb > /dev/null 2>&1
to
make -i ldb SSLTYPE=none
Note: Doing so will cause the output to be sent to you meaning that you will have to wait until this point in your script(about 50min) then come back and hit "y" then enter/return twice at the prompt. This is the only way I could get c-client to install properly.
Internal Server Error
If some of your php files return an internal server error (Server error 500) the install script probably copied the php binary when you needed the php-cgi binary. executecp ~/php5/bin/php-cgi ~/DOMAINNAME/cgi-bin/php.cgiand you will probably be fine.
"Bad interpreter" or "command not found" errors
If you create the file on Windows, then upload to the server, you can get the above errors when running the script.
It's easy to fix.
vi installscript
then, within vi enter
:set fileformat=unix
:wq
Now it should run correctly.
Borrow an Already Compiled PHP
Instead of compiling your own PHP, you can copy Dreamhost's already working executable into your own directory. From there, you can change the php.ini as you see fit. More information can be found about this in PHP.ini.
AddHandler vs. AddType
On our own servers, we use the AddType Apache directive:
AddType application/x-httpd-php .php Action application/x-httpd-php /cgi-bin/php.cgi
- however this did not work for us at DreamHost. Instead, we had to use the AddHandler Apache directive:
AddHandler php-cgi .php Action php-cgi /cgi-bin/php.cgi
See also
Categories: Unsupported Instructions | Cleanup | Web | How-To | PHP | UNIX-based

