Server-Side Magazine

Creating a PHP 5.3 Virtual Development Environment

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

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

Setup Ubuntu in VirtualBox

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.

Create Ubuntu Virtual Machine 1

Next, select at least 512 MB base memory size.

Create Ubuntu Virtual Machine 2

On the next window make sure you select the Create new hard disk option.

Create Ubuntu Virtual Machine 3

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.

Mount Ubuntu 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.

VirtualBox Ubuntu Installation 1

VirtualBox Ubuntu Installation 2

VirtualBox Ubuntu Installation 3

VirtualBox Ubuntu Installation 4

Once finished installing the OS make sure you shut it down and unmount the ISO image.

Unmount Ubuntu ISO File

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.

Open Terminal in Ubuntu

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

Install Apache in Ubuntu

Install MySQL in Ubuntu

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

Download PHP 5.3 in Ubuntu

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:

Execute Configure Command

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.

Related Posts

Tags: , , , , ,

About the Author

Server-Side Magazine

Server-Side Magazine is a place where users can contribute articles. Strictly server-side posts are presented in the following programming languages: PHP, Ruby, ASP.Net, Java, Python

Our philosophy is that knowledge should be free and available to anyone. We designed this site to be an open platform, meaning that anyone can contribute and share their knowledge on the above areas.

Although, it's an open platform we don't accept all articles, because it would result in a "just another", mediocre website. A minimum standard of quality is required from every submitted article.

Comments

Leave a Comment

Your email address will not be published. Required fields are marked *

Markdown enabled. Click here to see the syntax.

 
More in PHP (2 of 9 articles)