In case you haven’t heard the news, the PHP project released version 5.4.0 last Thursday. Naturally, I decided it was time to install and give it a try. I chose to install to a clean and bare-bones CentOS 6.2 virtual machine using VirtualBox. I did this for two reasons: 1) I wanted a clean environment for the build, and 2) I wanted to play with CentOS. At the time of this writing, there are not yet any official CentOS RPMs for PHP 5.4, so I had to build PHP from source. What follows are the notes I took during the installation and build process. I hope you find them helpful.
Set up a CentOS virtual machine
First of all, go grab the CentOS 6.2 netinstall ISO. Depending on the mirror, it will likely be located somewhere like
centos/6.2/isos/x86_64/CentOS-6.2-x86_64-netinstall.iso (note that I’m using the 64-bit version). Following that, create a new basic VirtualBox VM (512 MB RAM, 8 GB HDD, 12 MB video RAM) for your CentOS installation (use “Red Hat (64 bit)” as the Version) and follow these instructions for a CentOS 6.2 netinstall. I chose the 64-bit version, using the netinstall URL of
Since the VirtualBox video RAM selected is only 12 MB, it won’t boot into the graphical mode shown in the netinstall installation guide. Don’t worry about this. Also, it will make some assumptions (e.g. it won’t install Gnome or KDE), since you aren’t in graphical mode. What you’ll have at the end is a very bare-bones server installation.
After installation, I like to power down the VM and adjust my settings to set up port forwarding so that I can shell into my VM from my Mac terminal. Feel free to configure things as you like. See the screenshot for an example of forwarding ports in Virtual Box. Once set up, you can boot the VM and then use your favorite local terminal to SSH to the instance:
You’ll probably want to create a user for yourself, so that you’re not using root all the time, but since this is a VM on your local machine, it’s not a huge deal. If this was a box out in the open, I’d recommend locking it down and creating a user with much more restricted permissions.
Install packages needed for PHP
Once logged in to the VM, you’ll need to install some basic build stuff, like gcc, etc.
Next, update iptables to allow connections to the VM over ports 80 and 8000.
For the PHP configuration that I’m using, install the following packages. There will be a bunch of dependencies it will ask you to install. Just say yes to them all.
For some reason, libmcrypt isn’t available in the main CentOS repositories, so add the RPMForge repo to install it.
Now, the environment is all ready for building PHP 5.4!
Build PHP 5.4.0
All that’s left is to get the PHP 5.4.0 release package and build it. Choose a mirror closest to you and run the following commands to configure, make, and install PHP.
What you want to enable and build into your PHP installation will vary, but here’s the configure line that I used for this build:
Assuming the configure script ran perfectly, you’re ready to make and install PHP.
Now, you’ve got a fully-functioning build of PHP 5.4.0 on CentOS 6.2!
Trying out the build
Now, that PHP is installed, it’s time to try out a few things. Create a simple
phpinfo() script, make sure Apache knows to parse
.php files as PHP, and start Apache.
Now, assuming your VM port forwarding is set up correctly, from your local machine visit
http://localhost:8080/phpinfo.php. You should see the output of
One cool new PHP 5.4 feature is the built-in web server for development testing. You can try it out with this build. The following commands tell PHP to run the built-in web server using the current directory as the web root, while listening on port 8000 to all interfaces (not recommended on a public machine, but necessary for the request to the VM to work).
From your local machine, visit
http://localhost:8000/phpinfo.php. Note that the Server API line will say “Built-in HTTP server.” Of course, we’ve also set up Apache, so using the built-in HTTP server may not be of much value now, but in the future, if developing locally, the built-in web server can be a handy way to quickly try out things that typically need a web server.
There you have it, and it only takes about an hour to work through these installation and build steps, most of which is taken up by waiting on things to finish installing, configuring, or building. I hope these steps have been helpful. Feel free to let me know of your own experiences installing PHP 5.4 and leave any tips or tricks in the comments.
Thanks for reading!