<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Johan&#039;s Blog &#187; Virtualization</title>
	<atom:link href="http://blog.johan-mares.be/category/ict/virtualization/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.johan-mares.be</link>
	<description>A personal blog</description>
	<lastBuildDate>Sat, 24 Jul 2010 18:35:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Installing a virtual Ubuntu LAMP-server on Mac OS X using VirtualBox</title>
		<link>http://blog.johan-mares.be/ict/linux/installing-a-virtual-ubuntu-lamp-server-on-mac-os-x-using-virtualbox/</link>
		<comments>http://blog.johan-mares.be/ict/linux/installing-a-virtual-ubuntu-lamp-server-on-mac-os-x-using-virtualbox/#comments</comments>
		<pubDate>Sun, 01 Feb 2009 23:02:19 +0000</pubDate>
		<dc:creator>Johan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Virtualization]]></category>
		<category><![CDATA[LAMP]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[VirtualBox]]></category>

		<guid isPermaLink="false">http://blog.johan-mares.be/?p=188</guid>
		<description><![CDATA[Virtualization is a hot topic in ICT. How can you put this to use at home and more specifically on your Mac ? You can use it to run Windows on your Mac, but also to try out different flavors of Linux or to run a LAMP (Linux Apache MySQL PHP) development server. If you have a spare recent pc you can install a baremetal hypervisor like XenServer5, but that's a different story. If you want to install a hypervisor or virtual machine monitor on your MacBook, Mac mini or iMac, there are a number of solutions available. To name a few: VMWare, Parallels, Q and VirtualBox.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.johan-mares.be%2Fict%2Flinux%2Finstalling-a-virtual-ubuntu-lamp-server-on-mac-os-x-using-virtualbox%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.johan-mares.be%2Fict%2Flinux%2Finstalling-a-virtual-ubuntu-lamp-server-on-mac-os-x-using-virtualbox%2F&amp;source=maresjohan&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>Virtualization is a hot topic in ICT. How can you put this to use at home and more specifically on your Mac ? You can use it to run Windows on your Mac, but also to try out different flavors of Linux or to run a LAMP (Linux Apache MySQL PHP) development server. If you have a spare recent pc you can install a baremetal <a title="hypervisor" href="http://en.wikipedia.org/wiki/Hypervisor" target="_blank">hypervisor</a> like XenServer5, but that&#8217;s a different story. If you want to install a hypervisor or virtual machine monitor on your MacBook, Mac mini or iMac, there are a number of solutions available. To name a few: VMWare, Parallels, Q and VirtualBox.<br />
First requirement: it has to be free, free as in made freely available by the software vendor, not as in a pirated or illegal copy. So skip VMWare (unless you stick with the VMWare Player) and Parallels.<br />
Second requirement: it must be a hypervisor project, preferably open source, with active development, user groups, forums and good documentation.<br />
So I chose <a title="VirtualBox" href="http://www.virtualbox.org/" target="_blank">VirtualBox</a>. For the cross-platformers among you, like myself, VirtualBox also runs on Windows, Linux and OpenSolaris and supports a large number of guest operating systems including Windows (NT 4.0, 2000, XP, Server 2003, Vista), DOS/Windows 3.x, Linux (2.4 and 2.6), Solaris, OpenSolaris, and OpenBSD.<br />
But this post will be about installing a virtual Ubuntu LAMP or web server on Mac OS X using VirtualBox.<span id="more-188"></span></p>
<h3>
<div id="attachment_370" class="wp-caption alignright" style="width: 160px"><a href="http://blog.johan-mares.be/wp-content/uploads/2009/02/vbu-sharing.png"><img class="size-thumbnail wp-image-370" title="vbu-sharing" src="http://blog.johan-mares.be/wp-content/uploads/2009/02/vbu-sharing-150x150.png" alt="Sharing" width="150" height="150" /></a><p class="wp-caption-text">Sharing</p></div>
<p>Getting started</h3>
<p>For starters, you will need a Mac. I have a MacBook 2.16 GHz Intel Core Duo, with 2 GB RAM and 120 GB hard disk and Mac OS X Leopard (10.5.6) installed. My Mac is connected to a wireless router.<br />
Next, you will need to download <a title="Download VirtualBox" href="http://www.virtualbox.org/wiki/Downloads" target="_blank">VirtualBox</a> for Intel Macs (mine is version 2.1.0) and <a title="Download Ubuntu" href="http://www.ubuntu.com/getubuntu/download" target="_self">Ubuntu</a> server (I chose for the 8.04 <abbr title="Long Term Support">LTS</abbr> 32 bit version).<br />
You will also need enough diskspace to install one or more virtual machines, but that goes without saying &#8230; right ? 8 GB and up is recommended for a virtual machine, but since we will be using the server edition, <abbr title="Command Line Interface">CLI</abbr> only (no GNOME, no KDE, no Office suite, no games, &#8230;) 4-5 GB should be more than enough for a development webserver.</p>
<div id="attachment_371" class="wp-caption alignleft" style="width: 160px"><a href="http://blog.johan-mares.be/wp-content/uploads/2009/02/vbu-tcpip.png"><img class="size-thumbnail wp-image-371" title="vbu-tcpip" src="http://blog.johan-mares.be/wp-content/uploads/2009/02/vbu-tcpip-150x150.png" alt="IPv6" width="150" height="150" /></a><p class="wp-caption-text">IPv6</p></div>
<p>The installation of VirtualBox is pretty straightforward, so I&#8217;ll skip this.<br />
However, you must change some settings of Mac OS X. First you must enable internet sharing. To do this, open &#8216;System Preferences&#8217; and in &#8216;Internet &amp; Network&#8217; click &#8216;Sharing&#8217;. Now you get the window you see in the picture &#8216;Sharing&#8217;, select &#8216;Internet Sharing&#8217;, for &#8216;Share your connection from:&#8217; select  &#8216;Airport&#8217; (when you use wireless) and select in &#8216;To computers using&#8217; the &#8216;Ethernet&#8217; option.<br />
Secondly, some sites mention that you should disable IPv6. I didn&#8217;t notice any difference between IPv6 status &#8216;Off&#8217; or &#8216;Automatically&#8217;. The information on those sites wasn&#8217;t very recent  and, if I recall correctly, referred to VirtualBox version 1.x. My IPv6 is configured to &#8216;Automatically&#8217;, but if you want to turn it off, here&#8217;s how to do it. Again open &#8216;System Preferences&#8217; and in &#8216;Internet &amp; Network&#8217; click &#8216;Network, next click the &#8216;Advanced&#8230;&#8217; button and the &#8216;TCP/IP&#8217; tab. Where it mentions &#8216;Configure IPv6&#8242; select &#8216;Off&#8217;.<br />
That should take care of the preparations. Let&#8217;s get down to business and install a virtual webserver.</p>
<h3>Create a virtual machine</h3>
<div id="attachment_372" class="wp-caption alignleft" style="width: 160px"><a href="http://blog.johan-mares.be/wp-content/uploads/2009/02/vbu-main01.png"><img class="size-thumbnail wp-image-372" title="vbu-main01" src="http://blog.johan-mares.be/wp-content/uploads/2009/02/vbu-main01-150x150.png" alt="VirtualBox" width="150" height="150" /></a><p class="wp-caption-text">VirtualBox</p></div>
<p>Start VirtualBox. Before we go into the step by step creation process, I will explain some of the choices I made. For RAM I chose 256 MB, this is the minimum for an Ubuntu server, but as it is just for a virtual development or test server on my MacBook, this should be enough. Keep in mind that the memory you allocate to your virtual machine is no longer available for your real machine; 2 GB RAM minus 256 MB still leaves plenty of RAM available for my Mac, enough to run a second and even a third virtual machine if I want to, but if you only have 1 GB of RAM to start with, you will probably notice that everything slows down if you allocate 512 MB to your virtual machine. According to VirtualBox the recommended disk space for Ubuntu is 8 GB, but that is for the desktop version with Gnome and all the bells and whistles you don&#8217;t need in a server. I chose 5 GB to be on the safe side, but after installation I noticed that Ubuntu server needs less than 1 GB of disk space, so I guess 2 or 3 GB should be more than adequate. It depends of course on what kind of sites you&#8217;ll be developing. I chose for &#8216;Fixed-size storage&#8217; instead of &#8216;Dynamically expanding storage&#8217;, but both options work, so no worries here. In the case of &#8216;Dynamically expanding storage&#8217; you select the maximum disk space and that space will only be addressed when needed, so you save some space on your hard drive &#8230; at least for a while.</p>
<p>Create your virtual server:</p>
<ul>
<li>click on the &#8216;New&#8217; icon</li>
<li>click &#8216;Next&#8217; to go to &#8216;VM Name and OS Type&#8217;</li>
<li>choose a meaningful name</li>
<li>as &#8216;Operating System&#8217; select &#8216;Linux&#8217;</li>
<li>as &#8216;Version&#8217; select &#8216;Ubuntu&#8217; or &#8216;Linux 2.6&#8242;, both options work</li>
<li>click &#8216;Next&#8217; to go to &#8216;Memory&#8217;</li>
<li>select amount of RAM, I chose 256 MB</li>
<li>click &#8216;Next&#8217; to go to &#8216;Virtual Hard Disk&#8217;</li>
<li>leave &#8216;Boot Hard Disk&#8217; checked</li>
<li>click &#8216;New&#8230;&#8217;</li>
<li>click &#8216;Next&#8217; to go to &#8216;Hard Disk Storage Type&#8217;</li>
<li>I chose for &#8216;Fixed-size storage&#8217;</li>
<li>click &#8216;Next&#8217; to go to &#8216;Virtual Disk Location and Size&#8217;</li>
<li>I kept the default name and location</li>
<li>select amount of disk space, I chose 5 GB</li>
<li>click &#8216;Next&#8217; and &#8216;Finish&#8217;</li>
<li>for  &#8216;Fixed-size storage&#8217; this can take a couple of minutes</li>
<li>click &#8216;Next&#8217; and &#8216;Finish&#8217; (again)</li>
</ul>
<h3>Virtual machine settings</h3>
<div id="attachment_373" class="wp-caption alignleft" style="width: 160px"><a href="http://blog.johan-mares.be/wp-content/uploads/2009/02/vbu-general01.png"><img class="size-thumbnail wp-image-373" title="vbu-general01" src="http://blog.johan-mares.be/wp-content/uploads/2009/02/vbu-general01-150x150.png" alt="General tab" width="150" height="150" /></a><p class="wp-caption-text">General tab</p></div>
<p>Before actually installing your virtual Ubuntu server, you must change some settings.</p>
<p>In the main VirtualBox window, select the virtual machine you&#8217;ve just created and go to &#8216;Settings&#8217; either by a right mouse click on the virtual machine or by clicking on the &#8216;General&#8217; link (in blue). Now click on the &#8216;Advanced&#8217; tab and check &#8216;Enable PAE/NX&#8217;, this is required to install an Ubuntu server, it is however not needed for an Ubuntu desktop or so I&#8217;ve read.</p>
<p>On top of this window you see a list of icons: &#8216;General&#8217;, &#8216;Storage&#8217;, &#8216;Audio&#8217;, &#8216;Network&#8217;, &#8216;Ports&#8217;, &#8230; Click on &#8216;Network&#8217;. Here several settings need to be changed.<br />
Change the &#8216;Adapter Type&#8217; to &#8216;Intel PRO/1000 T Server (&#8230;)&#8217;. This adapter is less demanding on your CPU.<br />
Change &#8216;Attached to&#8217; to &#8216;Host Interface&#8217;, &#8216;NAT&#8217; is fine when you only want an outgoing connection like for Ubuntu Desktop, but you want your Ubuntu Server to accept incoming connections (HTTP, FTP, SSH) too, otherwise your server is useless, so change it to &#8216;Host Interface&#8217;.</p>
<div id="attachment_374" class="wp-caption alignright" style="width: 160px"><a href="http://blog.johan-mares.be/wp-content/uploads/2009/02/vbu-network01.png"><img class="size-thumbnail wp-image-374 " title="vbu-network01" src="http://blog.johan-mares.be/wp-content/uploads/2009/02/vbu-network01-150x150.png" alt="Network" width="150" height="150" /></a><p class="wp-caption-text">Network</p></div>
<p>Which host interface to select in &#8216;Host Interfaces&#8217; ? I read another blog that mentions that you must select &#8216;en0: Ethernet&#8217; even if you only have a wireless connection. I believe this caused all the problems I encountered installing this virtual machine. At first it was a success, the installation went fine, the server got assigned an IP address in the 192.168.2.0 network although I have no idea where this network comes from (Mac or VirtualBox). The updating, upgrading, configuring, &#8230; everything went smooth. I could connect from my MacBook to the virtual machine via HTTP and SSH. Next day, no more connections from the virtual server to the internet or from my MacBook to the server (cannot allocate memory errors, see troubleshooting chapter at the bottom). I lost count on how many attempts I made to get it to work. I was convinced that the problem was either caused by the IPv6 setting or because I didn&#8217;t install the linux-virtual kernel and the &#8216;Guest Additions&#8217; right away. Google searches indicated these to be the most likely culprits. Once the problem occurred, the only solution was to delete the virtual machine and start all over again. It was only after I selected &#8216;en1: Airport&#8217; as &#8216;Host interfaces&#8217; that it kept working. I could see a lot benefits by using the rogue/alien/virtual/&#8230; 192.168.2.0 network: I would be able to connect to my webserver even when my Mac was offline or on a different wireless network, so I didn&#8217;t want to give it up so easily. By selecting &#8216;en1: Airport&#8217; my virtual machines now connect to my wireless router, which has a 192.168.1.0 network. And there are benefits for this solution too: your virtual machines can connect to other machines on your home network (you can use this to make backups) or let those other machines connect to the virtual servers on your Mac (e.g. a Windows pc to test a website with IE). Maybe I did something wrong, maybe the information on the other site was wrong, but 4 times in a row I installed servers with &#8216;en1: Airport&#8217; as host interface and they keep on working.</p>
<h3>Installing Ubuntu server</h3>
<p>Don&#8217;t close the &#8216;Settings&#8217; window yet. Click on &#8216;Storage&#8217; and select the tab &#8216;CD/DVD-ROM&#8217;. If you already closed the window you can click on the link &#8216;CD/DVD-ROM&#8217;. Here you can either mount your Ubuntu CD-ROM in your &#8216;Host CD/DVD Drive&#8217; or select the &#8216;ISO Image File&#8217; you downloaded on your computer. When you choose the &#8216;ISO Image File&#8217; option, click on the folder button on the right and in the new window &#8216;Virtual Media Manager&#8217;, click on the &#8216;Add&#8217; button and browse to the location of the ISO file. Don&#8217;t forget to unmount the CD- or DVD-ROM the first time you shut down after installing.<br />
From an economical and tree hugger point of view it is better to install from an ISO image <img src='http://blog.johan-mares.be/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  .<br />
Now you may hit the &#8216;Start&#8217; button after you&#8217;ve selected the virtual machine.</p>
<div id="attachment_375" class="wp-caption alignright" style="width: 160px"><a href="http://blog.johan-mares.be/wp-content/uploads/2009/02/vbu-ub.png"><img class="size-thumbnail wp-image-375" title="vbu-ub" src="http://blog.johan-mares.be/wp-content/uploads/2009/02/vbu-ub-150x150.png" alt="Ubuntu" width="150" height="150" /></a><p class="wp-caption-text">Ubuntu</p></div>
<p>I am going to walk you through the installation process, but very briefly.</p>
<ul>
<li>select language</li>
<li>select &#8216;Install Ubuntu server&#8217; or &#8216;Check CD for defects&#8217; first</li>
<li>select language, country and keyboard</li>
<li>let it configure your network with DHCP, you can change it later</li>
<li>choose a name for your webserver</li>
<li>as partitioning method I chose &#8216;Guided &#8211; use entire disk&#8217;</li>
<li>for the next step there was only 1 disk to select</li>
<li>agree to write the changes to disks</li>
<li>you can take a break now</li>
<li>set up a user and password</li>
<li>&#8216;HTTP proxy information&#8217;: leave it blank</li>
<li>you can take another short break now</li>
<li>select at least the following software to install: &#8216;LAMP server&#8217; and &#8216;OpenSSH server&#8217;</li>
<li>you will be asked to provide a password for the MySQL root user</li>
<li>after installation, let your virtual machine reboot and don&#8217;t worry about the CD-ROM or ISO image, it will be ignored, but unmount it when you shut your new server down</li>
</ul>
<div id="attachment_376" class="wp-caption alignright" style="width: 160px"><a href="http://blog.johan-mares.be/wp-content/uploads/2009/02/vbu-selsoftware.png"><img class="size-thumbnail wp-image-376" title="vbu-selsoftware" src="http://blog.johan-mares.be/wp-content/uploads/2009/02/vbu-selsoftware-150x150.png" alt="Select software" width="150" height="150" /></a><p class="wp-caption-text">Select software</p></div>
<p>There are several advantages for using ssh from a Mac OS X Terminal instead of the terminal or user interface provided by VirtualBox:</p>
<ul style="text-align: left;">
<li>more control over the layout: font, size, colors, background</li>
<li>better keyboard support (e.g. @ # ^ | `)</li>
<li>faster, more responsive &#8230; at least that is my impression</li>
</ul>
<p>Now you have installed a virtual Ubuntu LAMP or web server. It just needs some polishing and then you are ready to go. I believe it is best to continue and especially optimize your kernel for a <abbr title="Virtual Machine">VM</abbr> environment before calling it a day.</p>
<h3>Finishing off</h3>
<p>You do not have to do all of the following steps, for example the steps on how to configure the Apache webserver and vsftpd FTP-server, you can skip these or alter them to your liking, but I just want to leave you with a working webserver. Since it is supposed to be a virtual development server on your notebook or desktop I haven&#8217;t really bothered with security, creating virtual host, optimizations, &#8230;<br />
I recommend you do not skip the network configuration, the update and upgrade and the installation of the virtual kernel and guest additions.</p>
<p><strong>Network configuration</strong>: Currently your network configuration is based on <abbr title="Dynamic Host Configuration Protocol">DHCP</abbr>. This is not very useful for a server, you need a static IP address. In the user interface provided by VirtualBox, log in to your server. First check your current network configuration:</p>
<pre>johan@lamp:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:d4:b0:68
          inet addr:192.168.1.4  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fed4:b068/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1167 errors:0 dropped:0 overruns:0 frame:0
          TX packets:829 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:523485 (511.2 KB)  TX bytes:103126 (100.7 KB)
          Base address:0xc010 Memory:f0000000-f0020000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:12 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:600 (600.0 B)  TX bytes:600 (600.0 B)</pre>
<p>Obviously I am connected to the network provided by my wireless router, now edit your network configuration using the command:</p>
<pre>sudo vi /etc/network/interfaces</pre>
<p>For safety reasons it is best to make a copy of this file before editing. I will demonstrate the settings for my home network, they might be different for yours, but this example should help you to figure it out:</p>
<pre># This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.1.80
gateway 192.168.1.1
netmask 255.255.255.0</pre>
<p>Notice that I don&#8217;t need to specify a wireless-essid, wireless-key or wireless-channel, even though it is, indirectly, using a wireless connection, the settings are for a wired connection.<br />
Next restart the network using the command:</p>
<pre>sudo /etc/init.d/networking restart</pre>
<p>You can check the new configuration with the command <em>ifconfig</em>.</p>
<p><strong>Update/Upgrade</strong>: After an installation it is recommended to update and upgrade the installed software. On an Ubuntu server you do this via the following two commands, the second one can take a while:</p>
<pre>sudo apt-get update</pre>
<pre>sudo apt-get upgrade</pre>
<p><strong>Virtual kernel</strong>: You have to customize or optimize the kernel for a <abbr title="Virtual Machine">VM</abbr> environment:</p>
<pre>sudo apt-get install linux-virtual<strong>
</strong></pre>
<p><strong>Installing Guest Additions</strong>: To install the Guest Additions, click, with your virtual server running and in the active window, in the &#8216;Menu Bar&#8217; on &#8216;Devices&#8217; and &#8216;Installing Guest Additions&#8230;&#8217;. The ISO image containing those additions is now mounted to your virtual machine. By default a CD-ROM is not automatically mounted in Ubuntu server, so use the following commands to gain access to the additions:</p>
<pre>johan@lamp:/$ sudo mount /media/cdrom
mount: block device /dev/scd0 is write-protected, mounting read-only
johan@lamp:/$ cd /media/cdrom
johan@lamp:/media/cdrom$ ls
32Bit        VBoxLinuxAdditions-amd64.run  VBoxWindowsAdditions-amd64.exe
64Bit        VBoxLinuxAdditions-x86.run    VBoxWindowsAdditions.exe
AUTORUN.INF  VBoxSolarisAdditions.pkg      VBoxWindowsAdditions-x86.exe</pre>
<p>According to the VirtualBox manual, you must install <abbr title="Dynamic Kernel Module Support">DKMS</abbr> to be able to compile the kernel using the command (don&#8217;t do it, continue to read):</p>
<pre>sudo apt-get install dkms<strong>
</strong></pre>
<p>If you do that, and you execute &#8216;VBoxLinuxAdditions-x86.run&#8217; you will get the following output:</p>
<pre>johan@lamp:/media/cdrom$ sudo sh ./VBoxLinuxAdditions-x86.run
[sudo] password for johan:
Verifying archive integrity... All good.
Uncompressing VirtualBox 2.1.0 Guest Additions for Linux installation............
VirtualBox 2.1.0 Guest Additions installation
Please install GNU make.
Please install the build and header files for your current Linux kernel.
The current kernel version is 2.6.24-23-virtual
Please install the GNU compiler.
Problems were found which would prevent the Guest Additions from installing.
Please correct these problems and try again.</pre>
<p>As far as I can figure this out, installing DKMS doesn&#8217;t take into account that you have installed the linux kernel for virtualised hardware (linux-virtual). So instead install the headers for the right kernel and the necessary tools to be able to build.</p>
<pre>sudo apt-get install linux-headers-`uname -r` build-essential</pre>
<p>After that you can install the additions (make sure that you are in the CD-ROM directory):</p>
<pre>sudo sh ./VBoxLinuxAdditions-x86.run</pre>
<p>The VirtualBox manual recommends installing them, but I haven&#8217;t used them yet. This post is all about <em>installing</em> a virtual Ubuntu server on Mac OS X. It&#8217;s not an in-depth look at or the nuts and bolds of VirtualBox.</p>
<p><strong>Changing the configuration of the webserver</strong> to enable the per-user web directories. This means that every user can have his/her own website by creating a special directory in his/her home directory. First create a &#8216;public_html&#8217; directory in your home and change the group to &#8216;www-data&#8217; to give the Apache webserver the necessary permissions to process your webpages.</p>
<pre>cd $HOME</pre>
<pre>mkdir public_html</pre>
<pre>sudo chgrp www-data public_html/</pre>
<p>Enable the userdir module and restart or reload the Apache webserver.</p>
<pre>sudo a2enmod userdir</pre>
<pre>sudo /etc/init.d/apache2 force-reload</pre>
<p>Create a PHP test page info.php in your public_home directory with the following contents</p>
<pre>&lt;?php phpinfo(); ?&gt;</pre>
<p>and on your client computer enter the following URL in your browser (change the IP address and username)</p>
<pre>http://192.168.1.80/~johan/info.php</pre>
<p>and you should get the version information for your PHP installation.</p>
<p><strong>Installing an FTP-server</strong> to upload your websites. I am used to the &#8216;Very Secure FTPD&#8217; server, <a title="vsftpd" href="http://vsftpd.beasts.org/" target="_blank">vsftpd</a>, although I believe this is not the default one for Ubuntu. Anyway it is easy to install if you use the following commands to install and stop vsftpd and edit the config file.</p>
<pre>sudo apt-get install vsftpd</pre>
<pre>sudo /etc/init.d/vsftpd stop</pre>
<pre>sudo vi /etc/vsftpd.conf</pre>
<p>In the configuration file uncomment the following settings</p>
<pre>local_enable=YES</pre>
<pre>write_enable=YES</pre>
<pre>local_umask=022</pre>
<p>and change the &#8216;YES&#8217; to &#8216;NO&#8217; in</p>
<pre>anonymous_enable=NO</pre>
<p>and save. Restart.</p>
<pre>sudo /etc/init.d/vsftpd start</pre>
<p>Now you should be able to upload files to your virtual webserver using an FTP-client like <a title="FileZilla" href="http://filezilla-project.org/" target="_blank">FileZilla</a>. Enter the IP-address, your username and password, click &#8216;connect&#8217;. If all goes well, you will see the contents of your home directory on the webserver, including the public_html directory. Any files you upload to the public_html directory will become visible or at least accessible when you enter the following URL in your browser (change IP and username to match your settings):</p>
<pre>http://192.168.1.80/~johan/</pre>
<p><strong>Some extras</strong>: On a webserver I like to have phpMyAdmin and PHP <abbr title="Command Line Interface">CLI</abbr> available (when installing phpMyAdmin, select &#8216;apache2&#8242; when prompted):</p>
<pre>sudo apt-get install php5-cli</pre>
<pre>sudo apt-get install phpmyadmin</pre>
<p>The further configuration of your webserver, samba, &#8230; is beyond the scope of this post. Good luck.</p>
<h3>Troubleshooting</h3>
<p>I experienced a lot of problems at first. The installation went fine, the updating, upgrading and configuring too. Next day, the server could no longer connect to the internet and I could no longer access the server via HTTP, SSH or even ping to it. This happened enough times to exclude an accidental configuration error or a corrupt ISO image. The error messages I got were:</p>
<pre>ping: sendto: Cannot allocate memory</pre>
<pre>ssh: connect to host 192.168.2.22 port 22: Cannot allocate memory</pre>
<p>Once these occur just delete your virtual server and start all over again. They are either caused by IPv6 being turned on, not installing the for <abbr title="Virtual Machine">VM</abbr>&#8217;s optimized kernel or using the fictitious, virtual or whatever it is called 192.168.2.0 network. I have narrowed it down to the use of the 192.168.2.0 network. I do not know enough of virtualization to explain this, I only want a virtual webserver, in fact more than 1 server, running on my MacBook.</p>
<p>You can connect to your virtual server from other machines in your home. This works without hassle for Macs and Linux boxes, but for Windows XP you have to ping or connect via ssh to your virtual server first before you can browse to it (<abbr title="look this one up yourself, will ya">WTF</abbr>).</p>
<h3>PS</h3>
<p>I have no idea if this post is also useful for installing a virtual Ubuntu server on a Windows or Linux host.</p>
<table style="border: medium none; margin: 20px auto; width: auto;" border="0" align="center">
<tbody>
<tr>
<td>Windows users swear at their computers.<br />
Mac users swear by their computers.</td>
</tr>
<tr>
<td align="right"></td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://blog.johan-mares.be/ict/linux/installing-a-virtual-ubuntu-lamp-server-on-mac-os-x-using-virtualbox/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
	</channel>
</rss>
