Setting up Drupal development environment using Ubuntu and VirtualBox
Planning to set-up new development environment, but haven't yet quite decided between MAMP and installing Apache and MySQL locally?
There is also 3rd option, run LAMP stack virtuallized locally.
Benefits of running your XAMP (apache, mysql & php) stack in virtualbox has many benefits.
- Like having same environment as in production.
- All libraries are not (easily) available to all platforms.
- Freeing resources is easy, just shutdown your virtualmachine.
- Download and install VirtualBox https://www.virtualbox.org/
- Download and install Ubuntu 12.04 Server http://www.ubuntu.com/download
We need guest additions to get access local files in your host machine (folder sharing).
sudo apt-get install dkms build-essential linux-headers-`uname -r` sudo shutdown -r now
Click on VirtualBox menu: Devices -> Install Guest Additions...
sudo mkdir /media/cdrom sudo mount /dev/cdrom /media/cdrom cd /media/cdrom sudo ./VBoxLinuxAdditions.run --nox11 sudo shutdown -r now
(note: device may also be cdrom0 - cdromN)
Sharing folder with host
Apache (in Ubuntu) will need access to your local folder where you keep your Drupal Projects, something like projects or sites.
In VirtualBox, select your (new just-installed?) server image and adjust its settings. From under Shared Folders, share the folder you are using for your drupal projects. Basically if your drupal sites are under /Users/Uname/Sites/%PROJECT, share the Sites folder. DO NOT check read-only, instead check auto-mount option. If there are issues in mounting, do it manually.
To get access to share in linux, you need to add your username and www-data to vboxsf group by using
sudo usermod -a -G vboxsf www-data
Install and configure Apache and PHP
Start by downloading & configuring Apache and PHP
sudo apt-get install libapache2-mod-php5 php-pear php5 php5-cli php5-common php5-dev php5-gd php5-mysql php5-curl sudo apt-get install php-apc libapache2-mod-rpaf
Enable Apache modules and remove unneeded mods
Remove modules: cgi, autoindex, status; - a2dismod cgi autoindex statusEnable modules: Rewrite, expires;;- a2enmod rewrite expires
sudo apt-get install -y mysql-server mysql-client
Make sure mysql starts at reboot
character_set_server=utf8 collation_server=utf8_swedish_ci default-storage-engine=innodb
Restart MySQL and clear old index files
sudo /etc/init.d/mysql stop sudo rm /var/lib/mysql/ib* sudo /etc/init.d/mysql start
Stable ip for virtual machine (Ubuntu)
Stable ip is must-have for usability, you don't want to adjust configuration every time your ip-address changes.
This can be archieved by creating global (in VirtualBox) network and using it in virtual machine.
From VirtualBox's (softwares) preferences go to networking tab and create new network.
After you have created network, go to settings of virtual machine (ubuntu server) and edit network settings.
Adapter 1: Host only, select the network you just created.
Adapter 2: Since throught adapter 1 won't provide internet access, you can do it throught another adapter. Configuration depend your environment, but try either NAT or bridge.
Creating first site
First start by adding new site to /etc/apache2/sites-available/default file or create new file, you can use old configuration as a base.
Point directory to mounted folder in /media/MOUNT/folder (example /media/sf_Sites).
note: if your files are directly under mount-point, you will get 403 Forbidden error
Don't forget to reload settings! (sudo service apache2 reload)
Second step is checking what ip-address is assigned to your virtualbox machine. With default configuration it is propably 192.168.56.101. You can see your current ip-address by typing ifconfig in terminal and looking ip of eth0 interface.
You want alias for your site what you can use to access site from your local environment, example project.dev.
In Mac OS X or Linux add following line to /etc/hosts (in Windows use equilavent configuration):
As Juan pointed out if you have issues with file permissions you can try out solution from (http://askubuntu.com/questions/123025/what-is-the-correct-way-to-share-d... ), i think solved write permissions on Linux by adding user to same group with vboxfs.
But i think in the performance POW, it's best to use NFS mount.