A Full Stack Engineer's Perspectives on Technology, Startups, Software Engineering, and UI Design

Custom PHP Install on Dreamhost Shared Hosting

Posted: April 23rd, 2010 | Author: | Filed under: General | Tags: , , , | 11 Comments »

I like to share what takes some agitation to figure out and doing a custom PHP install on Dreamhost was my most recent tiring endeavor. It’s hardly difficult, but only if you know what you are doing. There’s a plethora of resources out there and unfortunately they all seem outdated (and some are, because I tried them). The ones that are not promise ease and quickness but fail to deliver when it comes down to actually getting it to work or providing the pivotal last hoorah that will accomplish that task.

The PHP Custom Install Script that Works

Source: http://www.bernawebdesign.ch/byteblog/2010/02/17/custom-php-5-3-1-with-apc-and-xdebug-on-dreamhost-shared-hosting/

Note: This script works and the others didn’t for me. I post it up here again for my peers who use Dreamhost in case they need it too. If you require help, you are welcome to post here or post on the original author’s blog.

Note #2: In order for this script and the .htaccess file to work accordingly, you must use a UNIX friendly text editor and save it in UNIX text mode. I use a tool called metapad and you can get it free here: http://liquidninja.com/metapad/. Otherwise, you might get 500 Internal Server Errors and those can sometimes be solved simply with this advice.


# update 16.2.2010
# @author Marco Bernasocchi
# – Added OPENSSL LIBMCRYPT LIBTOOL and a promt for installing XDEBUG
# (still uses XDEBUG 2.05, which has basic PHP 5.3.1 support. 2.1.0 is on its way)
# – removed unsupported php configure switches
# – disabled –with-xsl, if you want to use it you’ll probably need to install
# libxslt (http://xmlsoft.org/XSLT/) version 1.1.0 or greater.
# – sets the ini files into the install directory instead than on cgi-bin
# – to add more domains just copy the cgi binary to the new domain
# cp “$PHP_BIN_DIR/php-cgi” “$NEW_CGI_BIN_DIR/php.cgi” and modifiy the .htaccess

#Script for a minimal PHP 5.3.x install with APC
#- Prompts for the domain to build for
#- PHP configure line contains only valid PHP5 options
#- Displays colourful status messages
#- Many build messages, which aren’t helpful to most people, are now suppressed
#- Procedurised, making it cleaner and easier to follow
#The only things you may want to change in here are marked with “@todo”s
#Derived form the original PHP 5.3 install script at
#@author Dan Bettles

#Exit on error
set -e


echo -n “Enter the domain for which you want to build PHP and press [ENTER]: ”

echo -n “Enable XDEBUG (y|n): ”


#@todo Update versions, if necessary

#@todo Update install paths, if necessary


#@todo Alter features, if necessary
–with-config-file-path=$PHP_CONFIG_DIR \
–with-config-file-scan-dir=$PHP_CONFIG_DIR \
–bindir=$PHP_BIN_DIR \
–enable-zip \
–with-xmlrpc \
–with-freetype-dir=/usr \
–with-zlib-dir=/usr \
–with-jpeg-dir=/usr \
–with-png-dir=/usr \
–with-curl=$PHP_BASE_DIR \
–with-gd \
–enable-gd-native-ttf \
–enable-ftp \
–enable-exif \
–enable-sockets \
–enable-wddx \
–enable-sqlite-utf8 \
–enable-calendar \
–enable-mbstring \
–enable-mbregex \
–enable-bcmath \
–with-mysql=/usr \
–with-mysqli \
–without-pear \
–with-gettext \
–with-pdo-mysql \
–with-openssl=$PHP_BASE_DIR \
#–with-xsl=$=$PHP_BASE_DIR \


#@param string $1 Message
function echoL1 () {
echo -e “\n\033[1;37;44m$1\033[0;0;0m\n"

#@param string $1 Message
function echoL2 () {
echo -e "\n\033[0;37;44m$1\033[0;0;0m\n"

#@param string $1 URL
#@param string $2 Output directory
function downloadTo () {
wget -c $1 --directory-prefix=$2

#@param string $1 TAR filename
#@param string $2 Output directory
function untarTo () {
cd $2
tar -xzf $1
cd -

#@param string $1 Source directory
#@param string $2 Output directory
#@param string $3 configure arguments
function configureAndMake () {
cd $1
COMMAND="./configure --quiet --prefix=$2 $3"
if [ $1 = "$BUILD_DIR/$OPENSSL" ];then
#special command for OPEN SSL
COMMAND=”./config –prefix=$2 $3″
echo “$COMMAND”
make –quiet
cd -

#@param string $1 Source directory
#@param string $2 Output directory
#@param string $3 configure arguments
function makeAndInstall () {
configureAndMake $1 $2 “$3″
cd $1
make install –quiet
cd -

#@param string $1 Directory
function mkdirClean () {
rm -rf $1
mkdir -p $1

#@param string $1 Message
function echoWarning () {
echo -e “\n\033[1;37;41m$1\033[0;0;0m\n"



echoL1 "-> DOWNLOADING..."

mkdirClean $BUILD_DIR

echoL2 "--> Downloading $M4..."
downloadTo "http://ftp.gnu.org/gnu/m4/$M4.tar.gz" $DOWNLOADS_DIR
untarTo "$DOWNLOADS_DIR/$M4.tar.gz" $BUILD_DIR

echoL2 "--> Downloading $AUTOCONF..."
downloadTo "http://ftp.gnu.org/gnu/autoconf/$AUTOCONF.tar.gz" $DOWNLOADS_DIR

echoL2 "--> Downloading $OPENSSL..."
downloadTo "http://www.openssl.org/source/$OPENSSL.tar.gz" $DOWNLOADS_DIR

echoL2 "--> Downloading $CURL..."
downloadTo "http://curl.haxx.se/download/$CURL.tar.gz" $DOWNLOADS_DIR

echoL2 "--> Downloading $LIBMCRYPT..."
downloadTo "http://easynews.dl.sourceforge.net/sourceforge/mcrypt/$LIBMCRYPT.tar.gz" $DOWNLOADS_DIR

echoL2 "--> Downloading $LIBTOOL..."
downloadTo "http://ftp.gnu.org/gnu/libtool/$LIBTOOL.tar.gz" $DOWNLOADS_DIR

echoL2 "--> Downloading $PHP..."
downloadTo "http://www.php.net/get/$PHP.tar.gz/from/this/mirror" $DOWNLOADS_DIR

echoL2 "--> Downloading $APC..."
downloadTo "http://pecl.php.net/get/$APC.tgz" $DOWNLOADS_DIR

if [ $ENABLEXDEBUG = "y" ]; then
echoL2 “–> Downloading $XDEBUG…”
downloadTo “http://xdebug.org/files/$XDEBUG.tgz” $DOWNLOADS_DIR


echoL1 “-> BUILDING…”

mkdir -p $PHP_BASE_DIR

echoL2 “–> Building $M4…”
makeAndInstall “$BUILD_DIR/$M4″ $PHP_BASE_DIR

echoL2 “–> Building $AUTOCONF…”

echoL2 “–> Building $OPENSSL…”

echoL2 “–> Building $CURL…”
makeAndInstall “$BUILD_DIR/$CURL” $PHP_BASE_DIR “–enable-ipv6 –enable-cookies\
–enable-crypto-auth –with-ssl”

echoL2 “–> Building $LIBMCRYPT…”
makeAndInstall “$BUILD_DIR/$LIBMCRYPT” $PHP_BASE_DIR “–disable-posix-threads”

echoL2 “–> Building $LIBTOOL…”

echoL2 “–> Building $PHP…”
#Fixes compile error
export EXTRA_LIBS=”-lresolv”



mkdir -p -m 0755 $CGI_BIN_DIR
mkdir -p -m 0755 $PHP_CONFIG_DIR
cp “$PHP_BIN_DIR/php-cgi” “$CGI_BIN_DIR/php.cgi”
cp “$BUILD_DIR/$PHP/php.ini-production” $PHP_INI


echoL2 “–> Building $APC…”
configureAndMake $APC_SOURCE_DIR $PHP_BASE_DIR “–enable-apc –enable-apc-mmap\
cp modules/apc.so $PHP_EXTENSIONS_DIR
echo “extension=$PHP_EXTENSIONS_DIR/apc.so” > $PHP_CONFIG_DIR/apc.ini
cd -

if [ $ENABLEXDEBUG = "y" ]; then
echoL2 “–> Building $XDEBUG…”
configureAndMake $XDEBUG_SOURCE_DIR $PHP_BASE_DIR “–enable-xdebug\
cp modules/xdebug.so $PHP_EXTENSIONS_DIR
echo “zend_extension=$PHP_EXTENSIONS_DIR/xdebug.so” > $PHP_CONFIG_DIR/xdebug.ini
cd -

if [ -f $HTACCESS ]; then
echoWarning “–> Copied $HTACCESS to $HTACCESS_NEW”

#The backslash prevents a newline being inserted at the start
Options +ExecCGI
AddHandler php-cgi .php
Action php-cgi /cgi-bin/php.cgi

#Deny access to the PHP CGI executable and config files

Order Deny,Allow
Deny from All
Allow from env=REDIRECT_STATUS

#Preserve newlines in the content by quoting the variable name
echo “#######ADDED BY installPHP script” >> $HTACCESS

echoL2 “–> Created $PHP_INI”


rm -rf $BUILD_DIR

echo -n “Delete the downloads directory? (y/n): ”

if [ $DELETE_DOWNLOADS_DIR = "y" ]; then

echoL1 “DONE”

exit 0

After running this script, it creates a folder in your domain called ‘web’ and within that another folder called ‘cgi-bin’.  I wasn’t able to get anything working within this folder at first so I am guessing it is meant to be off limits? Anyways, I was able to get PHP 5.3 working ultimately with the following within your .htaccess file in the root of the your.com folder. This information came from the Dreamhost Custom PHP Install Wiki itself.

AddHandler phpFive .php
Action phpFive /web/cgi-bin/php.cgi

After getting your custom PHP build installed correctly, you should create a php file with phpinfo(); and check that the PHP version is 5.3 or whatever you might have altered the script to. At that point, you are free to edit your php.ini file located at /home/user/mycompiles/php-5.3 (or whatever it might be)/etc/php5/config/php.ini for further modifications.

Phew, well that took me a few hours to figure out and I hope it saves you some time :p. Trying scripts left and right can really eat up time. Some literally just “stopped” or as Dreamhost might say was “killed”. Others just produced errors during the php build of the operation with no indication of why it failed. Helpful? Not at the very least.

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

No related posts.

11 Comments on “Custom PHP Install on Dreamhost Shared Hosting”

  1. 1 Daniel said at 12:18 am on April 24th, 2010:

    Hi Men, nice post, im getting this error after running the script, i did what you suggest but still nothing. I have no idea what to do next, any advice ?

    Internal Server Error

    The server encountered an internal error or misconfiguration and was unable to complete your request.

    Please contact the server administrator, webmaster@quefresas.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

    More information about this error may be available in the server error log.

    Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

  2. 2 Daniel said at 12:39 am on April 24th, 2010:

    Hi again, i just solve the problem, just in case someone else have a similar problem, it seems that the install scripts edits automatically your .htaccess file, in my case i had custom rules on it, somehow the script got confused and edit the file incorrectly (not closing one tang /), so what i did was to check that everything on my .htaccess file were correct and add the cgi option mention in this post manually. Hope it helps someone.

  3. 3 Ayan said at 1:19 am on April 24th, 2010:

    Great! I was thinking that you were editing the file in a non-UNIX compliant text pad.

    The .htaccess file that this script edits is located in the yourdomain.com/web folder (unless you edited the defaults). For me, it posed no problem.

    Thanks for posting your solution!

  4. 4 Daniel said at 2:27 am on April 25th, 2010:

    Hey, which IDE do you use to debug your code, im trying to setup netbeans for php, but all the tutorials and guides i have found say you should use localhost, which is not my case beacuse i want to debug the dreamhost server.

  5. 5 Daniel said at 3:12 am on April 25th, 2010:

    All right, i figure it out again, im sorry im a newbie here. Maybe this is usefull for other people also starting with xdebug, when you modify your php.ini config file and add the following lines:

    xdebug.remote_host=localhost //This is not your php server it is your IDE enviroment.

    xdebug.remote_host , i got confused and thought that this was my php server (webserver) but it is not, at the contrary this is your IDE, so if your IDE is running locally and your PHP is running remotely , you should put here your computer IP address, you can get it from whatismyip.com or something similar and check that the port 9000 is really open http://www.canyouseeme.org/.

    Hope it helps someone else.

  6. 6 Roch said at 6:06 pm on June 8th, 2010:

    Do you know of anyway with htaccess to disable someone from using your domain to point to their own website on the same server? Ex: they use YOURDOMAIN.com to promote their PHISHING WEBSITE.COM by using this simple URL to send users : YOURDOMAIN.COM/~phishing/file.html

    Any help would be greatly appreciated. Thanks

  7. 7 Ayan said at 6:29 am on June 9th, 2010:

    I’ve never experienced this problem myself but how are they utilizing YOURDOMAIN.COM/~phishing/file.html ? Isn’t this a security problem with the host? Without knowing more about the mechanics of the problem, you could just block that URL and auto-redirect it with a .htaccess file in the root. You could also use mod-rewrite to auto redirect any query to a page that does not exist (it will redirect all requests to pages that are not physically there).

  8. 8 Ayan said at 6:31 am on June 9th, 2010:

    Thanks for posting up the solution. I use netbeans myself but haven’t set up xdebug yet. This will probably help me too; I just don’t know it yet :) .

  9. 9 PHP » DH PHP调试环境搭建 said at 10:50 pm on February 10th, 2013:

    [...] http://blog.ayanray.com/2010/04/custom-php-install-on-dreamhost-shared-hosting/ [...]

  10. 10 OvernightReputation.com said at 9:24 am on May 2nd, 2013:

    I was suggested this web site by my cousin.
    I’m not sure whether this post is written by him as no one else know such detailed about my trouble. You are incredible! Thanks!

  11. 11 Web Hosting Services Free Domain said at 10:25 pm on January 8th, 2014:

    WOW just what I was looking for. Came here by
    searching for web host review

Leave a Reply