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:
1. Install VirtualBox
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
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.
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
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:
Then compile and install PHP:
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…
… and create two files. The first file is called php5.load
sudo nano php5.load
Write the following line into the file:
LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
Save and create the second file called php5.conf
sudo nano php5.conf
Write the following lines into this file:
AddType application/x-httpd-php .php .phtml .php3 AddType application/x-httpd-php-source .phps
Almost finished. Load the configuration and restart Apache:
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:
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.