Installing Drupal 8 on Ubuntu 13.04 with Nginx

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;
                # 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:

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: Load up the site according to your network and LXC install. If we have PHP working then we can proceed with installing Drupal.

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:

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:

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?

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.

Further Reading and Final Thoughts

In my research for this blog I came across this but didn’t try it:  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.

2017-03-31T06:19:59+00:00 Categories: Drupal 8, How-To|Tags: |

About the Author:

David Numan joined CivicActions as an Engineer in 2011. He works both internally and with clients on the functional side of technology, creating solutions that empower people to reach their goals.

At CivicActions, David divides his time between tech support, back end systems work, and engineering on client projects. He recently completed the planning, coordination, and technical setup of a Drush-GitLab integration for CivicActions’ hosting system. His work in this area provides our entire engineering team with improved web access to code for awareness, review and discussion, as well as tools for managing project-specific documentation. David led the Drupal 6 to 7 migration for ReThink Media and has worked on projects for Democracy Now, Save the Children, Sedona Conference, Open Petition, BBRF, Marin Clean Energy, Netpop, and the Pew Charitable Trust, among others.

Prior to joining CivicActions, David spent 12 years as an independent web developer and consultant in both nonprofit and corporate sectors. During that time he created membership databases, conference registration systems, discussion forums, and web sites for clients that include The Royal Conservatory of Music, Canadian Charitable Annuity Association, and Hill Street Community Garden.

David has a BA in Business and is a PHP Certified Engineer. When he gets off the computer, he roasts fair trade coffee, makes yogurt, builds furniture using traditional woodworking techniques, and secretly enjoys watching classic Star Trek episodes.