How To Build a Vhosted Linux Development Server on Windows using VirtualBox
I've been doing a fair bit of PHP and Python on Linux recently. My favorite PHP editor, PhpEd is Windows only. However, I prefer to develop LAMP code on LAMP. Here's a solution: Linux on VirtualBox, networked to the host Windows OS.
NOTE: The latest version of VirtualBox, 3.0.2 at this time, puts a few things in different places, particularly the VT-x/AMD-V and Nested Paging settings. Check the latest VirtualBox docs for more info






sudo /cdrom/VBoxLinuxAdditions-x86.run from a shell in the guest. (If you installed a 64bit AMD Linux, look for VBoxLinuxAdditions-amd64.run.) This script will require a reboot and may need to be re-run after certain kernel updates.
sudo apt-get install apache2 mysql-server php5 php5-cli
sudo apt-get install php5-mysql libapache2-mod-php5
sudo mkdir /var/www/vhostsand add the line
sudo chmod 777 /var/www/vhosts
sudo vi /etc/fstab
vhosts /var/www/vhosts vboxsf iocharset=utf8,umask=000,uid=33 0 0
sudo mount vhostsand you should see the disk info for you host system disk, now mounted under Linux
df -h /var/www/vhosts
Filesystem Size Used Avail Use% Mounted on
vhosts 269G 174G 96G 65% /var/www/vhosts
Choose the Network settings. You should have a "VirtualBox Host-Only Ethernet Adapter network" already listed. (This network was used for your Adapter 2 setup above.) Select the little screwdriver icon and edit the details of that Host-only network. For mine, I turn off the builtin DHCP server, and set the network address to a range that doesn't conflict with anything on my other private networks:
I tried Gnutls for SSL Name Vhosting...I'll spare the details, but give it a pass.
sudo vi /etc/network/interfaces
auto eth1:0and then
iface eth1:0 inet static
name Ethernet alias LAN card
address 192.168.56.11
netmask 255.255.255.0
broadcast 192.168.56.255
network 192.168.56.0
auto eth1:1
iface eth1:1 inet static
name Ethernet alias LAN card
address 192.168.56.12
netmask 255.255.255.0
broadcast 192.168.56.255
network 192.168.56.0
auto eth1:2
iface eth1:2 inet static
name Ethernet alias LAN card
address 192.168.56.13
netmask 255.255.255.0
broadcast 192.168.56.255
network 192.168.56.0
sudo update-rc.d -f networking removeand
sudo update-rc.d networking defaults
sudo /etc/init.d/networking restart
ifconfig
ifconfig should give you something like
eth0 Link encap:Ethernet HWaddr 08:00:27:41:86:02
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe41:8602/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:30837 errors:0 dropped:0 overruns:0 frame:0
TX packets:15654 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:46594350 (46.5 MB) TX bytes:853804 (853.8 KB)
Interrupt:11 Base address:0xc020
eth1 Link encap:Ethernet HWaddr 08:00:27:ff:f6:55
inet6 addr: fe80::a00:27ff:feff:f655/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:298 errors:0 dropped:0 overruns:0 frame:0
TX packets:33 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:48980 (48.9 KB) TX bytes:6287 (6.2 KB)
Interrupt:10 Base address:0xc240
eth1:0 Link encap:Ethernet HWaddr 08:00:27:ff:f6:55
inet addr:192.168.56.11 Bcast:192.168.56.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:10 Base address:0xc240
eth1:1 Link encap:Ethernet HWaddr 08:00:27:ff:f6:55
inet addr:192.168.56.12 Bcast:192.168.56.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:10 Base address:0xc240
eth1:2 Link encap:Ethernet HWaddr 08:00:27:ff:f6:55
inet addr:192.168.56.13 Bcast:192.168.56.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:10 Base address:0xc240
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:40 errors:0 dropped:0 overruns:0 frame:0
TX packets:40 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3290 (3.2 KB) TX bytes:3290 (3.2 KB)
\Windows\System32\drivers\etc\hosts:
192.168.56.10 myhost
192.168.56.11 dev.mysite1.com
192.168.56.12 dev.mysite2.com
192.168.56.13 dev.mysite3.com
/etc/hosts
192.168.56.10 myhost
192.168.56.11 dev.mysite1.com
192.168.56.12 dev.mysite2.com
192.168.56.13 dev.mysite3.com
ping dev.mysite1.com
sudo a2enmod ssland add the following vhost setup on one of the IPs you created above.
sudo mkdir -p /var/www/vhosts/mysite1.com/httpdocs
sudo mkdir -p /var/www/vhosts/mysite1.com/log/
sudo vi /etc/apache2/sites-available/dev.mysite1.com
The certs are Ubuntu standard issue. If you're on a different distro...
<VirtualHost 192.168.56.11:80>
ServerName dev.mysite1.com
ServerAdmin "me@mysite1.com"
DocumentRoot /var/www/vhosts/mysite1.com/httpdocs
CustomLog /var/www/vhosts/mysite1.com/log/access_log combined
ErrorLog /var/www/vhosts/mysite1.com/log/error_log
<IfModule mod_ssl.c>
SSLEngine off
</IfModule>
<Directory /var/www/vhosts/mysite1.com/httpdocs>
<IfModule mod_php5.c>
php_admin_flag engine on
php_admin_flag safe_mode off
</IfModule>
Options +Includes +ExecCGI
</Directory>
</VirtualHost>
<VirtualHost 192.168.56.11:443>
ServerName dev.mysite1.com:443
ServerAdmin "me@mysite1.com"
DocumentRoot /var/www/vhosts/mysite1.com/httpdocs
CustomLog /var/www/vhosts/mysite1.com/log/ssl_access_log combined
ErrorLog /var/www/vhosts/mysite1.com/log/ssl_error_log
SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
<Directory /var/www/vhosts/mysite1.com/httpdocs>
<IfModule mod_php5.c>
php_admin_flag engine on
php_admin_flag safe_mode off
</IfModule>
Options +Includes +ExecCGI
</Directory>
</VirtualHost>
sudo a2ensite dev.mysite1.comor whatever you'd like to call it.
sudo /etc/init.d/apache2 restart
[/snippet[
and a nice bit of housekeeping <code>sudo vi apache2.conf</code>, find and after the ServerRoot directive add
[snippet]
ServerName "MySite"
echo >/var/www/vhosts/mysite1.com/httpdocs/phpinfo.php '<?php
phpinfo();
?>'
and from the host browse to http://dev.mysite1.com/phpinfo.php and https://dev.mysite1.com/phpinfo.php. You should see
- Install mysql tools on the guest:
sudo apt-get install mysql-admin mysql-query-browser
- Setup the PhpEd debugger extension on the guest, configure a Website Project under vhosts/mysite1.com on the host, and debug from host to guest. When you edit and save files on the host side, they're already in place for Apache running in the guest, thanks to the vhosts mount.
- Tune down the mysql & apache params for dev loads, make your VM a little more host friendly. Linode has a nice guide to this end.
- While you're tuning mysql, you may want to enable slow query logging. In
/etc/mysql/my.cnfuncommentlog_slow_queries = /var/log/mysql/mysql-slow.log
long_query_time = 2
log-queries-not-using-indexes - Also in
/etc/mysql/my.cnfchange the bind-address for access from the windows host:bind-address = 0.0.0.0
- If you're using it, make InnoDB the default storage engine sudo echo >/etc/mysql/conf.d/default_storage_engine.cnf "[mysqld] default-storage-engine = InnoDB"
Comments
Great tut so far, but I keep getting an error when I try to restart the network.
- if-up.d/mountntfs[eth0]: waiting for interface eth1:0 before doing NFS mounts
- if-up.d/mountntfs[eth0]: waiting for interface eth1:1 before doing NFS mounts
- if-up.d/mountntfs[eth0]: waiting for interface eth1:2 before doing NFS mounts
I'm using VB 3.0.10 with a Ubuntu 8.10 64bit guest OS, running on a WinXP x64 host machine.
Any idea what might be wrong?
Also I followed this setup tut first - http://www.sitepoint.com/blogs/2009/10/27/build-your-own-dev-server-with-virtualbox/
Thanks,
Derek.
Also I meant to mention that when I follow this error with a
sudo ifconfig
command it doesn't show the updates to the network, just the defaults.
Sorry, forgot to also say that my wireless config tool states my ip address etc on the host machine is as follows:
IP Address: 192.168.1.XX (XX think this changes at times) Subnet Mask: 255.255.255.0 Gateway: 192.168.1.254
Just in case it helps.
D.
Ok I got as far as the bridged adaptor, then went to modify the iptables files, but I can't find the sysconfig folder. I'm running Ubuntu 8.10, which appears to be different to Fedora. I've been using Windows for the last 15 years or so and have only started with Ubuntu in the last couple of months, so its all new to me.
Ok I got as far as the bridged adaptor, then went to modify the iptables files, but I can't find the sysconfig folder. I'm running Ubuntu 8.10, which appears to be different to Fedora. I've been using Windows for the last 15 years or so and have only started with Ubuntu in the last couple of months, so its all new to me.
buy r4 dsi
Related links
| PHP IDE - NuSphere PhpED - Complete PHP IDE for PHP Development. Posted by Rod, on Aug. 6 2009 |


