Setting up a VirtualBox LAMP Server
Introduction
I recently decided to play around with web development a little bit. Not being familiar with setting up a web server, I decided to setup a VirtualBox LAMP server. Since I couldn’t find a good guide that went through all the steps of setting up a VirtualBox LAMP Server in one place, I decided to write about my experience. I wanted a LAMP Server that I could access from any machine on my local network. In retrospect, it isn’t very hard to do, but having all the information in one place is nice.
Installing VirtualBox
Start by installing VirtualBox. The open source edition (OSE) should be good enough to use for the purposes of this guide. I was installing the full edition on openSuSE 11.2, and there were some issues. The issue I had was solved with this command: sudo chmod +x /usr/lib/virtualbox/VirtualBox and remove /tmp/*vbox*. Generally speaking it’s fairly easy to install VirtualBox on Windows. When creating a new virtual machine, I allocated 512MB of RAM and 12GB of HD space.
Installing LAMP
I chose Ubuntu for my LAMP server largely because there are many documents on how to setup a LAMP server on top of Ubuntu. I’ll do a quick overview here, and provide a link to setting up a LAMP server on Ubuntu (Hardy Heron). I liked this guide more than the guide for Jaunty because this one tells you to install the OpenSSH server, and being able to administer the VM remotely is a good idea.
Start by downloading the Ubuntu Server Edition. I tried downloading and installing Hardy Heron, which is the latest Long Term Support (LTS) release, but I kept getting a Kernel Panic when trying to boot in VirtualBox 3.1.2. It may have been the combination of VirtualBox version and Ubuntu version. Eventually, I ended up going with Karmic Koala. The installation process is almost identical to the Hardy Heron installation, and it provides both the LAMP and OpenSSH options that the guide suggests.
Network Configuration
Click on your newly created virtual machine, and open the settings dialog. Then click the Network settings area. For Adapter 1, make sure that the Enable Network Adapter checkbox is checked. Adapter 1 is attached to NAT by default, switch it to Bridged Adapter for it to look like a regular PC to the rest of your network. It will acquire an IP address from your router, like a normal computer. If you only want your host computer to be able to access it the Host-only Adapter option seems like an appropriate choice, but I did not use or test this option. After changing the setting, start up the virtual machine. To get the IP of the virtual machine use the ifconfig command. If you point your browser at that IP, you should see the apache welcome page.
Static IP
Setting a static IP address for the virtual machine is a good idea so you can always access the same IP address. These are the instructions for setting a static IP in Ubuntu.
Edit the /etc/network/interfaces file using vim or nano:
sudo [your_editor] /etc/network/interfaces
Find this line:
iface eth0 inet dhcp
Change it to:
iface eth0 inet static address 192.168.1.99 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.1
These settings worked well for my Linksys router. By default, the DHCP service the router provides starts using IP addresses starting with 192.168.1.100. By using 192.168.1.99 it was outside of that range. The Linksys router defaults to using 192.168.1.1 for its own IP, which is why the gateway is set to that.
Pure-FTPd FTP Server
The last step is setting up an FTP Server on it so you can easily transfer files. For this I chose Pure-FTPd because the project prides itself on is being easy to configure. It largely worked right out of the box without any configuration.
To install it:
sudo apt-get install pure-ftpd
Some Pure-FTPd configuration:
CD to the configuration directory located here: /etc/pure-ftpd/conf Set display dot files to on (so you can see your .htaccess file): echo yes > DisplayDotFiles Restart Pure-FTPd: sudo /etc/init.d/pure-ftpd restart Get your user connected to the /var/www directory: CD to your home folder and create a symbolic link to /var/www ln -s /var/www www Change ownership /var/www to your user, so you can write to this directory. chown -R /var/www Change to 755 permissions chmod -R 755 /var/www
You should now be able to connect to the FTP server from anywhere on your network by pointing your FTP client at: 192.168.1.99 (or any IP you may have chosen). It should have no problem running PHP files.
If any part of this short guide was confusing or didn’t work, leave a comment so I can look into it and update the guide.
In: Uncategorized · Tagged with: lamp, virtualbox
on March 17, 2010 at 2:23 pm