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
Permalink
Hi Joe,
this ifconfig thing doesn’t work for me. I get an IPv6 address (inet6) but it doesn’t work in my browser.
I tried changing the IP to a static one as you describe it but it doesn’t help either. (“Unable to connect”), although a new ifconfig shows that the changes are actually applied successfully. So I restarted the Ubuntu server to make sure, Apache is running and I prompted the IP 192.168.1.99 again in my host browser and got a “connection has timed out” this time. Refreshed 2x, no better. Any clue what’s wrong?
Thanks,
I.
on March 17, 2010 at 7:00 pm
Permalink
Did you make sure to set the network adapter in VirtualBox correctly?
On the dialog when the VM is selected my network section looks like this:
Can you post your ifconfig output, running it in the VM for me looks like this:
If you don’t mind, what kind of router are you using? 192.168.1.99 is an IP that is appropriate for my linksys router, you may need to use a different IP address.
on January 17, 2011 at 5:14 pm
Permalink
As much as I hate being one of those guys I just want to point a few things out for you that are… flawed. Once you get into your setup for Pure-FTPD it is full of permissions problems (from a default LAMP Ubuntu install).
echo yes > DisplayDotFiles
Returns:
-bash: DisplayDotFiles: Permission denied
The restart works as does the symbolic link.
chown -R /var/www
Returns:
chown: missing operand after ‘/var/www’
and obviously gives permission faults because the chown failed!
I’m going to dig around for these solutions, but I just thought you would like to know that your guide might have worked for you but seems like you accidentally left out a lot of things.
on January 17, 2011 at 5:19 pm
Permalink
Ok a brief update that experimenting was able to resolve the chown and chmod bit.
sudo chown -R /var/www so you can change ownership
sudo chmod -R 755 /var/www so you can change permissions
this has allowed it… I’m thinking that on 10.10 ubuntu it isn’t needed to DisplayDotFiles as it appears to be done already.
I do have to thank you for the guide as it was helpful… the need for sudo could be version dependant and I don’t want to discredit you for your knowledge.
on January 19, 2011 at 10:15 pm
Permalink
I’m glad you were able to find a solution to your problem. It appears I may have left out the sudo command. As I use Linux daily, it’s probably automatic for me. Sorry for the confusion.
on March 28, 2011 at 11:12 pm
Permalink
Been trying to get this to work for a very long time with complicated procedures, but this is actually quite a simple task illustrated very well and clearly. Thanks
on April 2, 2011 at 1:39 pm
Permalink
You’re welcome, I’m glad you found it useful!
on February 28, 2012 at 8:16 am
Permalink
Thank you, your guide is immensely helpful!
on March 26, 2012 at 10:30 am
Permalink
Just thought I’d say thank you: a very useful guide.
For reference when editing your /etc/network/interfaces file; you can find the netmask (Mask), broadcast (Bcast) from your host machine, which just leaves network and gateway: which for my router (a netgear) are the same (192.168.0.1)