A few introductory words
I started playing with Drupal 8 about a year ago. At that time installing it on a local computer was the only option as none of hosting providers that I tried had a server compatible with Drupal 8. It was fun to try new Drupal 8 features, but the inability to launch a demo website and test drive it in action pushed me away.
In this article I will explain how you can deploy a Drupal 8 website on DigitalOcean servers and get it running on PHP7. By the way, if you have thoughts on using their services too, you may sign up with this link and get free $10.00 in credit!
Creating a DigitalOcean droplet
In order to host your website on DigitalOcean servers you create a "droplet" (consider it a virtual server) and link it to your domain.
First, in the control panel of your domain registrar configure the following DigitalOcean nameservers to be used for your domain:
Here is a screenshot with an example configuration for the namecheap domain registrar (they offer, well, cheap domain names :-):
It can take up to 48 hours for those updates to propagate throughout the Internet (but usually it takes a couple of hours only). Although you won't be able to access your site at this domain till then, we can continue configuring our DigitalOcean droplet.
Sign into your DigitalOcean account and press the green "Create droplet" button at top right. On the new page switch to the "One-click Apps" tab and choose the following settings:
- Drupal 8.0.5 on 14.04 (this will deploy Drupal 8.0.5 and Ubuntu 14.04 when the droplet has been create)
- "Choose a size" - for a started Drupal 8 website the first option is enough ($5/month)
- "Choose a datacenter region" - this is the region where you want your server to be located
- "Select additional options" - you may skip these paid options
- "Add your SSH keys" - press "New SSH key", paste your SSH key (that you will use to access the server) and give it a name. You can follow these instructions to generate such a key: for Linux and Mac OS X users / for Windows users. My computer is a Windows one, but I use Git BASH that emulates the Linux console, so I followed the instructions for Linux users.
- "How many Droplets?" - 1 Droplet
- "Choose a hostname" - put your domain name there (without the www)
An example droplet configuration:
Press the "Create" button and wait till DigitalOcean create a droplet for you.
For every droplet that you create DigitalOcean assign an IP address that you can view on the page with the list of droplets:
Now you can check if the droplet is created successfully - open the droplet's IP address in your browser and see a "fresh" Drupal 8 website installed there.
To access the droplet via SSH you should use the "root" login. Also, if you SSH client doesn't use the SSH key automatically, you should specify it manually (the one that you specified when created the droplet). If you use Git BASH you can access the server as follows: ssh firstname.lastname@example.org
On the first access via SSH a notice with the Drupal 8 administator's password will appear:
You can configure a short alias for the droplet's IP address. On a Windows computer you should edit the C:\Windows\System32\drivers\etc file and add a line with your droplet's IP and the short alias (for instance, "do"). Having this you can access the server with "ssh root@do".
Now you should complete linking the droplet with your domain name. Open the "Domains" page in the "Networking" section, enter the domain name and choose your droplet:
Then configure DNS records for the domain as follows:
- A: mail -> droplet's IP address
- A: @ -> droplet's IP address
- CNAME: www -> domain name (with a dot on the tail)
- MX: 1 -> domain name with the "mail" prefix (and a dot on the tail)
- NS: keep the three default records created by DigitalOcean
Here is an example configuration:
This should be enough to get your droplet available at your domain name (after all changes have propagated throughout the Internet).
Upgrading to PHP7
By default DigitalOcean install PHP5, but Drupal 8 is hungry for resources, so it makes sense to upgrade the droplet to PHP7.
Access the droplet via SSH and run the following console commands:
- Add the repository with PHP7-related packets:
sudo add-apt-repository ppa:ondrej/php
- Updates the database with information on packet versions:
sudo apt-get update
- Install PHP7 and other required packets:
sudo apt-get install php7.0-fpm
sudo apt-get install php7.0-mysql
sudo apt-get install php7.0-xml
sudo apt-get install php7.0-cli
sudo apt-get install php7.0-opcache
sudo apt-get install php7.0-mbstring
sudo apt-get install php7.0-gd
sudo apt-get install php7.0
- Edit /etc/nginx/sites-enabled/drupal and replace the line that looks like "fastcgi_pass unix:/var/run/php5-fpm.sock;" with "fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;" (attention: check the extra "php"):
sudo vim /etc/nginx/sites-enabled/drupal
- Restart nginx:
sudo service nginx restart
- Open the "Reports" -> "Status report" page in your Drupal 8 and check that now it uses PHP7. If you see a server error, it may be that Drupal 8 requires some packet that you didn't install on the 3rd step. Check the /var/log/nginx/error.log file - it can give you a clue what packet is missing. Install the packet with the "sudo apt-get install php7.0-packet-name" console command.