I'm working on a VirtualBox image for a LAMP server. There are a few good reasons to use a virtualised LAMP server:
My own set-up is a host OS of Ubuntu 11.04, and a guest OS (the VirtualBox image) of Xubuntu 11.04. There are smaller distros, and it's probably a good idea for more advanced/confident Linux users to use the server edition, but only if you want to keep the requirements low and focus only on basic LAMP.
I also wanted the installation to be as generic as possible, so I also set my main user to be webdev. It doesn't really matter, but for me it helps distinguish the roles of the LAMP server and that of the host OS and development.
There are a few optional steps, and a few steps I've taken that have incomplete instruction. I'll make references to other useful links in these cases, and mention if something is required or not. I also should point out that these are really just notes for myself, and things I found useful for the installation along the way. It won't cover certain basics of LAMP and a basic level of understanding of both LAMP and Linux is required.
sudo apt-get update sudo apt-get upgrade
Then to install the LAMP server, use the following:
sudo apt-get install tasksel sudo tasksel install lamp-server
You will be asked for a new root MySQL password (and username, I think). You can test if it's worked by browsing to "localhost" in your browser, and you should be getting a page that says something along the lines of "It works!"
Then you will most likely want PHPMyAdmin:
sudo apt-get install phpmyadmin
Here you will be asked if you want to use apache2 (you do) and you will be asked for a username and password for phpmyadmin and the root password that you assigned to mysql during the LAMP installation above.
Once your basic LAMP server is installed you will most likely want mod_rewrite which allows you to test "clean URLS" in your web apps:
sudo a2enmod rewrite sudo /etc/init.d/apache2 restart
There is a list of commonly used modules that I also found that you can install:
sudo apt-get install php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-json sudo /etc/init.d/apache2 restart
Howerver, you can always add new modules as and when they may be required, at any point. Just make sure that you restart the apache server to enable the changes (i.e. the "/etc/init.d/apache2 restart" command)
Anyway, if you do want your virtual LAMP server to work as an extension of your local network then you simply need to set-up the network card in VirtualBox to "Bridged Network". To use a separate subdomain IP then set Adapter 1 to NAT (using default DHCP settings) and Adapter 2 to Host-only Adapter. In your Xubuntu LAMP server Adapter 2 will probably appear as Auto eth1 and you can change it to a static IP of something like 192.168.56.101 and use 192.168.56.1 as the Gateway and DNS server (you can additionally use Google DNS 220.127.116.11 and 18.104.22.168 or something like OpenDNS).
Once you have a static IP, then it's easy to add things like FTP, SSH and hosts aliases for your test websites.
sudo apt-get install ssh
You can connect to the LAMP server from your host computer with:
"webdev" is your username and "server.dev" is the name of your lamp server. To determine these (if you're unsure), in your LAMP server you can use "whoami" and "hostname" at the command prompt.
You might also want to set-up Nautilus (Ubuntu's file browser) to be able to access the virtual LAMP server's files using SSH. This allows you to browse the files almost like they're local files. There is an option "Connect to server..." where you can add those details: the static IP address, username, and folder "/var/www"
cd ~ mkdir Projects cd Projects mkdir -p testside.local/public_html
Then you will need to point apache to that site (also notice that I'm using "public_html" which allows you to have a different public root folder to the root of your site, and you can have an exact duplicate of your live site. Of course, it could be "htdocs" rather than "public_html" depending on your live environment (note, we're not setting up a live web server, only a testing LAMP server!).
Enter the code, substituting "gedit" with your preferred editor ("kate" on Kubuntu; "mousepad" on Xubuntu, or "scite" as a cool alternative)
sudo gedit /etc/apache2/sites-available/testsite.local
In the text editor, put in something like this (you might also need to create the weblogs folder):
<VirtualHost *:80> ServerName testsite.local DocumentRoot /home/webdev/Projects/testsite.local/public_html ErrorLog /home/webdev/WebLogs/testsite-error.log CustomLog /home/webdev/WebLogs/testsite-access.log common DirectoryIndex index.php index.html </VirtualHost>
Then save the file and enable it with:
sudo a2ensite testsite.local sudo /etc/init.d/apache2 restart
As an additional step you may find it useful to be able to access your test site from the host OS's browser by using "testsite.local". In order to do this you need to add a line to the /etc/hosts file:
sudo gedit /etc/hosts
And in this file, add a line like:
sudo apt-get install pure-ftpd
And also add the group "www-data" to your server's "webdev" user. If you're lazy, like me, you can just change the permissions of the files on your website files to 777 ("chmod -R 777 /home/webdev/Projects") and use your "webdev" user to access the FTP. It doesn't really matter for these files as it's only for testing, but I'll perhaps write another article delving into the correct permissions / settings at a later stage.
I may add / amend anything in here as it's a reference for myself as much as anyone else. I've tested the entire process a few times now, so the theory is sound, even if I may have made a few typos or errors writing this :P
sudo apt-get install sendmail
However, you may or may not need to make changes to the configuration to get it working (correctly). Again, all I'm interested in is getting something basic that I can make tests with.
Update: for sendmail, I also needed to add my hostname (server.dev) and localhost.localdomain. This fixed a problem where it was taking ages to send an email via PHP.
127.0.0.1 localhost localhost.localdomain server.dev