Tuesday 5 May 2009

Create your perfect virtualised PHP development environment

The development environment is one of the most important factors to be taken into consideration for successful projects. The environment has three basic elements: the operating system, the text editor and the test environment. The operating system is not really important as long as you're used to it, and this also applies to the text editor. The test environment is something else, because you want to avoid “surprises” when your code goes on the production or company test environment. Your test environment should be very similar, if not identical to the production environment. Unfortunately a lot of organisations have rules over rules that stop you from having your perfect environment. Those of you who are allowed to develop on Linux, consider yourself lucky, because most of the companies will provide a Windows/MacOS environment.

How are you supposed to have a PHP test environment under Windows/MaxOS that is similar to your production Linux? The answer is quite simple: virtualisation. You can have a Linux virtual machine that runs your test environment, and the best part is that you have total control of the test environment, with root access. If that sounds good, read on, and follow these easy steps:
  • Start by downloading VMware Server for your operating system from http://www.vmware.com/products/server/ . You have to register, but the product is free.
  • Install VMWare Server on your machine
  • Go to the VMware Infrastructure Web Access, located at http://127.0.0.1:8222/ui/ , and login with your operating system credentials. If you have problems with that, check out this post
  • Next, you have to create the virtual machine. In the Vmware Infrastructure Web Access main page, go to Virtual Machine->Create Virtual Machine.
  • In the “Name and location” screen, just give a name to your virtual machine, and select the standard datastore. Click next after each step to move forward.
  • In the “Guest and Operating System” screen, you have to choose the right operating system you intend to install. For Linux, select “Linux operating system”, and the version you want.
  • In the “Memory as Processors” screen, it depends on your machine how much you want to use for your virtual machine. I would recommend at least 512MB for a simple Linux installation. If you're not sure, start with 512MB, and you can increase the memory later if you need to. The default setting for Processors should be ok, usually 1 processor is fine for testing.
  • In the “Hard Disk” screen, select “Create a new virtual disk” and input a proper size for your Linux installation. Disk space is really cheap these days, so put enough space.
  • In the “Network adapter” screen, you definitely want to add networking capabilities to your virtual machine. Select “Add a network adapter”, and choose from the three possible connections. I would recommend bridged, so that your virtual machine will be visible not only from your computer, but from your network.
  • In the “CD/DVD drive” screen, select “Use a physical drive” if you have your Linux distribution written on a CD/DVD of “Use an ISO image” if you have just the .iso file.
  • Don't add no floppy drive on the “Floppy drive” screen, unless you have a good reason to add one.
  • If you need USB, add an USB controller from the “USB controller” screen.
  • After completing all these steps, the virtual machine is ready to be created, click “Finish” to do that. Wait for the machine to be created, you can see the progress at the bottom of the screen. You have your virtual machine now, next you have to install the operating system.
  • Select your newly created virtual machine from the left side of the screen and go to the “Console” tab. In order for you to be able to access the virtual machine, you will need to install a browser plugin that allows you to see the virtual operating system inside your browser. Click on the install plugin link, you will get the plugin installed, and the browser will restart. Log in again to the VMware Infrastructure Web Access (http://127.0.0.1:8222/ui/ ) and go to the Console tab of your virtual machine.
  • Now you can start the machine by clicking in the middle of the console. You will have to click again the “Open console in new window” link to open the console.
  • Finally you can see the console. Depending on what you have selected on the “CD/DVD drive” screen, your Linux installation will start automatically if you have selected an existing iso image, or you will have to provide the CD/DVD for the installation to start. From this point it is up to you what you install and how you install it. Try to avoid installing graphical Linux, because it's pointless and it will consume a lot of memory.
After installing Linux, if you want to quickly install PHP and Apache, you might have a look at Zend Server Community Edition. I have detailed in my last post the installation, you might want to have a look(http://bogdan-albei.blogspot.com/2009/05/zend-server-community-edition.html).

Now you have your own Linux machine inside your Windows and you can tune it as closely as possible to your production server. It's not necessary to access your machine through the console. As long as it is started you can access it with your favourite SSH client.

Don't forget that you will have to start the virtual machine every time you start your operating system.

2 comments:

  1. Hi,
    Nice post. I'd like to read about virtualisation made with scalability in mind. Like, how to set up PHP/Apache(Nginx, Yaws)/MySql(Postgres, Oracle, anything) on a virtual machine, so that when starting a new VM on a separate hardware machine, it will smoothly integrate with the others already running.
    Altfel? Esti bine?:)

    ReplyDelete