Darren Mothersele

Software Developer

Warning: You are viewing old, legacy content. Kept for posterity. Information is out of date. Code samples probably don't work. My opinions have probably changed. Browse at your own risk.

Testing Drupal 8 dev with Nginx, PHP-FPM and MariaDB using Vagrant

Jul 8, 2013


My preferred setup for running Drupal sites uses Nginx, PHP-FPM and MariaDB. After reading a few posts about issues with Drupal 8 in this setup, I decided to quickly test it using Vagrant. I managed to get a development version of Drupal 8 up and running in approximately 30 mins in which I tried various things to get it working. Here are the steps that worked.

This is not a complete guide to hosting Drupal 8 on Nginx using PHP-FPM and there's a lot of tweaking needed, so here I just use default configurations wherever possible for simplicity. I plan to share more advanced configurations in a future post, like the configurations I'm using with Apiary.

First make sure you've got Vagrant installed, create a new folder, and initialize a new Vagrant box:

vagrant init precise32

Edit the Vagrantfile to add a port map for port 80, so your Vagrantfile looks like this:

Vagrant.configure("2") do |config|
  config.vm.box = "precise32"
  config.vm.network :forwarded_port, guest: 80, host: 4567

I then vagrant ssh into the box and do an apt-get update and apt-get upgrade. I then setup Aptitude sources to enable installation of MariaDB.

sudo apt-get install python-software-properties
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
sudo add-apt-repository 'deb http://mirror.stshosting.co.uk/mariadb/repo/5.5/ubuntu precise main'
sudo apt-get update

And then install all the required packages:

sudo apt-get install mariadb-server nginx-extras php5-fpm php-pear php5-cli php5-gd php5-curl php5-common php5-mysql php-apc php-console-table

This installs MariaDB, Nginx, PHP-FPM and some required PHP packages, and PHP console table that's required by Drush.

You could start the nginx service now with sudo service nginx start and you would see the "Welcome to nginx!" page if you go to http://localhost:4567/ in your browser.

In order to use Drush with Drupal 8 you need to install Drush version 6. This can be done by specifying the version explicitly when installing with pear:

sudo pear channel-discover pear.drush.org
sudo pear install drush/drush-6.0.0

I downloaded Drupal to the /vagrant folder using Drush. I then later found issues with file permissions over the folder shared with the host machine from within Vagrant so I symlinked the sites folder to /home/vagrant and changed the owner to www-data. I also found issues running Drush as the vagrant user, so I use sudo to run it as if it was www-data.

drush dl --select --all drupal-8

With that command you can then select to download either the Drupal 8 dev version, or the latest alpha (at time of writing alpha2).

I then create a database for Drupal to use by using the Mysql client

mysql -uroot -p

And entering these SQL commands:

GRANT ALL PRIVILEGES ON drupal8.* TO [email protected] IDENTIFIED BY 'password';

Then change directory into the Drupal folder and run the Drush site installer as www-data user:

sudo -u www-data drush si --db-url=mysql://drupal:[email protected]/drupal8

In this test I'm just using the default configurations. So start PHP-FPM and it will be available on

sudo service php5-fpm start

I remove the default nginx site:

sudo unlink /etc/nginx/sites-enabled/default

And then create a new configuration using the values from the Nginx wiki. This is not the production nginx configuration I am using, as I use Puppet modules that I created based on Perusio's nginx configuration, but for this test I just wanted the basics. Copy this code into /etc/nginx/sites-available/drupal8 and then create a symlink to enable the site:

sudo ln -s /etc/nginx/sites-available/drupal8 /etc/nginx/sites-enabled/drupal8

NB: You need to update the PHP socket information based on the default configuration provided by PHP-FPM otherwise you will get Gateway errors when you try to access the site. By default the nginx configuration above is using a unix socket, so change this to as specified in the default pool configuration for PHP-FPM.

Now start (or restart) nginx to see the site working in the browser:

sudo service nginx restart