Saturday, 28 August 2010 23:43

Set up your own virtual Linux LAMP server on Windows


Even the most Microsoft-ardent developer will know web hosts favour Linux, Apache, MySQL and PHP over Windows, IIS, ASP.NET and SQL Server. Thanks to virtualisation the days of dual booting are over. Here is how to set up a streamlined LAMP development environment on any Windows PC.

Of course, as a virtual machine is for all intents and purposes a real computer, these instructions apply just as well if you are setting up a real Linux dedicated machine for LAMP development.

There are many reasons to have a LAMP development environment, no matter your preferred choice of computer platform. The truth is even if you are a hard-core Microsoft Windows user you will find web hosts offer cheaper plans for Linux environments than they do for Windows, if they offer Windows at all. Additionally, you can find various free web hosting options that are based on Linux.

Several reasons for this state of affairs are that Linux is inherently secure and lean with a long heritage of robust multiuser time-sharing hosting.

Of course, another very significant reason is that because Linux, Apache, MySQL and PHP are all open source they have no licensing charges whatsoever. This makes them significantly cheaper than Microsoft Windows and particularly when combined with Microsoft SQL Server.

You might be wanting to get into LAMP development - perhaps a totally new software system you are writing from the ground up, or maybe even to create a backup WordPress or Drupal environment so you can experiment before touching your live site hosted elsewhere.

Whatever the reason, the first step for Windows users is to ensure you have a virtual machine environment. You might choose Microsoft's own Virtual PC, or VMWare or VirtualBox or any other virtualisation technology you might prefer.

Next, pick a Linux distribution. While Ubuntu is generally a runaway favourite I've opted for Debian Linux myself for my development platform.

My reasoning is that Debian is powerful and flexible, and importantly, it allows a lightweight system to set up very quickly. My goal in making a virtual machine is to give me the means to write dynamic PHP web apps against a MySQL database without bloat. I don't need or want an X-Windows GUI or Open Office or any other, more user-oriented, programs.

Debian offers a tiny minimal bootable CD-ROM image which is perfect for making a small virtual machine. Download the appropriate ISO image, whether i386 or amd64 depending on whether you want a 32-bit or 64-bit environment.

Next, create a new virtual machine using whichever virtual machine management tool you've chosen. No matter the software the process will be largely identical: name your VM, specify an amount of RAM and create a virtual hard disk drive with a sensible amount of space - which includes not too much as well as not too little. I chose 1Gb of RAM and 20Gb of hard disk space.

Finally, be sure to set your virtual machine's network adapter to a real network interface on your computer and set the virtual machine's CD drive to use the Debian network install ISO image.

Fire the virtual machine off and it will boot from the Debian CD, leading you through its installation process. Be careful to choose the right keyboard layout - Australian users should pick US English and not British English, for instance. If you make the wrong selection (pressing the pipe (|) key displays a tilde (~), for example) you can easily recover by running the command dpkg-reconfigure console-data later on.

You will be prompted to configure the network interface giving it either a static IP address or allowing DHCP to assign one. You will also be prompted for the type of setup to use. You can uncheck everything here, except for web server. Even if you're running your virtual machine on a laptop don't choose the laptop package.

Don't choose the database server option either, unless you wish to use PostgreSQL instead of MySQL (although now Oracle owns MySQL the traditional LAMP metaphor may swing to being LAPP in time).

Finally, you will be presented with a login prompt. Enter the username and password you specified during installation.

We want to make some changes to our base setup. Enter the command su and press enter. Enter the root password which you also gave during installation. If you've not used Linux before, this command elevates your privileges so you are now able to execute commands as the super user. The prompt changes to a hash (#) to indicate this.

First, let's ensure our virtual machine is up to date and has all the software we wish. Enter these commands in turn. You will be prompted to specify a super-user password for MySQL when it is installed:

aptitude update
aptitude upgrade
aptitude install mysql-server mysql-client
aptitude apache2 apache2-doc
aptitude install php5 php5-mysql libapache2-mod-php5

If you are familiar with other languages you might like to also install Perl and/or Python too:

aptitude install perl libapache2-mod-perl2
aptitude install python libapache2-mod-python

Let's also install some useful utilities. PHPMyAdmin provides web-based access to the MySQL database server and its contents:

aptitude install phpmyadmin

Lynx is a text-based web browser which will let you test simple web pages from the command prompt:

aptitude install lynx

For those who are not familiar with either vi or emacs, nano is an easy-to-use editor for creating and modifying text files:

aptitude install nano

Finally, to allow you to login to your virtual machine from other computers on your network install the OpenSSH server:

aptitude install openssh-server

After installing these packages restart Apache:

/etc/init.d/apache2 restart

Let's now make some test pages. The web server root is in the folder /var/www so let's create a file there called test.php. To do this using the nano editor type

nano /var/www/test.php

Enter this line into the file:

Before we can test we need to know the IP address of the virtual machine. If you assigned a static address then you know it already. If you allowed DHCP to assign an address type the command


and look for the IP address following the text 'inet addr'. In my case, that's

Take the mouse pointer out of your virtual machine. Leave it running, of course, but open your web browser - whether Internet Explorer, Firefox, Safari, Chrome or something else - and try each of these URLs. Be sure to substitute with the actual IP address of your system.

Each of these URLs should have shown a different result. The first will display a sample Apache 'it works' web page, which is being fed from /var/www/index.html.

The second will load the PHP page you made above, and display the results of the phpinfo() call.

The third will load PHPMyAdmin. You can log in using username root and the super-user password you nominated when installing MySQL. Using this utility you can very easily maintain MySQL databases.

Stop for a moment and take in what you've achieved. You have a fully working Linux server sitting on top of your Windows box, and you can access it through your web browser just like it was a real machine sitting out somewhere on the Internet.

That is pretty much the end of this tutorial, except for one thing. You don't want to get in the habit of becoming super-user so you can create web pages in the /var/www folder. Instead, you can make a folder in your own regular user home folder and have Apache serve files out of there.

Let's create a new Apache configuration file:

nano /etc/apache2/conf.d/mywebapp.conf

Enter this line and save the file, being sure to replace 'david' below with your own username:

Alias /mywebapp /home/david/mywebapp

Restart Apache again with the same command as previously:


There is no need to be the super user any longer; press CTRL + D at the same time to revert back to your ordinary user privileges.

Return to your home folder and make a directory and web page like so:

mkdir mywebapp
cd mywebapp
nano test.html

Enter any text you like into the file test.html and save it.

Go back to your Windows web browser and browse to the URL, again replacing with the right IP address for your virtual server.

You should find your text appearing. This means you can now freely edit web pages in your virtual machine under the mywebapp folder in your home directory, and view results immediately within your web browser.

Read 34966 times

Please join our community here and become a VIP.

Subscribe to ITWIRE UPDATE Newsletter here
JOIN our iTWireTV our YouTube Community here


Thoughtworks presents XConf Australia, back in-person in three cities, bringing together people who care deeply about software and its impact on the world.

In its fifth year, XConf is our annual technology event created by technologists for technologists.

Participate in a robust agenda of talks as local thought leaders and Thoughtworks technologists share first-hand experiences and exchange new ways to empower teams, deliver quality software and drive innovation for responsible tech.

Explore how at Thoughtworks, we are making tech better, together.

Tickets are now available and all proceeds will be donated to Indigitek, a not-for-profit organisation that aims to create technology employment pathways for First Nations Peoples.

Click the button below to register and get your ticket for the Melbourne, Sydney or Brisbane event



It's all about Webinars.

Marketing budgets are now focused on Webinars combined with Lead Generation.

If you wish to promote a Webinar we recommend at least a 3 to 4 week campaign prior to your event.

The iTWire campaign will include extensive adverts on our News Site and prominent Newsletter promotion and Promotional News & Editorial. Plus a video interview of the key speaker on iTWire TV which will be used in Promotional Posts on the iTWire Home Page.

Now we are coming out of Lockdown iTWire will be focussed to assisting with your webinars and campaigns and assistance via part payments and extended terms, a Webinar Business Booster Pack and other supportive programs. We can also create your adverts and written content plus coordinate your video interview.

We look forward to discussing your campaign goals with you. Please click the button below.


David M Williams

David has been computing since 1984 where he instantly gravitated to the family Commodore 64. He completed a Bachelor of Computer Science degree from 1990 to 1992, commencing full-time employment as a systems analyst at the end of that year. David subsequently worked as a UNIX Systems Manager, Asia-Pacific technical specialist for an international software company, Business Analyst, IT Manager, and other roles. David has been the Chief Information Officer for national public companies since 2007, delivering IT knowledge and business acumen, seeking to transform the industries within which he works. David is also involved in the user group community, the Australian Computer Society technical advisory boards, and education.

Share News tips for the iTWire Journalists? Your tip will be anonymous