Installation of PHPUnit on a Dreamhost Account

I know it’s been awhile since I posted here.  I needed to get some other web work complete, such as the Trenton 1784 website, which took me away from the Zend Framework for a bit.  Now I am back at it.

Since I have the Zend Framework in Action book, in order to fill out my knowledge of Zend, I wanted to get my server fully set up for the applications in this book and this required the downloading of PHPUnit in order to do the Unit Testing.  Now it doesn’t seem like this would be a requirement to actually go through the book,  but I had always done unit testing when I was a consultant developing desktop apps for Fortune 500 companies.  Since Zend Framework in Action also explains how to use PHPUnit, I might as well take advantage of it.

First a note about installing this. These are merely steps that I took to get PHPUnit to wok for me.  I can not be held responsible for anything that may happen during these steps.  I have tried to lay them out as clearly as I could and in an easy to follow process.  It did take me some trial and error, as well as researching several websites to put this all together.

Installing it is like piecing together a puzzle – trying to find the next bit of information that someone may have left out.  Just downloading it was a bit of challenge since I wasn’t going to be using the Pear Installer.  First I had to look for where to download the zip file from. On the main page they have a Install PHPUnit link.  Okay, so I thought that would bring me to the download page. Nope – it brings me to the instructions on how to install it in the PDF manual.  At first I thought this wasn’t what I wanted, which was my own damn fault for just glancing at it, so I went back to the main screen to see if they had a “Download Link”, which they didn’t.  After looking at various links, I went back to the install link and read that page.  Although it was not hotlinked – the link for downloading PHPUnit manually was in there –

So I downloaded the PHPUnit-3.4.3.tgz file and FTPed to the server (you can’t use Dreamhost’s WebFTP since it is over 2 meg -  I used Dreamweaver and of course you can use any FTP program you wish).  Now that it was on the server, I had to see how to set it up on a Dreamhost account that is on a  shared server. These are the steps I had to take.  I am putting these here because I noticed while doing searching that others were trying to figure out the same thing (some things I have already had set-up, such as putty, but I will go through them so anyone completely unfamiliar will be able to follow from start to finish.

Using Putty to get into Dreamhost account

1) First get Putty – no installation required, just download and run.

2) Enter in the hostname – this is just your website  without the “http://www” – i.e.,  “”

3) Click Open at the bottom.

4) When the black command line screen comes up it will first says “login as”. Just type in the dreamhost user name which you use to FTP into dreamhost.

5) It will then ask for the specific account’s password.  Type in the password that you use to FTP into that account with.

6) If everything goes okay – you should see the console welcome screen.

If you do a dir command, you will see that you are on the root level of your account’s directory. You can easily get back to this directory by just typing “cd $HOME

Installing PHPUnit

1) Make sure the PHPUnit-x.x.x.tgz file is in your root account directory.  If it isn’t – then go to the directory you saved it in and copy it in the home directory by typing cp PHPUnit-x.x.x.tgz $HOME

2) Unzip the tgz file by issuing this command – tar -zxvf PHPUnit-x.x.x.tgz I found this on the DreamhostWiki

3) Now create the local/bin directory if it is not already created by issuing this command mkdir -p $HOME/local/bin

4) Back to the PHPUnit installation instructions – you need to rename the phunit.php file  to just phpunit (note the lowercase) without the .php extension and copy it to your local/bin directory by issuing this command cp PHPUnit-x.x.x/phpunit.php $HOME/local/bin/phpunit. You can find this file located in the PHPUnit-x.x.x subdirectory which was created when the tar file was unzipped. NOTE: the Dreamhost PHPUnit Installation instructions says that the file is located in the PHPUnit-x.x.x/bin directory – which there no such directory, at least in version 3.4.3 which is the latest. Also, it says nothing about having to rename the file.

5) Now set up the paths.  I first tested these out one at a time without changing the .bash_profile to make sure it worked.

6) You have to set a path to the PHP5 Command Line interpreter.  The instructions for Dreamhost I found here – PHP-CLI (Using PHP from the Command line) You want to enter – export PATH=/usr/local/php5/bin/:$PATH
Type php – v to make sure it work. It should give you the PHP CLI version information.

7) Set the path for your local/bin directory  so it will find the phpunit file. Enter in – export PATH=$HOME/<accountname>/local/bin:$PATH
Type phpunit –help (Note: This will still give you an error because it is not able to find the other files in the PHPUnit-x.x.x/PHPUnit directory – we will add that path next.  It should find at least the PHPUnit file though, attempt to run it and not give an command not found message.)

8 ) Set up the path to find the rest of the files required by PHUnit.  I kept these in the original subdirectory which is located in PHPUnit-x.x.x/PHPUnit.  Just enter export PATH=$HOME/<accountname>/PHPUnit-x.x.x:$PATH

9) Now test it the whole thing out by entering phpunit –help If everything worked you should get the version information and help screen.  If you didn’t make sure that all your path’s are entered in correctly with the proper upper and lower cases.

Making the Changes Permanent in the .bash_profile

Once you have gotten that to work you want to make those paths permanent so you don’t have to retype them every time you log in. This requires putting them into your .bash_profile (note the period before the file name – just like .htaccess)

1) Enter cd $HOME to make sure you are in the root directory

2) Enter vi .bash_profile (This will bring you to the vi editor)

3) The vi editor opens in view mode and you need to change to edit mode – so hit the a key You should now be able to edit the file.

4) Cursor  down to the end of the last line and hit enter (you should now have a new line to enter in information). Enter this –


That line is made up of the three paths we entered before – just concatenated together and are now in the .bash_profile file.

5) Now to save the file.  Hit the esc key to get out of edit mode. Type : x  (no space between the colon and the x) to save and exit.

To test to make sure the .bash_profile works you need to  logout of the command line by typing logout and enter.  Log back in using Putty (which is described above) After logging in, if you type in phpunit –help now, it should give you version and help information as it did before but without you having to manually type in the paths.

If it doesn’t work, double check your paths and make sure everything is correct. It seemed as if the path to PHPUnit-x.x.x had to appear first for some reason.  When I didn’t have it first it generated a  PHP error.  It could be possible that Dreamhost has a copy of PHPUnit somewhere on their system that it could be picking up if it doesn’t search in YOUR PHPUnit directory first.

Posted in Computers/Programming, PHP, Web Development.
Notify of

Newest Most Voted
Inline Feedbacks
View all comments
Scott Maggelet
14 years ago

Thank you for the very helpful instructions.

In my case, copying the phpunit.php file to the local/bin directory did not work. PHPUnit failed to find the required included files. However, renaming the phpunit.php file and executing it within its current directory did work. I am on a Dreamhost Private Server, though I don’t know if that makes a difference.