After spending some time configuring Yosemite to end up in a poor result (slow server, MySQL crashing repeatedly), I decided have a look at this Vagrant stuff.
I was astonished how easy it was to get up and running with it.
Vagrant is a VM based development environment that automates current actions for a vhost (database creation, Apache entries, ...) and provides shared directories between the host system (here, MacOSX) and the VM. Starting points are called boxes (ready to user VM's) and can be found on sites such as http://www.vagrantbox.es/ or https://atlas.hashicorp.com/boxes/search
A Drupal ready environment is provided by the community, it comes out of the box with
- A LAMP stack (Ubuntu)
- Drush (with automatic aliases)
- Webgrind (Xdebug profiling)
- Mailcatcher (that is preconfigured out of the box to intercept every outgoing email, nice)
Hereunder, a shortcut for the documentation based on https://www.drupal.org/node/2008792
- Download VirtualBox https://www.virtualbox.org/wiki/Downloads
- Download Vagrant http://www.vagrantup.com/downloads.html
- Download https://www.drupal.org/project/vdd
- Expand VDD in home directory. Example: one version on vdd_test, for quick module review / another on vdd_sites as a replacement of ~/Sites driven by Mac OSX Apache install.
- Edit the config.json on vdd_sites with the website details
- On the vdd_sites directory, run
vagrant up: will build your vhosts, databases, drush aliases
- Once done,
vagrant sshto open a SSH session on your fresh VM
- The first thing to do is to setup NFS on the VM :
sudo apt-get install nfs-kernel-server, that will enable the NFS protocol between MacOSX and the VM (much faster thant the default configuration)
- Change the config.js : under
vagrant reloadunder vdd_sites (on MacOSX)
- Visit http://192.168.44.44/
- Copy the values dedicated to the MacOSX /etc/hosts files
- Git clone in the current directory : cd into sites/my_site then git clone https://my.git.repo . (do not forget the trailing period)
- Code happily
If you have to rebuild (vagrant destroy then vagrant up - removes all your databases, keeps files and recreates the environment), keep in mind to change back type = "default" (from "nfs") before launching vagrant up, otherwise, it will cause errors (no more nfs packages installed on your VM).
If you encounter the PDOException: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away, your database probably needs more ressources. Modify your MySQL configuration file
sudo nano /etc/mysql/my.cnf and append the following under the [mysqld] section :
max_allowed_packet = 32M save and relaunch MySQL
sudo service mysql restart
Time to insall Drupal now !
Inside ~/sites/my_site (defined in config.json)
cd in your docroot
git clone --branch 8.0.x http://git.drupal.org/project/drupal.git .
drush @my_site si standard -y
remove the docroot directory
drush dl drupal --drupal-project-rename=docroot
drush @my_site si standard -y
You can also continue by configuring PHP Storm for XDebug, use your GitHub GUI by adding the cloned repo, ...
Apply changes in config.json
The documentation talks about
vagrant reload --provision I always got this error:
Shared folders that Chef requires are missing on the virtual machine. This is usually due to configuration changing after already booting the machine. The fix is to run a `vagrant reload` so that the proper shared folders will be prepared and mounted on the VM.
To get rid of this and apply changes:
vagrant reload --provision