Installing ZendFramework on DreamHost - Quick-n-Dirty Guide

Install ZendFramework on DreamHost

Even though installing ZF on dreamhost is not so hard, I wanted to document the way I did it. This is quick way of getting development site up and running on ZendFramework, but for production use, please take extra caution when deploying application using this guideline.


Pre-Requisite

I am assuming you have following things to get going:

  • Dreamhost shared hosting account
  • Shell access for the user
  • You are signed into shell and your current path is your HOME (eg. /home/yourusername)
  • You will replace [YourUserName] with actual DreamHost shell-username


Getting ZendFramework in place

As of now, the latest release is 1.11.4 - to get most recent release check http://framework.zend.com/download/latest
# Download the latest release
wget http://framework.zend.com/releases/ZendFramework-1.11.4/ZendFramework-1.11.4-minimal.zip
 
# Un-zip ZF archive
unzip ZendFramework-1.11.4.zip
 
# Rename ZF directory to more generic so that we can upgrade later
mv ZendFramework-1.11.4 ZendFramework
 
# Make sure ZF is readable and executable
chmod 755 -R ZendFramework

Update PHP Settings on Dreamhost

Now, you have to update PHP related settings on Dreamhost.
# Copy global php.ini to ZF
cp /etc/php5/cgi/php.ini ~/ZendFramework/
 
# Update include path inside our custom php.ini
# You you favorite text editor to open php.ini or use nano
nano ~/ZendFramework/php.ini
# Now, go to section called "include_path" and at the end of the existing value add your ZF library path
include_path  = ".:/usr/local/lib/php:/usr/local/php5/lib/pear:/home/[YourUserName]/ZendFramework/library"


Update ZendFramework configs

Now you have to update PHP's binary executable location in ZF tools We will be using PHP v5 loaded in /usr/local/php5/bin/php
# To validate php path, use:
/usr/local/php5/bin/php -v
 
# As of now, executing above command gives:
PHP 5.2.15 (cli) (built: Dec 15 2010 14:09:31)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
    with Zend Extension Manager v1.2.2, Copyright (c) 2003-2007, by Zend Technologies
    with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies

Now, we need to update this in zf.sh
# Open ZF Tool script (use nano or other text-editor)
nano ~/ZendFramework/bin/zf.sh

Since we are giving PHP_BIN location directly - remove code block where CLI tool searches for PHP_BIN and add PHP_BIN location. We also need to tell the executable to use our custom php.ini instead of global config.
The ending config file should contain following contents (omitted ZF License comment block) :
# Use Dreamhost PHP 5 Library - no need to find it
PHP_BIN=/usr/local/php5/bin/php
 
# find zf.php: pear first, same directory 2nd,
if test "@php_dir@" != '@'php_dir'@'; then
    PHP_DIR="@php_dir@"
else
    SELF_LINK="$0"
    SELF_LINK_TMP="$(readlink "$SELF_LINK")"
    while test -n "$SELF_LINK_TMP"; do
        SELF_LINK="$SELF_LINK_TMP"
        SELF_LINK_TMP="$(readlink "$SELF_LINK")"
    done
    PHP_DIR="$(dirname "$SELF_LINK")"
fi
 
"$PHP_BIN" -c /home/[YourUserName]/ZendFramework/php.ini -d safe_mode=Off -f "$PHP_DIR/zf.php" -- "$@"
Finally, you also need to add an alias to ZF Tool so that you don't have to type the full path of ZF Tool shell script
# Open your .bash_profile
nano ~/.bash_profile
 
# Add following line at the end of file to create an alias
alias zf=/home/[YourUserName]/ZendFramework/bin/zf.sh
 
# Save above changes and reload your profile environment
source ~/.bash_profile
 
# Now you should have ZF Tool working, run following command to verify
zf show version
# Outputs:
Zend Framework Version: 1.11.4

Final Step

This is where things get dirty. After you create/upload a new project, you have to have ZF library in include path. There is two ways you can do it (feel free to use your own method here.)
  1. You can open [YourZFProjectPath]/application/configs/application.ini and add ZF absolute path /home/[YourUserName]/ZendFramework/library/
  2. or, create a symbolic-link to ZF library inside projects library directory, which I am going to use here.
    1. # Use this to create sym-link to global ZF library (don't forget to update your project-path)
      ln -s /home/[YourUserName]/ZendFramework/library/Zend /home/[YourUserName]/[YourZFProjectPath]/library/Zend
      If you do not add ZF library to the path, you might end up getting following error: ZF error without library
      If everything goes right, you will be greeted with welcome page without any error. Enjoy!
      ZF Default Welcome Page
© Hossain Khan - Some rights reserved.
Creative Commons License This site is licensed under a Creative Commons Attribution-Noncommercial 2.5 License.