Does Drupal 8 love the latest Ubuntu, Raring Ringtail? Let's find out. You'll need an install of Ubuntu 13.04 and if you already have a previous version, try LXC for a quick set up. If you're not on Ubuntu, this should work just as well with other Virtualization methods such as VirtualBox. Or take the plunge and install Ubuntu 13.04 as your main OS. Raring Ringtail is set to be released this Thursday (April 25). Totally ready now to try out Nginx and Drupal.

So let’s log in to our fresh Ubuntu and get started. Quick tip: I recommend a strong password generator for things like Mysql root password and the drupal admin password. This is optional, but here's the commands to install and use the pwqgen command, which produces strong passwords such as "Attack_usable2Screw".

# sudo apt-get install passwdqc
# pwqgen

Install Nginx, Mysql, and PHP5-fpm

This command installs our "LEMP" stack to support Drupal:

# sudo apt-get install  nginx mysql-server php5-common php5-cli php5-fpm php5-mysql php5-gd php5-curl git drush

The last two, git and drush, are optional but I highly recommend them. The Mysql install will prompt for a root password. This is where pwqgen is helpful.

Nginx with PHP5-fpm

To check if PHP is working on Nginx I edited the configuration file /etc/nginx/sites-available/default and uncomment lines these lines:

        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                # With php5-cgi alone:
                # fastcgi_pass 127.0.0.1:9000;
                # fastcgi_pass unix:/var/run/php5-fpm.sock;
                # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }

Now add a one-liner phpinfo.php file to the root dir /usr/share/nginx/html to show PHP info:

<?php phpinfo(); ?>

Restart Nginx and check if it works:

# sudo service php5-fpm restart && sudo service nginx restart

I setup my container on a private IP so I can load the page here: http://10.0.1.20/phpinfo.php Load up the site according to your network and LXC install. If we have PHP working then we can proceed with installing Drupal.

phpinfo

Drop in a vhost

I haven’t used Nginx before and I’m thinking of setting up some Drupal 7 test sites on this container anyway so before attempting 8, I chose to get 7 working. Nginx has documentation on Drupal configuration here: http://wiki.nginx.org/Drupal

Create a new file in /etc/nginx/sites-available/ with any name. Filenames based on the domain name is a good convention. Copy the config from the Nginx Drupal guide into that file and edit the server_name and root variables. Feel free to take a look at my config as an example.

The php config from the Drupal Nginx wiki page didn’t work for me. But we just had php working above in the previous section so I replaced the location ~ \.php$ block with the one from the default file and I'm good to go.

Now create a mysql database for the new site and grant permissions. Instructions for this can be found here: http://api.drupal.org/api/drupal/INSTALL.mysql.txt/7

Go to your site root, download latest stable Drupal.

drush dl drupal

Does it work? Load up your new vhost with the address or sitename you configured. If you’re doing this on a local network and using a private domain name as I am don’t forget to add it to your /etc/hosts file. Also, if you remove /etc/nginx/sites-enabled/default then the new single vhost config acts as the default.

If all is not well, possibly because I forgot to mention an important step somewhere, check the error logs. I run this in the command then load the page if i’m having trouble:

sudo tail -f /var/log/nginx/error.log

Google the error, fix the problem, then tweet me to let me know what I missed. :)

Eight is great

With Drupal 7 working I was eager to see how 8 would go. I used the same Nginx configuration and tried it out. I did trip on a missing curl library (which I added to the "apt-get install" command above) but after that it installed just fine. Is it me, or does Nginx feel much faster than Apache?

Drupal 8 on Nginx

One missing piece that I’ve found so far: Upload progress. "Your server is not capable of displaying file upload progress. File upload progress requires an Apache server running PHP with mod_php." I’ll see about getting that working another day.

No Upload Progress

Further Reading and Final Thoughts

In my research for this blog I came across this but didn’t try it: https://github.com/perusio/drupal-with-nginx#nginx-configuration-for-running-drupal  Looks like a very complete Drupal config for Nginx and worth looking into if you're setting this up on a production server.

Almost as fun as time travel and alternate universes, LXC provides a quick way to work with multiple server stacks and safely test pre-release distributions of Linux and Drupal. I definitely see Nginx in my future.

David Numan is a Tech Lead at CivicActions. He focuses on the functional side of technology, creating solutions that empower people to reach their goals. Dave is a PHP Certified Engineer, woodworker and long time Star Trek fan. LLAP.