Vagrant + Craft CMS
A puppet provisioned Vagrant development server for Craft CMS projects. It uses the standard Vagrant Ubuntu Precise base box precise64.box
.
Please note: This is intended for development purposes only.
What do you get?
The latest versions of:
- Nginx (ppa:nginx/stable)
- PHP-FPM (ppa:ondrej/php5)
- phpMyAdmin
- MySQL
Tested on Vagrant 1.6.2.
Usage
First you need to install Virtualbox and Vagrant and then follow these steps:
-
Clone this repo into a
vagrant
folder at the root of your project. So it's sitting alongside yourpublic
,craft
, etc. folders:git clone https://github.com/enovatedesign/vagrant-craft.git vagrant
-
Grab the sub-modules:
cd vagrant && git submodule update --init
-
Make a logs directory within the Vagrant folder (PHP errors will be put here):
mkdir logs
-
Move the Vagrantfile to the root of your project:
mv .Vagrantfile ../Vagrantfile
-
Install the vagrant-cachier plug-in (this makes provisioning boxes from scratch way faster):
cd .. && vagrant plugin install vagrant-cachier
-
Get started (first run this takes 10 minutes after that about 3 minutes - thanks to
vagrant-cachier
:vagrant up
-
Restore your DB using phpMyAdmin by going to http://localhost:9000/ (you'll be logged-in automatically).
-
Access your website at http://localhost:8080/ and get to work!
You can use your hosts file to point http://craft.dev:8080/ or any domain you fancy at the site.
Important notes and troubleshooting
-
Running
vagrant destroy
is the virtual equivalent of throwing a computer out of the window so make sure you have a DB back-up first! -
Make sure your Craft database credentials are set correctly, e.g.:
'.local' => array( 'server' => 'localhost', 'user' => 'root', 'password' => 'password', 'database' => 'DATABASE NAME HERE', 'tablePrefix' => 'craft' )
-
For performance reasons the
craft/storage/runtime
folder is excluded from the Vagrant synced folder. As Craft writes a lot of log entries here this has a major impact on the VM performance (particularly on Windows). So excluding the folder makes the site run a LOT quicker but remember you need tovagrant ssh
onto the VM to access thecraft.log
file. -
In the Vagrantfile on lines 21 and 22 you may need to adjust the memory and CPU settings for the VM.
-
Using the
precise64.box
assumes you are running a 64-bit OS. I haven't tried but I assume you can switch toprecise32.box
if necessary (lines 10 and 11 of the Vagrantfile). -
You can un-comment line 20 in the Vagrantfile so that Virtualbox will launch a GUI so you can see the console for the VM as it launches for troubleshooting.
-
The Nginx virtual host file assumes you are serving Craft from a folder called
public
within the root of your project, if that's not the case it can be edited in the file/files/nginx/sites-available/default
at line 5. -
The server name that is presented to Craft CMS is "vagrant.local". This can be changed on line ~4 of the file
/files/nginx/sites-available/default
so it matches your multi-environment config.
Nginx
This is pre-configured to work with PHP-FPM and includes a Craft CMS friendly virtual host file and also another for phpMyAdmin.
The Craft CMS virtual host file includes some development friendly cache expiry settings too.
MySQL
The root password is "password".
phpMyAdmin
This is accessible at http://localhost:9000/ and will auto-login.
Log file location
All Nginx and PHP-FPM log files are written to the /logs/
folder.
As mentioned above the craft/storage/runtime
folder is not synced so you need to vagrant ssh
into the VM to view the craft.log
stored there.
Craft CMS not included!
This doesn't actually include Craft CMS! Sorry, it's intended to be dropped into your Craft CMS project.
With thanks to...
These repositories gave me a headstart on getting this done:
https://github.com/experience/vagrant-craft-application by Experience
https://github.com/MikeRogers0/vagrant-nginx-wordpress-puppet by MikeRogers0