Back to top

Install Drupal 8 on Ubuntu 14.04 LTS

Drupal 8 on Ubuntu 14.04 LTS with PHP 7.1

Ubuntu 14.04 LTS was released in April 2014, and its end of life date is April of 2019. To all those who are still using it this gives you roughly 8 months during which an upgrade is to be performed.

In case you want to install Drupal 8 before you get around upgrading the OS you'll have to update some packages because Ubuntu 14.04 doesn't satisfy all the requirements.

Recommended: Min PHP 7.1 for Drupal 8

Although Drupal 8 PHP requirements state that version 5.5.9+ is supported, it isn't recommended.

PHP version Supported Recommended?
5.5 5.5.9+  No
5.6 Yes  No
7.0 Yes  No
7.1 Yes  Yes
7.2 Yes as of Drupal 8.5.0*  Yes

You probably won't get far with the default PHP installation on Ubuntu 14.04 when it comes to Drupal 8. There will be things that won't work properly and it will be difficult to figure out why.

The good news is that it's possible to update the PHP to a newer version and have everything working without problems. With PHP 7 you also get the additional benefits of performance improvements, error handling, and other new features.

Update PHP to 7.1 on Ubuntu 14.04

Here are the steps how to update the PHP to 7.1 on Ubuntu 14.04 so your websites will work without issues:

  1. # Add the repository
  2. sudo add-apt-repository ppa:ondrej/php
  3. # Update your repos list
  4. sudo apt-get update
  5. # Install all the necessary packages 
  6. sudo apt-get install libapache2-mod-php7.1 php7.1-cli php7.1-common php7.1-json php7.1-opcache libssl1.0.2 php7.1-readline php-common php7.1-xml php7.1-mbstring php7.1-mysql php7.1-gd php7.1-curl
  7. # Disable the existing php5 modules 
  8. sudo a2dismod php5
  9. # Enable php7.1 module
  10. sudo a2enmod php7.1
  11. # Restart Apache
  12. sudo service apache2 restart

You can now proceed to install Drupal 8 through the usual composer dependencies manager.

Install Drupal 8 through composer

If you have already created the database for your new site and if you have composer already installed you can install Drupal 8 into d8 folder with these commands:

  1. cd /var/www/html
  2. composer create-project drupal-composer/drupal-project:8.x-dev d8 --stability dev --no-interaction
  3. cd d8
  4. # Some special characters like & and # in your password can be problematic! 
  5. ../vendor/bin/drush site-install --db-url=mysql://{username}:{password}@localhost/{database}

Add Trusted hosts to settings.php

  1. $settings['trusted_host_patterns'] = array(
  2.   '^d8\.local$',
  3.   '^www\.d8\.local$',
  4.   '^localhost$',
  5. );

Check folder permissions

Make sure your web/sites/default/files folder and it's subfolders are owned by the server user:

  1. cd /var/www/html/d8/web/sites/default/
  2. sudo chown -R www-data:www-data files/

If the web/sites/default/files/styles/ folder doesn't have appropriate permissions you may see a problem where you can upload images, but they won't display.

Start tracking your project

  1. cd /var/www/html
  2. git init 
  3. # Adjust more files to ignore
  4. nano .gitignore 
  5. git add . 
  6. git commit -m "Drupal 8 init" 

Install modules through composer, enable them with Drush

To install modules through composer:

  1. # --dev for modules that aren't used on production sites
  2. composer require --dev drupal/devel
  3. # Commit composer.json and composer.lock anytime they change
  4. git add .
  5. git commit -m "Devel module added for dev environments" 
  6. cd d8
  7. ../vendor/bin/drush en devel
Need any help with this? Or with any other Drupal problem? Contact me for a friendly chat, share about your project and see how I can help you solve any issues you might have.
What did you think of this article?