Installing PHP4
From DreamHost
| The instructions provided in this article or section are considered advanced. You are expected to be knowledgeable in the UNIX shell. |
| As of August 8, 2008, PHP 4 has been discontinued, and will not receive any further security updates. Please use PHP 5 for all new installations. |
Compiling a Customized PHP 4
If you want to compile your own copy of PHP 4, the following script will download and compile it with some commonly-used additional extensions. You can also compile PHP 5. To compile PHP 4:
- log in to your account using SSH
- create a new file by entering the command:
vim installscript
- copy the text below into a text editor and replace ***YOUR DOMAIN NAME*** on the 3rd line with your site's domain name. Copy the new contents to your clipboard. MAKE SURE YOU USE THE SAME CASE THAT APPEARS IN THE DIRECTORY LISTING (UPPER or lower).
- in PuTTY, hit i for insert mode, then right-click to paste your clipboard 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 it by entering the command:
./installscript
After it has finished you will need to edit your .htaccess file appropriately. Add something like:
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 of your directory folder (/home/USERNAME/EXAMPLE.COM/.htaccess)
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 Script
#!/bin/bash
# Version 0.1, 2009-02-07
#
# - Updated 2009-02-07 by Srinivasan A Paul Joseph - (mail@sripauljoseph.com)
# - Updated packages to the latest version that works with PHP4
# - Bug fixed: Break due to invalid braces use
# Abort on any errors
set -e
# The domain in which to install the PHP CGI script.
export DOMAIN="your-domain-here"
# Update version information here. If you get an error trying to retrieve the PHP distribution,
# double check this to see that the distribution you are trying to retrieve is correct and is
# available at the specified url.
PHP="php-4.4.9"
LIBICONV="libiconv-1.12"
LIBMCRYPT="libmcrypt-2.5.7"
LIBXML2="libxml2-2.6.32"
LIBXSLT="libxslt-1.1.24"
MHASH="mhash-0.9.4"; MHASH_TAR="${MHASH}a" # Pests!
ZLIB="zlib-1.2.3"
CURL="curl-7.15.2"
LIBIDN="libidn-0.6.9"
FREETYPE="freetype-2.3.8"
IMAP="imap-2004g"
# Set DISTDIR to somewhere persistent if you plan to muck around with this
# script and run it several times! It is where distributions are downloaded.
DISTDIR=${HOME}/dist
# Where do you want all this stuff built? Using a local filesystem is best.
# ***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? A versioned directory eases upgrades!
INSTALLDIR=${HOME}/${PHP}
# A simple name link eases use
ln -s ${INSTALLDIR} php
# What PHP features do you want enabled?
PHPFEATURES="--prefix=${INSTALLDIR} \
--with-config-file-path=${INSTALLDIR}/etc/php4 \
--enable-force-cgi-redirect \
--with-xml --with-libxml-dir=${INSTALLDIR} \
--with-freetype-dir=${INSTALLDIR} \
--enable-soap \
--with-xsl=${INSTALLDIR} \
--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-ftp \
--enable-sockets \
--enable-wddx \
--with-iconv=${INSTALLDIR} \
--enable-sqlite-utf8 \
--enable-calendar \
--with-curl=${INSTALLDIR} \
--enable-mbstring \
--enable-mbregex \
--with-mysql=/usr --with-mysqli \
--with-imap=${INSTALLDIR}"
# ---- end of user-editable bits. Hopefully! ----
# Push the install dir's bin directory into the path
export PATH=${INSTALLDIR}/bin:$PATH
#setup directories
mkdir -p ${SRCDIR}
mkdir -p ${INSTALLDIR}
mkdir -p ${DISTDIR}
cd ${DISTDIR}
# Get all the required packages
wget -c http://us3.php.net/get/${PHP}.tar.gz/from/us.php.net/mirror
wget -c http://ftp.gnu.org/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://easynews.dl.sourceforge.net/sourceforge/mhash/${MHASH_TAR}.tar.gz
wget -c http://www.zlib.net/${ZLIB}.tar.gz
wget -c http://curl.haxx.se/download/${CURL}.tar.gz
wget -c ftp://alpha.gnu.org/pub/gnu/libidn/${LIBIDN}.tar.gz
wget -c http://easynews.dl.sourceforge.net/sourceforge/freetype/${FREETYPE}.tar.gz
wget -c ftp://ftp.cac.washington.edu/imap/old/${IMAP}.tar.Z
cd ${SRCDIR}
# Unpack them all
tar xzf ${DISTDIR}/${PHP}.tar.gz
tar xzf ${DISTDIR}/${LIBICONV}.tar.gz
tar xzf ${DISTDIR}/${LIBMCRYPT}.tar.gz
tar xzf ${DISTDIR}/${LIBXML2}.tar.gz
tar xzf ${DISTDIR}/${LIBXSLT}.tar.gz
tar xzf ${DISTDIR}/${MHASH_TAR}.tar.gz
tar xzf ${DISTDIR}/${ZLIB}.tar.gz
tar xzf ${DISTDIR}/${CURL}.tar.gz
tar xzf ${DISTDIR}/${LIBIDN}.tar.gz
tar xzf ${DISTDIR}/${FREETYPE}.tar.gz
uncompress -cd ${DISTDIR}/${IMAP}.tar.Z |tar x
# Build them in the required order to satisfy dependencies.
#libiconv
cd ${SRCDIR}/${LIBICONV}
./configure --enable-extra-encodings --prefix=${INSTALLDIR}
make
make install
#libxml2
cd ${SRCDIR}/${LIBXML2}
./configure --with-iconv=${INSTALLDIR} --prefix=${INSTALLDIR}
make
make install
#libxslt
cd ${SRCDIR}/${LIBXSLT}
./configure --with-libxml-prefix=${INSTALLDIR} --prefix=${INSTALLDIR}
make
make install
#zlib
cd ${SRCDIR}/${ZLIB}
./configure --shared --prefix=${INSTALLDIR}
make
make install
#libmcrypt
cd ${SRCDIR}/${LIBMCRYPT}
./configure --disable-posix-threads --prefix=${INSTALLDIR}
make
make install
#mhash
cd ${SRCDIR}/${MHASH}
./configure --prefix=${INSTALLDIR}
make
make install
# FIXME: For some reason, mincludes.h isn't copied across
cp ${SRCDIR}/${MHASH}/include/mutils/mincludes.h ${INSTALLDIR}/include/mutils
#libidn
cd ${SRCDIR}/${LIBIDN}
./configure --with-iconv-prefix=${INSTALLDIR} --prefix=${INSTALLDIR}
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
make install
#freetype
cd ${SRCDIR}/${FREETYPE}
./configure --prefix=${INSTALLDIR}
make
make install
# imap
cd ${SRCDIR}/${IMAP}
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 4
cd ${SRCDIR}/${PHP}
./configure ${PHPFEATURES}
make
make install
#copy config file
mkdir -p ${INSTALLDIR}/etc/php4
cp ${SRCDIR}/${PHP}/php.ini-dist ${INSTALLDIR}/etc/php4/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
echo ---------- INSTALL COMPLETE! ----------

