Since the official release of PHP 5.3 many developers want to test the new features out, but still don’t want to mess with the old PHP installation. Same thing goes for me, I don’t want to mess up my existing PHP installation yet, but eager to test namespaces, late static binding and closures.
So let’s create a virtual development environment using the latest software bundles.
With the help of this tutorial you will install the following softwares:
- VirtualBox
- Apache 2.2.x
- MySQL 5.0
- Ubuntu 9.04 as the guest OS
- …and of course PHP 5.3
1. Install VirtualBox
I prefer VirtualBox from Sun mainly, because it’s free and it’s easy to work with. You can use another virtualization product such as VMWare or Parallels for Mac OS X.
If you want to go with VirtualBox then download it from the link above or from this link. I happen to have it already installed on my Mac, so I won’t go into details.
2. Download Ubuntu
This step is pretty straightforward. Download the ISO image from this direct link.
3. Setup Ubuntu in VirtualBox
Once downloaded you have to add the ISO file as a CD/DVD image in Virtualbox. Open the Virtual Media Manager (File->Virtual Media Manager) window, open the CD/DVD Images tab and click Add
Once this is ready, we have to create a new virtual machine to load it successfully. Go to the main VirtualBox window and select New. Name it to Ubuntu PHP 5.3 and select Linux for operating system and Ubuntu for the version.
Next, select at least 512 MB base memory size.
On the next window make sure you select the Create new hard disk option.
Once finished, mount the Ubuntu ISO by going to the settings page of the virtual machine, selecting Storage -> CD/DVD-ROM tab. On this window check Mount CD/DVD Drive and select the ISO image file.
Finally, start the virtual machine.
4. Install Ubuntu inside the virtual machine
I will show you a quick overview of the installation process.
Once finished installing the OS make sure you shut it down and unmount the ISO image.
5. Install Apache and MySQL
Thanks to Brandon Savage for writing a tutorial on installing and compiling Apache, MySQL and PHP 5.3 on Ubuntu. I will take the steps from that tutorial and illustrate it here.
Installing Apache and MySQL is pretty straightforward. Just open the Terminal and write the following lines.
The first line installs Apache 2.2.x and the second line installs MySQL 5.0. Alternatively you can skip writing sudo if your user has root privileges.
1 2 | sudo aptitude install apache2 apache2-mpm-prefork apache2-prefork-dev apache2-utils apache2.2-common sudo aptitude install mysql-client mysql-client-5.0 mysql-common mysql-server mysql-server-5.0 mysql-server-core-5.0 |
The tricky part is installing the necessary libraries in order for PHP 5.3 to function correctly. Fortunately Brandon Savage deals with this issue too. Just write the following line into the console:
sudo aptitude install libtidy-dev curl libcurl4-openssl-dev libcurl3 libcurl3-gnutls zlib1g zlib1g-dev libxslt1-dev libzip-dev libzip1 libxml2 libsnmp-base libsnmp15 libxml2-dev libsnmp-dev libjpeg62 libjpeg62-dev libpng12-0 libpng12-dev zlib1g zlib1g-dev libfreetype6 libfreetype6-dev libbz2-dev libxpm4-dev libmcrypt-dev libmcrypt4
6. Installing PHP 5.3
First, download the source from the website. Just write the following commands:
1 2 3 | cd ~ wget http://us3.php.net/get/php-5.3.0.tar.gz/from/this/mirror tar xvfz php-5.3.0.tar.gz |
Before executing the following configure command restart your virtual machine, because there is the possibility that Apache or MySQL is not properly loaded.
After restarting go into the folder where PHP was extracted. Mine is ~/php-5.3.0
1 | cd php-5.3.0 |
Then execute the configure command:
./configure –with-apxs2=/usr/bin/apxs2 –with-mysql=/usr –with-mysqli=/usr/bin/mysql_config –with-pgsql=/usr –with-tidy=/usr –with-curl=/usr/bin –with-curlwrappers –with-openssl-dir=/usr –with-zlib-dir=/usr –enable-mbstring –with-xpm-dir=/usr –with-pdo-pgsql=/usr –with-pdo-mysql=/usr –with-xsl=/usr –with-ldap –with-xmlrpc –with-iconv-dir=/usr –with-snmp=/usr –enable-exif –enable-calendar –with-bz2=/usr –with-mcrypt=/usr –with-gd –with-jpeg-dir=/usr –with-png-dir=/usr –with-zlib-dir=/usr –with-freetype-dir=/usr –enable-mbstring –enable-zip –with-pear
You should see something like this:
Create the make files by executing the make command:
1 | sudo make |
Then compile and install PHP:
1 | sudo make -i install |
As Brandon Savage states, the -i will ignore a nasty error that is caused by Ubuntu: "Ubuntu uses an unusual configuration for Apache which causes the installer not to know how to install PHP properly. This will produce a fatal error and cause the install to stop. The -i flag tells it to ignore the errors."
7. Configure PHP 5.3
After compiling PHP go to this directory…
1 | cd /etc/apache2/mods-available |
… and create two files. The first file is called php5.load
1 | sudo nano php5.load |
Write the following line into the file:
1 | LoadModule php5_module /usr/lib/apache2/modules/libphp5.so |
Save and create the second file called php5.conf
1 | sudo nano php5.conf |
Write the following lines into this file:
1 2 | AddType application/x-httpd-php .php .phtml .php3 AddType application/x-httpd-php-source .phps |
Almost finished. Load the configuration and restart Apache:
1 2 | a2enmod php5 /etc/init.d/apache2 restart |
That’s it! Now you can test if PHP is properly loaded by going to /var/www and creating an index.php file:
1 2 | cd /var/www sudo nano index.php |
Write the phpinfo() command into the file:
1 2 3 | <?php phpinfo(); ?> |
Enjoy your new development environment. Oh, if this tutorial was useful to you don’t hesitate to comment and share it with others.
More From Server-Side Magazine
- 4 Most Important PHP Security Measures
- Bootstrap PHP Code
- PHP Security Measures Against CSRF Attacks
Server-Side Magazine Recommends
- Wicket Tutorial, part 3 – first form in our application (TomekDziurko)
- Wicket tutorial, part 5 – generic unique entity validator (TomekDziurko)















I think for this kind of use a virtualised graphical distro is just an overkill. Ubuntu Server would be a good choice as you can select both mysql and apache during installation and only need to complie PHP yourself. Although you have to dig a bit into VirtualBox machine properties, namely, you need to enable PAE because Ubuntu Server's kernel needs this processor feature to run. Another option is Archlinux, to save a headache or two. Of course, that would be out of scope for a tutorial like this, being much more advanced.
@KRiS: Yes I know that the Ubuntu Server is enough, but for that extra headache I decided not to go with it.
I tried Archlinux and also Damn Small Linux, but both of them didn't provided the ease of use and also the installation is more complicated.
On the other hand Ubuntu is quite popular among web developers :)
Hi, thanks for tutorial but I think it is not very complete enough.
Would this virtual dev env would be available outside virtualbox (in mac os x) how about svn?
I haven't tried it myself yet, but there is a ("experimental") debian packages: http://www.mail-archive.com/debian-user@lists.debian.org/msg550223.html Not that compiling is such a big deal, but a lot of people prefer a package manager..
@irmantas: Yes, virtualbox can be run on all the major platforms incuding Windows, Linux and Mac OS X.
SVN installation and other dev. stuff is out of the scope for this tutorial. I simply wanted to illustrate how to create a virtual environment where you can test PHP 5.3 without messing with your existing installation.
Also, you can do whatever you want in this Ubuntu virtual environment including SVN installation.
@John Kleijn: That is why I opted for compiling PHP, because the deal with experimental stuff is that it's either working or not...
Where did you choose the 'root' user password ? I have an authentication failure when with 'su' Thx
The root password is actually your username's password which you had to specify when you installed Ubuntu.
If you didn't changed it, than it's the same...
I like the concept of using Virtual Box instead of rebooting my system. I run Gentoo primarily and have been using Ubuntu to try to get php 5.3 working so I can move ahead with my framework.
It might take some time for it to appear on Gentoo.
Yes, even Windows is not supported as it used to...
No need to compile php5.3, just add the dotdeb repositories for now: http://www.dotdeb.org/ I hope karmic will have 5.3 by default: https://answers.edge.launchpad.net/ubuntu/+source/php5/+question/70902
Finally, wrote a similar article on virtualizing development over here: http://kevin.vanzonneveld.net/techblog/article/howvirtualizationwillimproveyour_code/
I always felt more comfortable compiling my own software, because I have more control over how they work...
i'am getting warning: –with-mysql=/usr: invalid host type ... any ideas?
Make sure you properly installed MySQL and upon installation you didn't got any errors.
it's still not working :( http://paste-it.net/public/icdbab0/ mysql is installed and I can use the server via the shell. any ideas?
What version of Ubuntu do you use? What version of MySQL did you installed? Was the install successful?
Ubuntu 9.04 mysql Ver 14.12 Distrib 5.0.75, for debian-linux-gnu (i486) using readline 5.2 The installation was successful.
If you have an error like "–with-mysql=/usr: invalid host type" try to replace "–" in ./configure string with "- -" (w/o space). Sorry for my english.
@vatja : if you simply copy-paste the examples you will get that error. So did I.
After a few hours of c***k-sucking found that the utf-8 charset screwed my head over the fence :)
Make (touch) a 'tmpfile' then paste the copied text and replace any "–" with "--", and also not forget to remove the line breaks. Than cat 'tmpfile' and that is what you need.
"--" means - - without spaces (damn wordpress)
One IMPORTANT thing. If you want to develop by using the Zend Framework, you MUST exclude the '- -with-curlwrappers' from the configuration, or you will have file inclusion and "bad/illegal format or URL" errors in the Zend_Loader class. Read PHP Bug page for more info.
@Gixx Thanks for your useful comments!
Replacing Ubuntu Desktop with Ubuntu Server can greatly reduce memory usage. In my case I've chosen VMWare Server for my virtual development environment. I like it more because it allow to run virtual machine as a Windows service, and never see it on task bar. Probably VirtualBox also have this feature, but I didn't found it.
You can check my blog for more details about virtual development environment based on VMWare server. Part 1: http://vrubleuski.blogspot.com/2010/04/development-environment-for-open-source.html Part 2: http://vrubleuski.blogspot.com/2010/05/development-environment-for-open-source.html
@Vasili I usually don't approve this kind of comments, but I've read your posts and I think it could benefit SSM's readers.
So good luck with your blog and if you'd like to write a guest post on SSM you're welcome to do it :)