Drupal Development with Virtual Box

warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid/gid is 751/751 is not allowed to access /tmp owned by uid/gid 0/0 in /home/opengov1/public_html/www.matsearle.com/includes/file.inc on line 190.

I often use Virtual Box to do cross browser testing. It became an issue for me as a web developer to boot up into another operating system and then discover that I had theming issues. To be able to develop against this os I needed to make changes in it (therefore duplicating my code) and providing inconsistencies between each version. Here I provide 2 scripts which enable you to point your Virtual Box browser at your local machines ip address and allow you develop locally and test your results in virtual box. A great time saver and means you no longer have to switch between machines/boot sessions.

If you are using a LAMP setup and want to test your website cross browser, you may use Virtual Box. I have written a couple of scripts which change the default page which is served up from Apache so that when you point the Virtual Box browser to your ip address it shows your localhost.

This has it's advantages in being able to develop on your local machine and it show the changes in the Virtual Box browser. Priceless for theming tasks. No more booting up windows to check your site.

Here is the first one. I have put checks here to ensure that you do not run the same script twice after one another. It will tell you to run the other one if it finds you have.

RDP_TO_LOCAL.sh

#!/bin/bash -ex
 
#to create the local environment on rdp
 
cd /etc/apache2/sites-available
 
defaultconfig="/etc/apache2/sites-available/default.bak" 
 
if [ -e "$defaultconfig" ] # checking to see if we have default.bak, if we do, stop as we will remove the original config.
then
  echo "WARNING - YOU HAVE ALREADY RUN local_environment_rdp.sh, RUN REVERSE SCRIPT BEFORE TRYING THIS AGAIN, SCRIPT HAS BEEN EXITED."
  exit
fi
 
sudo mv default default.bak
 
sudo ln -s defaqto.localdomain.conf default
 
cd /var/www/my_drupal_website
 
sudo mv default default.bak
 
sudo ln -s www.defaqto.com/ default
 
sudo /etc/init.d/apache2 restart
 
echo "now point your rdp browser at you ipaddress"

Here is the second script to revert it back to how it started:

REV_RDP_TO_LOCAL.sh

#!/bin/bash -ex
 
# to get your local environment back to how it was before using rdp locally
 
cd /etc/apache2/sites-available
 
defaultconfig="/etc/apache2/sites-available/default.bak" # checking to ensure we have the original config (default), if not stop as we are removing important info
 
if [ ! -e "$defaultconfig" ]
then
  echo "WARNING - YOU HAVE NOT RUN local_environment_rdp.sh, SO REVERSING IT WILL CAUSE PROBLEMS, SCRIPT HAS BEEN EXITED."
  exit
fi
 
sudo rm default
 
sudo mv default.bak default
 
cd /var/www/my_drupal_website
 
sudo rm default
 
sudo mv default.bak default
 
sudo /etc/init.d/apache2 restart
 
echo "should be back to how it was before you changed your rdp to point at local ;)"

To run the script go 'cd' to the directory that it is located and dependant on which script you are running type:

./RDP_TO_LOCAL.sh

Later on I will write a short blog about creating aliases and variables in bash to enable you to run the script simply by typing the alias i.e.

$ rdp_local

Hope it's useful to some people.

© 2011 Creation Web Design. Website Designed & Built by Creation Web Design.