Php5 on Dreamhost

Im pretty satisfied with DreamHost so far, although it kind of urked me that they did not support native php SOAP. Why not? It seems like it would be a pretty popular thing.. Anyway, I’m not a big fan of NuSoap or any of the other SOAP libraries written in PHP so I started on my journey to custom install PHP5. All in all it went well, and only took roughly an hour. I can now host all my Google API goodies here which is basically the point of the install :) .

Heres how to run the install [on Mac OsX]: – Elaboration on DreamHost Wiki [Full Article]

  1. Open your favorite text editor and paste in the script below – MAKE SURE TO CHANGE YOUR DOMAIN on line 4
  2. save as “installscript” to your Desktop, or wherver else – just as long as you can find it in the terminal
  3. Open your terminal (/Applications/Utilities) and navigate to your Desktop (cd ~/Desktop - or CD Desktop)
  4. [client side] Type “scp installscript {USER}@{DOMAIN}:
  5. [client side] Type “ssh {USER}@{DOMAIN}” to log into your account
  6. [server-side] Type “chmod +x installscript” now make sure your directory is clear of the directories “php5, source, dist” if they are in there for some reason other than this install, run “rm -rf {DIRNAME}” to get rid of them. The install script will error if those directories are in place.
  7. [server-side] Type “./installscript” – then grab a beer and watch T.V.
  8. [server-side] Type “cd {DOMAIN}” then create an .htaccess file containing something like
    AddHandler php-cgi .php Action php-cgi /cgi-bin/php.cgi
  9. Now you should be in business, try a script to see if everything is enabled that you need.. if not, modify the script below to add/remove any extras that you want
  10. *Read the bottom for notes on how to keep things clean & simple

The Script

#!/bin/bash

# Abort on any errors
set -e

# The domain in which to install the PHP CGI script.
export DOMAIN="{YOUR DOMAIN HERE}"

# 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.1.4"
LIBICONV="libiconv-1.10"
LIBMCRYPT="libmcrypt-2.5.7"
LIBXML2="libxml2-2.6.26"
LIBXSLT="libxslt-1.1.17"
MHASH="mhash-0.9.7"
ZLIB="zlib-1.2.3"
CURL="curl-7.15.4"
LIBIDN="libidn-0.6.3"
CCLIENT="c-client"
CCLIENT_DIR="imap-2004g" # Another pest!

# What PHP features do you want enabled?
PHPFEATURES="--prefix=${INSTALLDIR}
 --with-config-file-path=${INSTALLDIR}/etc/php5/${DOMAIN}
 --enable-force-cgi-redirect
 --with-xml
 --with-libxml-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-ftp
 --with-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"

# ---- 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/distributions/${PHP5}.tar.gz
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 http://ftp.acc.umu.se/pub/GNOME/sources/libxml2/2.6/${LIBXML2}.tar.gz
wget -c http://ftp.acc.umu.se/pub/GNOME/sources/libxslt/1.1/${LIBXSLT}.tar.gz
wget -c http://easynews.dl.sourceforge.net/sourceforge/mhash/${MHASH}.tar.gz
#wget -c http://www.zlib.net/${ZLIB}.tar.gz
wget -c http://easynews.dl.sourceforge.net/sourceforge/libpng/${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 ftp://ftp.cac.washington.edu/imap/${CCLIENT}.tar.Z

echo ---------- Unpacking downloaded archives. This process may take several minutes! ----------

cd ${SRCDIR}
# Unpack them all
tar xzf ${DISTDIR}/${PHP5}.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.gz
tar xzf ${DISTDIR}/${ZLIB}.tar.gz
tar xzf ${DISTDIR}/${CURL}.tar.gz
tar xzf ${DISTDIR}/${LIBIDN}.tar.gz
uncompress -cd ${DISTDIR}/${CCLIENT}.tar.Z |tar x

# 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
make install

#mhash
cd ${SRCDIR}/${MHASH}
./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
echo ---------- INSTALL COMPLETE! ----------

Notes to keep things clean
This install will only configure the 1 website right off the bat, but say you want to toggle between the PHP4/PHP5 DreamHostoptions, or your custom configured PHP5 install – on a PER-SITE basis. Its actually dead simple. Heres the ‘basic’ process that I use to get this done.

When you run this install PHP creates a {DOMAIN}/cgi-bin/ which is good and all, but since you want to keep the option of using a custom install dynamic this isn’t as good as we want it.

What i did was to make a ~/cgi-bin/ in your home directory and link whore it out. To do this just get in your terminal again and get to your {DOMAIN}s root directory and type “mv cgi-bin/ ~/cgi-bin/” then without leaving your domain’s root type “ln -s ~/cgi-bin/ cgi-bin” to create a symbolic link. Now if you want to shut off the custom php5 you can “rm cgi-bin” and take those 2 lines out of your .htaccess file.

For every other domain you want to have this install run on is 1 step off from just “cd {DOMAiN}“, “ln -s ~/cgi-bin/ cgi-bin“, “vim .htaccess” (putting in those 2 lines from above). For each new domain you need to create a php.ini file (or folder at least) in the ~/php5/etc/php5/ dir. You can again use a symbolic link here if nothing is changing. Just copy it from your default {DOMAIN} folder back to the ~/php5/etc/php5/ folder and symbolic link it to each new directory you create. Of course, for unique .inis you would need to copy it and modify it.

I hope that helps anyone out there keep their custom php5 install under wraps. Now if they would just enable those few extra modules so i don’t have to keep updating php manually :)




Comments

No comments yet.

Add Yours

  • Author Avatar

    YOU


Comment Arrow



About Author

Rob Hurring

Ruby, Rails, PHP, bash... oh my!