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.
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.
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 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
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
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 192.168.1.111.
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 192.168.1.111 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.
Let's create a new Apache configuration file:
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:
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 https://192.168.1.111/mywebapp/test.html, again replacing 192.168.1.111 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.