How to Install Drupal 8 with Apache, MySQL and SSL on Ubuntu 15.10

Drupal is a open source content management system based on PHP and distributed under the GNU General Public License. Drupal is a scalable and open platform for web content management, it's community provides more than 31,000 modules to extend the core functions and Drupal is used by at least 2.1% of all website on the internet. At the end of 2015, the Drupal project has released the new major version Drupal 8 that I will cover in this tutorial.

In this tutorial, I will show you how to install Drupal 8 on Ubuntu 15.10 with Apache as web server, MySQL as database backend and how to secure the website with SSL.

Prerequisites

  • Ubuntu 15.10 - 64bit.
  • Root privileges.

Step 1 - Install Apache and PHP

I will install apache and PHP (and some PHP modules that are required by Drupal) with apt, the Ubuntu package installer. Then we will enable the apache modules mod_rewrite and mod_ssl.

Update the Ubuntu repository and install Apache:

sudo su
apt-get update
apt-get install apache2 -y

Then install PHP 5  and the PHP modules with the command below:

apt-get install -y php5 libapache2-mod-php5 php5-mysqlnd php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-apcu

Now enable the Apache SSL and rewrite modules with the 'a2enmod' command. Restart apache to apply configuration changes:

a2enmod rewrite ssl
systemctl restart apache2

Check that the modules are loaded with the command:

apache2ctl -M | egrep 'ssl|rewrite'

The output shall show the following lines:

#Enabled
 rewrite_module (shared)
 ssl_module (shared

So mod-rewrite and mod-ssl are loaded.

Now I will check that Apache and PHP are working well. Create a new file in the "/var/www/html/" directory. The file contains the phpinfo() command:

cd /var/www/html
echo "<?php phpinfo(); ?>" > info.php

visit the server IP: 192.168.1.100/info.php

phpinfo result.

The result should be similar to this screenshot.

Delete the info.php file:

rm -f /var/www/html/info.php

As a publicly accessible info.php file is a security risk.

Step 2 - Install and Configure the MySQL Database

In this step, we will install MySQL 5.6 and create a new database for Drupal. We will create a database with the name 'drupaldb', a new user 'drupaluser' with the password 'drupaluser@', and grant the user access to the database.

Install MySQL with command below:

apt-get install mysql-server mysql-client -y

The installation process will prompt for the MySQL password, choose a secure password.

Enter the MySQL password.

Now log into the MySQL database with the user "root" and the password that you have chosen above, then create the database and user for drupal.

You can use commands below:

mysql -u root -p

create database drupaldb;
create user [email protected] identified by 'drupaluser@';
grant all privileges on drupaldb.* to [email protected] identified by 'drupaluser@';
flush privileges;
exit

Create a MySQL database for Drupal.

The Database configuration is finished.

Step 3 - Install and Configure SSL

We will use SSL to enable secure access to Drupal. Create a new directory for ssl in the apache configuration directory, then create an SSL certificate with the OpenSSL command and change the permission of the certificate file.

Go to the apache directory, create a ssl directory and enter it:

cd /etc/apache2/
mkdir ssl
cd ssl/

Generate a self-signed SSL certificate:

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/drupalssl.key -out /etc/apache2/ssl/drupalssl.crt

Change the permission of the certificate file:

chmod 600 *

The new SSL certificate file is created.

Step 4 - Configure the Apache Virtualhost

In this step, we will create a directory for Drupal inside the /var/www directory and add a new virtual host configuration file for Drupal.

mkdir -p /var/www/drupal
cd /etc/apache2/sites-available

Now create a new file called 'drupal.conf' with vim that will contain the Apache virtual host configuration:

vim drupal.conf

Paste the virtual host configuration below:

        <VirtualHost *:80>
                ServerName www.mydrupal.co
                DocumentRoot /var/www/drupal

                # Redirect http to https
                RedirectMatch 301 (.*) https://www.mydrupal.co$1
        </VirtualHost>

        <VirtualHost _default_:443>

                # Server Info
                ServerName www.mydrupal.co
                ServerAlias mydrupal.co
                ServerAdmin [email protected]

                # Web root
                DocumentRoot /var/www/drupal

                # Log configuration
                ErrorLog ${APACHE_LOG_DIR}/drupal-error.log
                CustomLog ${APACHE_LOG_DIR}/drupal-access.log combined

                #   Enable/Disable SSL for this virtual host.
                SSLEngine on

                # Self signed SSL Certificate file
                SSLCertificateFile      /etc/apache2/ssl/drupalssl.crt
                SSLCertificateKeyFile /etc/apache2/ssl/drupalssl.key

                <Directory "/var/www/drupal">
                        Options FollowSymLinks
                        AllowOverride All
                        Require all granted
                </Directory>

                <FilesMatch "\.(cgi|shtml|phtml|php)$">
                                SSLOptions +StdEnvVars
                </FilesMatch>
                <Directory /usr/lib/cgi-bin>
                                SSLOptions +StdEnvVars
                </Directory>

                BrowserMatch "MSIE [2-6]" \
                                nokeepalive ssl-unclean-shutdown \
                                downgrade-1.0 force-response-1.0
                # MSIE 7 and newer should be able to use keepalive
                BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown

        </VirtualHost>

Replace the domain name www.mydrupal.co with the domain name of your Drupal website.

Save the file and exit.

Now test the apache configuration with command:

apachectl configtest

If you see "Syntax ok", then the apache configuration is correct.

Now activate the Drupal virtual host and restart the Apache:

a2ensite drupal
systemctl restart apache2

The virtual host is created and configured.

Step 5 - Install and Configure Drupal 8

We have to install git and drush before we will install Drupal. So let's install them with the following apt command:

apt-get install git drush -y

Now go to the Drupal directory and download the new Drupal 8 version with the 'drush command'.

cd /var/www/drupal
drush dl drupal-8

Move all Drupal files to "/var/www/drupal":

mv drupal-8.0.1/* .
rm -rf drupal-8.0.1/

Go to the directory 'sites/default' and copy the two configuration files 'settings.php' and 'services.yml':

cd sites/default
cp default.settings.php settings.php
cp default.services.yml services.yml

Then create a new directory 'files' and change the permission of all files and folders in 'sites/default' directory:

mkdir files/
chmod a+w *

Go to the '/var/www/' directory and change the owner of the drupal directory to the user and group 'www-data':

cd /var/www/
chown -R www-data:www-data drupal/

The shell part of the Drupal installation is finished, visit the drupal domain of your website "www.mydrupal.co" and you will be switch to https connection automatically.

Choose your language, I will use 'English' here.

Chose language in Drupal installer.

Select 'Standard' installation profile.

Chose Drupal installation profile.

When your server is ready for Drupal (as our server is when you used the installation steps above) then you will be passed to the 'Verify requirements' section and continue with the database configuration. Fill in the database details of the MySQL database that we created earlier:

Drupal database settings.

Click on "Save and continue" and wait until the installation process finished.

ow Configure the site, admin account, email, site name etc.

Drupal site configuration.

Drupal is installed and configured.

The Drupal installation is finished.

Conclusion

Drupal is a content management system based on PHP, it is used by at least 2.1% of all websites on the internet. Until now, Drupal has released version 8 and provides many add-on modules that make Drupal is really useful. We can install Drupal on any server that supports MySQL or MariaDB as database, a web server like Apache or Nginx and the PHP programming language. Drupal is easy to install and configure.

Share this page:

19 Comment(s)

Add comment

Comments

From: Rosendo Pablo

Thank you so much for this howto, I followed all the steps until I got to the step 4, where it asks to create the vim drupal.conf, I did the copy step but right on the bottom it says "Replace the domain name www.mydrupal.co with the domain name of your Drupal website", my machine is just going to be a local server using localhost or 127.0.1.1, I changed www.mydrupal.co with localhost but when I go to the web browser and type localhost/drupal8 it says "Not Found The requested URL /drupal8 was not found on this server" I have already downloaded likde it says in step 5 and I finished the steps there.

From: Mark Keppinger

I am experiencing problems with getting Drupal 8 installed and configured.  Initially I downloaded LAMP on a new Ubuntu 15.10 install that only had 'gparted' and 'xrdp' installed.  I followed instruction to install Drupal on an Ubuntu 14.04 Server that installed Drupal 7.32  but doing a 'wget' of Drupal 8.0.1 prior to Christmas and had no success and ran out of time.

I believe I cleaned up the LAMP items and then reinstalled using these instruction.  I am also using my private IP 192.168.0.159 and a hostname without a domain for configuring the Apache Virtualhost (Step 4).   In Step 5 "Install and Configure Drupal 8" ('drush' downloaded 8.0.2), it complained about the HTTPS.  But was able to perform the configure part using HTTP.  The last screen shot comes up.  But I am unable to do anything beyond this and it continues to complain about HTTPS.

The only noticeable error was in Step 1 with the "apache2ctl -M | egrep 'ssl|rewite'" which also complained about the hostname and that it would use the loopback IP 127.0.0.1.  I looked through the lengthy "<?php phpinfo();" output  and saw nothing obvious.  The Apache Environment had HTTP.HOST set to 192.168.0.195.

 

--Mark

From: Joseph Hillenburg

Just after I select the installation profile, I get an error about clean URLs.

Clean URLs Screenshot

I would suspect that this was not what is intended.

From: LocalhostDrupal8

I agree, the tutorial should include settings for clean urls on the server because that does not work unfortunately, which makes the installed Drupal8 almost unusable.

From: LocalhostDrupal8

I had an issue in the first step at line apache2ctl -M | egrep 'ssl|rewrite'. 

Error message: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message

The Ubuntu 15.10 version is fresh (18th February 2016) and it is a desktop 64 bit instance.

Fixing this problem is, however, quite easy. Apache wants you to define a ServerName. So let’s add it by first opening terminal and editing the httpd.conf file: sudo nano /etc/apache2/apache2.conf Go to the very bottom of that file and add this line: ServerName localhost

Thank you for the fix for the author of the following article:

https://thomas.vanhoutte.be/miniblog/fix-apache-error-ah00558/

From: Sam

After following this tutorial I got stuck at opening Drupal in the browser.  Like others here, I'm running this on a local server and am unable to navigate to the Drupal installation in the browser.  I've tried replacing "www.mydrupal.co" in the config file with various things such as the server's IP, localhost...  nothing works. 

 

Any update to this tutorial? Thanks.

From: David

Replace www.mydrupal.co with an arbitrary domain name (or keep as www.mydrupal.co) and then edit the hosts file on the client machine that you will be accessing Drupal from with an entry which redirects the arbitrary domain name to the server IP (I think localhost could even work), on my LAN this entry got it to work from my Mac laptop:

192.168.0.2    www.mydrupal.co

From: Bruc3

Alternatively you can also edit this file

/etc/apache2/sites-available/000-default.conf

remove:

DocumentRoot /var/www/html

and add instead, then you can access site in browser via ipaddress/drupal:

DocumentRoot /var/www

From: Prashanth

mv drupal-8.0.1/* . doesn't move the hidden files in the folder. To move everything, use mv drupal-8.0.1/{.,}* .

From: Alex F

Thank you for great tutorial!!!

 

For Drupal 8.0.5

================

I added some setting for Step 5:

 

1. Set password for drupaluser

SET PASSWORD FOR [email protected] = PASSWORD('xyz');

 

2. Install a php5-mysql module in order to select a MySQL database in the 'Database configuration' page.

sudo apt-get install php5-mysql

 

After this you need restart an apache.

sudo service apache2 restart

From: Alex F

I can access the home page (http://mydrupal.co), but when I clicked any further links (e.g. http://mydrupal.co/admin/structure),

it shows error:

"Not Found

 The requested URL /admin/structure was not found on this server."

 

This happened because an apache not found the .htaccess file in the /var/www/drupal directory. The mv command doesn't copy the hidden files (i.e. .htaccess file). You should copy .htaccess file before deleting the drupal-8.0.x directory.

 

Below a new sequence which doing this:

mv drupal-8.0.5/* .

cp drupal-8.0.5/.htaccess .htaccess

rm -rf drupal-8.0.5/

From: Scott Morgan

Yes, you are right, and there are other hidden files. So, the extra step should be:

mv drupal-8.*/* .

From: h_trism

This worked perfectly for me on Ubuntu 14.04, just wanted to add that you will also need to install postfix in order for the app to send emails.

From: Chewbacca

Took way too many tests because noone came back to give the solution to the clean urls problem.  This worked for me ...

Update this Directory section in /etc/apache2/apache2.conf to look like this:

 

  Options Indexes FollowSymLinks

  AllowOverride All

  Require all granted

 

  RewriteEngine on

    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteCond %{REQUEST_URI} !=/favicon.ico

    RewriteRule ^ index.php [L]

 

 

Be sure to restart apache:

# apachectl configtest

# systemctl restart apache2

 

From: Bruc3

Thanks so much for that 'chewbacca', it worked for me.

From: Subhash

Thank you for this tutorial. I followed the steps and successfully installed www.mysite1.com. But when I am trying to setup www.mysite2.com then mysite1 has stopped working and getting configuration from mysite2. Any idea why it is happening that site1 is getting configuration from site 2. Or is there something else I need to take care of for installation more than 1 sites in a single server?

Thanks in advance.

From: Manindra Gautam

 drush dl drupal-8 command not working

it gives error everytime

<pre>mkg drupal # drush dl drupal-8

PHP Fatal error:  Uncaught Error: Call to undefined function Drush\UpdateService\simplexml_load_file() in phar:///usr/bin/drush/lib/Drush/UpdateService/Project.php:74

Stack trace:

#0 phar:///usr/bin/drush/lib/Drush/UpdateService/ReleaseInfo.php(64): Drush\UpdateService\Project::getInstance(Array, 86400)

#1 phar:///usr/bin/drush/lib/Drush/UpdateService/ReleaseInfo.php(122): Drush\UpdateService\ReleaseInfo->get(Array)

#2 phar:///usr/bin/drush/commands/pm/download.pm.inc(111): Drush\UpdateService\ReleaseInfo->selectReleaseBasedOnStrategy(Array, '', 'auto', false, NULL)

#3 phar:///usr/bin/drush/includes/command.inc(373): drush_pm_download('drupal-8')

#4 phar:///usr/bin/drush/includes/command.inc(224): _drush_invoke_hooks(Array, Array)

#5 phar:///usr/bin/drush/includes/command.inc(192): drush_command('drupal-8')

#6 phar:///usr/bin/drush/lib/Drush/Boot/BaseBoot.php(67): drush_dispatch(Array)

#7 phar:///usr/bin/drush/includes/preflight.inc(66): Drush\Boot\BaseBoot->bootstrap_and_dispatch()

#8 phar:///usr/bin/drush/includes/startup.in in phar:///usr/bin/drush/lib/Drush/UpdateService/Project.php on line 74

Drush command terminated abnormally due to an unrecoverable error.      [error]

Error: Uncaught Error: Call to undefined function

Drush\UpdateService\simplexml_load_file() in

phar:///usr/bin/drush/lib/Drush/UpdateService/Project.php:74

Stack trace:

#0 phar:///usr/bin/drush/lib/Drush/UpdateService/ReleaseInfo.php(64):

Drush\UpdateService\Project::getInstance(Array, 86400)

#1 phar:///usr/bin/drush/lib/Drush/UpdateService/ReleaseInfo.php(122):

Drush\UpdateService\ReleaseInfo->get(Array)

#2 phar:///usr/bin/drush/commands/pm/download.pm.inc(111):

Drush\UpdateService\ReleaseInfo->selectReleaseBasedOnStrategy(Array, '',

'auto', false, NULL)

#3 phar:///usr/bin/drush/includes/command.inc(373):

drush_pm_download('drupal-8')

#4 phar:///usr/bin/drush/includes/command.inc(224):

_drush_invoke_hooks(Array, Array)

#5 phar:///usr/bin/drush/includes/command.inc(192):

drush_command('drupal-8')

#6 phar:///usr/bin/drush/lib/Drush/Boot/BaseBoot.php(67):

drush_dispatch(Array)

#7 phar:///usr/bin/drush/includes/preflight.inc(66):

Drush\Boot\BaseBoot->bootstrap_and_dispatch()

#8 phar:///usr/bin/drush/includes/startup.in in

phar:///usr/bin/drush/lib/Drush/UpdateService/Project.php, line 74

</pre>

From: Krakysis

Thank you Chewbacca !

From: Jake

This tutorial needs some revising. Drupal 8 is alive, active and being updated. Sadly, the documentation is still lagging behind. Ubuntu is on version 16.04.1 LTS and the standard in php now is version 7 (not 5).