I’m developing a new site using Drupal, and the production environment will be Linux. So I could develop the whole site on my windows machine… but I don’t like doing that. There’s always weird environment problems and it’s just nicer developing in the same environment that the production box will be on. Plus Drupal and PHP run so much faster on Linux!
Using Oracle’s VirtualBox you can have a local Linux server running on your windows machine! From here you can setup apache, mysql and drupal, share out your working folders and then do your development on your windows computer. It’s the best of both worlds.
My instructions below will show you how to run Apache on a different port (8088) so that your IIS will continue to work on port 80. The VM setup is also extremely unsecure so make sure that your machine is behind a very secured firewall!
So how do you do this?
Setup VirtualBox
First off, download your linux install. I used CentOS, and I downloaded the 64bit DVD iso’s. The file is about 4 gig… so bittorrent is the best option!
Next, download and install sun’s virtualbox:
When installing CentOS, I created new user account, username: lachlan, password: lachlan
To make troubleshooting easier, I completely turned off the firewall. Go to System, Admin, Security Level Configuration -> Firewall options, set the firewall to “Disabled”, inside the SELinux tab Management, set SELinux setting to “Disabled”
Setup Hostname
Give the box a hostname by editing:
/etc/sysconfig/network
and change it to:
HOSTNAME=LachDrupal
also edit:
/etc/hosts
and set it to:
127.0.0.1 localhost.localdomain localhost lachdrupal
::1 localhost6.localdomain6 localhost6
192.168.56.10 LachDrupal
Network Configuration
Shut down VM. Inside VirtualBox add a new network interface by going to box settings, Network, Adapter 2, setting it to “Host only Adapter”. Startup the machine.
Grab IP Address of host VM by typing:
/sbin/ifconfig
on my machine it is 192.168.56.10
Edit the network file for this network interface and set it to static IP instead of DHCP:
/etc/sysconfig/network-scripts/ifcfg-1
and it should contain:
DEVICE=eth1
BOOTPROTO=static
IPADDR=192.168.56.10
NETMASK=255.255.255.0
On my machine SSH was already running by default (if not, do this:)
yum -y install openssh-server openssh-clients
/sbin/service sshd start
I could then SSH to my virtualbox instance on port 192.168.56.10!!
Setup Apache
The directories that you need to look at for configuring apache are:
/etc/httpd/conf <-- config files
/var/www/html <-- base directory (similar to /inetpub/wwwroot)
/var/log/httpd <-- log file directory
open /etc/httpd/conf/httpd.conf and change/add the following lines:
Listen 192.168.56.10:8088
ServerName LachDrupal:8088
DocumentRoot "/var/www/html/drupal-7.8"
and right down the bottom put:
NameVirtualHost *:8088
<VirtualHost *:8088>
ServerAdmin me@example.com
DocumentRoot /var/www/html/drupal-7.8
ErrorLog /var/log/httpd/errorlog.log
</VirtualHost>
find the location of the 'Directory "/www/var/html"' line and change it to:
<Directory "/var/www/html/drupal-7.8" >
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>
(This is for enabling clean URLs in Drupal).
start up apache:
/sbin/service httpd restart
The URL should now work:
http://192.168.56.10:8088
Now that http://192.168.56.10:8088 works, you'll notice that no-one else on your network can go to http://192.168.56.10:8088, as it's a virtual port and IP only accessable from your machine. So what you need to do is to forward a port on your _external_ IP to the internal one.
So, shut down the VM.
Go back to adapter 1, click on "Port Forwarding". Enter a new rule, set the Host IP to be your machine's IP address (in my case 192.168.2.154) and set it to be port 8090. Set the Guest IP to be 192.168.56.10 and set the Guest Port to be 8088.
Startup the VM, startup apache, and then visit
http://192.168.2.154:8090
and it'll be accessable to all! You should also be able to use your hostname instead of your IP address.
Setting Up Mysql
First step, install mysql:
yum install mysql-server
Start up mysql:
/sbin/service mysqld start
Set the root password for mysql:
/usr/bin/mysqladmin -u root password 'lachlan'
Connected to mysql:
./mysql -p
(enter password 'lachlan')
create a database:
create database Drupal7;
then create an account under the name 'lachlan' :
CREATE USER 'lachlan'@'localhost' IDENTIFIED BY 'lachlan';
GRANT ALL PRIVILEGES ON *.* TO 'lachlan'@'localhost'
Download drupal 7:
cd /var/www/html
wget http://ftp.drupal.org/files/projects/drupal-7.8.tar.gz
tar xzvf drupal-7.8.tar.gz
chown -R apache:apache drupal-7.8
Now apparently the version of php that comes with CentOS is too old - by default it's 5.1 - so it needs to be updated to 5.2. At the moment 5.2 isn't certified for CentOS so you need to tell CentOS about the "testing" respository. Following these instructions: [http://wiki.centos.org/HowTos/PHP_5.1_To_5.2]
1. Create a file named:
/etc/yum.repos.d/CentOS-Testing.repo
2. Put this stuff in it:
# CentOS-Testing:
# !!!! CAUTION !!!!
# This repository is a proving grounds for packages on their way to CentOSPlus and CentOS Extras.
# They may or may not replace core CentOS packages, and are not guaranteed to function properly.
# These packages build and install, but are waiting for feedback from testers as to
# functionality and stability. Packages in this repository will come and go during the
# development period, so it should not be left enabled or used on production systems without due
# consideration.
[c5-testing]
name=CentOS-5 Testing
baseurl=http://dev.centos.org/centos/$releasever/testing/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing
includepkgs=php*
3. run
./yum php update
voila.
Drupal PHP Dependencies
You will also need to install GD, DOM and PDO.
To view which php packages you can install you can do:
./yum list php *
then:
yum install php-gd.x86_64
yum install php-pdo.x86_64
yum install php-xml.x86_64
yum install php-mysql.x86_64
Next, visit:
http://192.168.56.10:8088/install.php
then restart apache:
/sbin/service httpd restart
And Drupal should be all ready to go!
Samba (filesharing)
In order to access the drupal files from your windows machine, you need to setup a fileshare in samba. To do this, edit your
/etc/samba/cmd.conf
file to have the following:
[global]
workgroup = intrepidtravel.local
server string = Samba Server Version %v
security = share
passdb backend = tdbsam
wins support = yes
dns proxy = no
cups options = raw
guest ok = yes
guest account = lachlan
[drupal]
comment = Public Stuff
path = /var/www/html/drupal-7.8
force user = lachlan
force group = apache
browseable = yes
writeable = yes
guest ok = yes
map archive = yes
Then restart Samba:
/sbin/service smb restart
You should then be able to access this fileshare by going to:
\\LachDrupal\drupal
these files should be editable too! If not, check the linux file + directory permissions (make them 775 just to be safe).
I have setup my machine so that the drupal folder is owned by the user lachlan and group apache.
cd /var/www/html
chown -R lachlan:apache drupal-7.8
chmod 775 drupal-7.8
/usr/sbin/useradd -G apache lachlan
/usr/sbin/usermod -G lachlan apache
Setting up services to run at boot
By default, apache, samba and mysql won't run at bootup. Enter the following commands as root to set this up:
/sbin/chkconfig --level 235 httpd on
/sbin/chkconfig --level 235 mysqld on
/sbin/chkconfig --level 235 smb on
Et voila!
If anyone can suggest any better or simplier ways to set this up I'd love to hear from you!


Metaltheater.com now works on your mobile! If you pop out your iPhone, Blackberry, Android, Nokia or whatever, and go to metaltheater.com, you should find a nice and easy to read version of the site!