Posted: January 24, 2005. Updated: Feb. 11, 2005.
Setting up PHP 5 on Dreamhost
Here is how you can set up PHP5 on Dreamhost's Debian
Stable shared hosting
server. Dreamhost lets you compile
your own version of PHP as a CGI
binarywhen you are logged in through SSH. This means you can use
PHP 5 and
MySQL 4 at a shared server price, without needing a dedicated server of
your own!
This whole process took about one and a half hours to complete.
(Pressing the "Customize" button above will customize these
instructions for your particular setup on Dreamhost.)
# ---------------------- Setting up PHP 5 on a Dreamhost Account -----------------------
# ---------- Pre Compilation
-------------------
# Dreamhost's site:
http://www.dreamhost.com
# Type of hosting: Shared hosting with
SSH access, Debian Linux (Version: 'Debian Stable')
# This document is based on notes found
at:
#
https://panel.dreamhost.com/kbase/index.cgi?area=2538&keyword=compile%20php
#Text version of this document can be found at:
# http://www.moztips.com/php5_install/text_install.txt
# Replace
'your_dh_username' with your Dreamhost shell username.
# This is the username to which your
domain is mapped.
# Replace
'your_dh_domain.com' with to the domain to which your username is
mapped.
# Before
you begin
# Through the Dreamhost control
panel, increase the disk space quota for the user for this domain to
500 MB
# Wait up to two hours for this to take
effect. Then begin.
# Note: the following instructions were
slightly rewritten from the way I originally did it, to make them
easier to follow
# This could have resulted in minor
syntax errors when it comes to uncompressing / untarring things.
# Thus, please double check all paths
before beginning
# Feedback: Please send feedback to jay
[at - make this a real at] moztips.com
# ---------- Compilation --------------
# Make
dir for PHP binary and PHP libraries
cd /home/your_dh_username
# Make dir for compiled PHP binary and
compiled PHP libraries
mkdir php
cd php
mkdir lib
# Make dir for generated configure_help
output and install logs
cd ..
mkdir configure_help
mkdir install_logs
# Download
PHP 5 5.0.3 and PHP 5 Libraries Source Code
# Orig .tgz file has been updated (Jan
24, 2004).
# Strange errors after compilation
should now be fixed. Sorry for the original problem.
wget
www.moztips.com/php5_install/php5_libs_src.tgz
# This is a packaged, compressed file
that I made with all the source files you should need
gunzip php5_libs_src.tgz
tar -xf php5_libs_src.tar
# Remove / delete the PHP tar file
rm php5_libs_src.tar
# To download each library individually from
the orig. mirrors, pl. visit http://www.moztips.com/php5_install/manual_dloads.txt
# Above steps create a src dir here
# That src dir contains two subdirs:
# php-5.0.3 and php5libs
cd src/php5libs
# Download openssl library, which is used by curl library for SSL connections
wget http://www.openssl.org/source/openssl-0.9.7e.tar.gz
gunzip openssl-0.9.7e.tar.gz
tar -xf openssl-0.9.7e.tar
# -------------- Compile all PHP 5 libraries --------------------------
# ----------------- libiconv -----------------
cd libiconv-1.9.2
./configure
--prefix=/home/your_dh_username/php/lib >
/home/your_dh_username/install_logs/libiconv_configure.txt
make >
/home/your_dh_username/install_logs/libiconv_make.txt
# After running make, I got this
(safe to ignore):
# libtool: install: warning:
remember to run
# libtool --finish
/home/your_dh_username/php/lib/lib
make install
# ----------------- zlib -----------------
cd ../zlib-1.2.2
./configure
--prefix=/home/your_dh_username/php/lib >
/home/your_dh_username/install_logs/zlib_configure.txt
make >
/home/your_dh_username/install_logs/zlib_make.txt
make install
# ----------------- libxml2 -----------------
# Problems with compiling latest version
of the libxml2 library on Debian Stable
# Thousands of elfghack.h warnings, e.g.:
# elfgcchack.h:7598: warning:
`visibility' attribute directive ignored
# Using slightly older version (2.6.10)
cd ../libxml2-2.6.10
./configure
--prefix=/home/your_dh_username/php/lib >
/home/your_dh_username/install_logs/libxml2_configure.txt
make >
/home/your_dh_username/install_logs/libxml2_make.txt
# Got following warnings (safe to
ignore):
# catalog.c: In function
`xmlCatalogGetSystem':
# catalog.c:3536: warning: function
returns address of local variable
# catalog.c: In function
`xmlCatalogGetPublic':
# catalog.c:3580: warning: function
returns address of local variable
make install
# Warnings/ Errors (safe to ignore):
#/usr/bin/install: cannot stat
`./*.html': No such file or directory
#make[3]: [install-data-local] Error 1
(ignored)
#/usr/bin/install: cannot stat
`./html/index.sgml': No such file or directory
#make[3]: [install-data-local] Error 1
(ignored)
#libtool: install: warning: relinking
`libxml2mod.la'
# ----------------- libxslt1 -----------------
cd ../libxslt-1.1.3
# Need slightly older version of libxslt
# for it to work with older version of
libxml2
# Try libxslt-1.1.3
#For more info. on configure options for libxslt, try this:
#./configure --help >
/home/your_dh_username/configure_help/libxslt_configure_help.txt
# Note: libxslt needs to find libxml on
your system
# Relevant configuration options:
# --with-libxml-prefix=PFX Specify
location of libxml config
# --with-libxml-include-prefix=PFX
Specify location of libxml headers
# --with-libxml-libs-prefix=PFX Specify
location of libxml libs
# --with-libxml-src=DIR For libxml thats
not installed/compiled yet
./configure
--prefix=/home/your_dh_username/php/lib
--with-libxml-prefix=/home/your_dh_username/php/lib >
/home/your_dh_username/install_logs/libxslt1_configure.txt
make >
/home/your_dh_username/install_logs/libxslt1_make.txt
# Warnings (safe to ignore):
# xsltutils.c: In function
`xsltDefaultSortFunction':
# xsltutils.c:1074: warning: passing arg
1 of pointer to function discards qualifiers from pointer target
type
# xsltutils.c:1079: warning: passing arg
1 of pointer to function discards qualifiers from pointer target
type
# More warnings omitted here
make install
# Warnings (safe to ignore):
#libtool: install: warning: relinking
`libexslt.la'
#/usr/bin/install: cannot stat
`./html/index.sgml': No such file or directory
#make[2]: [install-data-local] Error 1
(ignored)
#libtool: install: warning: relinking
`libxsltmod.la'
# ----------------- libmcrypt
-----------------
cd ../libmcrypt-2.5.7
./configure --prefix=/home/your_dh_username/php/lib --disable-posix-threads >
/home/your_dh_username/install_logs/libmcrypt_configure.txt
make >
/home/your_dh_username/install_logs/libmcrypt_make.txt
make install
# Note the --disable-posix-threads line
# that is necessary for mcrypt to work
with PHP5
# ----------------- mhash -----------------
cd ../mhash-0.9.2
./configure
--prefix=/home/your_dh_username/php/lib >
/home/your_dh_username/install_logs/mhash_configure.txt
make >
/home/your_dh_username/install_logs/mhash_make.txt
# Lots of mhash warnings (safe to
ignore, I think):
# mhash.c:105: warning: initialization
from incompatible pointer type
make install
# ----------------- openssl (used by curl for SSL connections) -----------------
cd ../openssl-0.9.7e
# It seems to be ./config here and not ./configure ... not sure why ?!
./config
--prefix=/home/your_dh_username/php/lib > /home/your_dh_username/install_logs/openssl_configure.txt
make >
/home/your_dh_username/install_logs/openssl_make.txt
make install
# ----------------- curl -----------------
cd ../curl-7.12.3
./configure
--prefix=/home/your_dh_username/php/lib --with-ssl=/home/your_dh_username/php/lib --with-zlib=/home/your_dh_username/php/lib > /home/your_dh_username/install_logs/curl_configure.txt
make >
/home/your_dh_username/install_logs/curl_make.txt
make install
# ----------------------------------- PHP 5 Compilation
-------------------------------
#For more info. on configure options for PHP 5, try this:
#./configure --help >
/home/your_dh_username/configure_help/php5_configure_help.txt
# pico /home/your_dh_username/configure_help/php5_configure_help.txt
# Better yet, view all PHP 5 configure options here:
# http://www.moztips.com/php5_install/php_configure_help.txt
# Found out why mcrypt and mhash were not being compiled
# I needed --with-mcrypt and not --with-mcrypt-dir and --with-mhash and not --with-mhash-dir
# I had corrected this for libxslt earlier
# It pays to look at the linked PHP configure help file above, to make sure the correct configures options are used.
# Important note:
# I was previously compiling PHP against locally compiled MySQL client libraries.
# Since Dreamhost already has the MySQL libraries in /usr, we should use those.
# Also - using the locally compiled MySQL libraries causes a segmentation fault (crash)
# when the compiled PHP binaries try to access a MySQL server
# I was having trouble at the ./configure stage if I used the system MySQL libraries: --with-mysql=/usr
# I don't have a solution to this. Perhaps the only solution is to compile PHP 5 without mysql support - which is not a very good option at all.
cd ../../php-5.0.3
# If you get question marks in the pasted text, try removing the backslashes and putting all directives on a single line ...
#Important note:
# I would highly recommend adding the following line to the ./configure directive below:
# --with-config-file-path=/home/your_dh_username/etc/php5/
# Then, after you compile PHP, copy the php.ini-dist file from the php-5.0.3 dir.
# to /home/your_dh_username/etc/php5/
# You probably need to create these directories before copying the file over
# Commands would be something like:
# cd /home/your_dh_username/
# mkdir etc
# cd etc
# mkdir php5
# cp /home/your_dh_username/php-5.0.3/php.ini-dist /home/your_dh_username/etc/php5/php.ini
# Make sure you edit the following items in php.ini:
# register_globals (many scripts need it to be on), and the session_save_path to /tmp, or somewhere else in your home directory.
# Note: no mysql support included below due to crashes in PHP 5 if it is compiled against a local MySQL library
# I tried compiling it against a MySQL shared object, that sort of worked, but not all the way ...
./configure
--prefix=/home/your_dh_username/php \
--enable-force-cgi-redirect \
--with-xml \
--with-libxml-dir=/home/your_dh_username/php/lib \
--enable-soap \
--with-xsl=/home/your_dh_username/php/lib \
--with-openssl=/home/your_dh_username/php/lib \
--with-curl=/home/your_dh_username/php/lib \
--with-mhash=/home/your_dh_username/php/lib \
--with-mcrypt=/home/your_dh_username/php/lib \
--with-zlib-dir=/home/your_dh_username/php/lib \
--with-jpeg-dir=/usr/ \
--with-png-dir=/usr/ \
--with-gd \
--enable-gd-native-ttf \
--enable-ftp \
--enable-sockets \
--enable-wddx \
--with-iconv \
--enable-soap \
>
/home/your_dh_username/install_logs/php5_configure1.txt
make >
/home/your_dh_username/install_logs/php5_configure1_make.txt
# Warnings (safe to ignore, I think):
#
/home/your_dh_username/src/php-5.0.3/main/php_sprintf.c: In function `php_sprintf':
#
/home/your_dh_username/src/php-5.0.3/main/php_sprintf.c:40: warning: assignment makes pointer from
integer without a cast
make install
# ------------------------- Post Install
Setup -------------------------
cd /home/your_dh_username
cd your_dh_domain.com
mkdir cgi-bin
# You MUST chmod 755 the cgi-bin
directory your php interpreter goes in
chmod 755 cgi-bin
# Copy that binary into some
location accessible from your domain (cgi-bin/ is a good idea). So:
cp
/home/your_dh_username/php/bin/php
/home/your_dh_username/your_dh_domain.com/cgi-bin/php
#For the sake of maximum ease,
rename the PHP binary to end in .cgi:
mv
/home/your_dh_username/your_dh_domain.com/cgi-bin/php
/home/your_dh_username/your_dh_domain.com/cgi-bin/php.cgi
cd
/home/your_dh_username/your_dh_domain.com/
# Now create an .htaccess file to
redirect all PHP requests to this PHP binary
# instead of going through the default
system PHP binary. Put this inside:
cd
/home/your_dh_username/your_dh_domain.com/
mkdir php5docs
# Use pico to create the following
.htaccess file in the
/home/your_dh_username/your_dh_domain.com/php5docs/ dir
# Doing this will make all files ending
in .php and .pcgi in http://your_dh_domain.com/php5docs/ be
run by PHP 5!
cd php5docs
pico .htaccess
# Paste following contents (remove #
signs before pasting!)
# AddHandler custom-php .php .pcgi
# Action custom-php /cgi-bin/php.cgi
# Ctrl+O to write out / save file
# Note: You can use whatever
extension(s) in the AddHandler line. Separate multiple entries with
spaces.
# Make sure that the Action line points
to a useful URL.
# In the example above, it points to
http://domain.com/cgi-bin/php.cgi.
# If your PHP binary is in a different
location, use a different URL.
# And keep in mind that it's a URL (sans
domain name), NOT a path for the filesystem. Don't forget that first
slash!
# Create phpinfo.php test file
pico
/home/your_dh_username/your_dh_domain.com/php5docs/phpinfo.php
# Enter the following contents:
<?php phpinfo(); ?>
# Save the file using Ctrl + 0
# Go to
#
http://your_dh_domain.com/php5docs/phpinfo.php
# You should see something like the
following page:
#
http://moztips.com/php5_install/phpinfo_sample.html
# If the a page like that appears,
that's it! Congratulations!
# ------- END------