Installing Drupal 8.2 on Arch Linux

For years the LAMP stack (Linux, Apache, MySQL, PHP.) has been the industry standard toolset to build websites. The tech giants like Google and Facebook had (Or have,) some services running using similar tools.

In this post I’m going to talk about the experience of installing and configuring the LAMP and Drupal.

I’m going to be using Arch Linux, for no particular reason other than it’s my current distro. Because of how closely Arch tries to follow upstream many of the steps described might be different from other distros such as Debian. Antegros and other Arch derivatives should be similar however.

I will be using Apache version 2.4.23–1, the latest available on the Arch repos as of this post.
I will be using MariaDB which is an open-source fork of the Oracle owned MySQL.
Finally I will use PHP 7.0.13–2, again the latest available on Arch.

Installing the packages

We need to install the following packages, using pacman or any other package manager:

  • PHP
  • Apache
  • PHP-Apache
  • MySQL (Will prompt for implementation.)
  • Drupal

As an alternative to installing Drupal via a package manager I’ll show how to do it manually later in the post.

Configuring Apache

First we need to enable the module that lets Apache work with PHP and our chosen database. To do this open the Apache configuration located at:

/etc/httpd/conf/httpd.conf

And comment the line:

#LoadModule mpm_event_module modules/mod_mpm_event.so

And uncomment the lines:

LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
LoadModule rewrite_module modules/mod_rewrite.so

Then look for the line:

LoadModule dir_module modules/mod_dir.so

And after it add:

LoadModule php7_module modules/libphp7.so
AddHandler php7-script php

Then after the list of 'Include' add:

Include conf/extra/php7_module.conf

Now copy the example Apache configuration (Unless doing a manual Drupal installation):

cp /etc/webapps/drupal/apache.example.conf /etc/httpd/conf/extra/drupal.conf

And Include it at the bottom of httpd.conf

Include conf/extra/drupal.conf

Configuring PHP

This is a rather simple step, all we have to do is uncomment the extension for the database we want to use. In this case, MariaDB, open the file:

/etc/php/php.ini
And uncomment the line:
extension=pdo_mysql.so

Configuring MariaDB

First initialise the database using:

mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

Now connect to the database:

mysql -u root -p

Next let’s create a database:

CREATE DATABASE databasename CHARACTER SET utf8 COLLATE utf8_general_ci

Then add a user and grant it permissions on the database:

CREATE USER 'drupal'@'localhost' IDENTIFIED BY 'some_pass';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES ON databasename.* TO 'drupal'@'localhost';
FLUSH PRIVILEGES;
\q

Manually installing Drupal

Usually this would be done via pacman, but if for some reason you want to install Drupal manually, perhaps installing an older version, here is how to do it.

First download the version of Drupal you want to install from:

https://www.drupal.org/files/projects/drupal-$pkgver.tar.gz

Where $pkgvar is the version of Drupal you want.
Then extract the archive using tar or equivalent:

tar -xf drupal-8.2.3.tar.gz
cd drupal-8.2.3

Move the sites folder:

mkdir /var/lib/drupal
mv sites /var/lib/drupal/sites

Move the .htaccess file:

mv .htaccess /etc/webapps/drupal/.htaccess

Then write the example configuration file:

        Alias /drupal "/usr/share/webapps/drupal"
<Directory "/usr/share/webapps/drupal">
AllowOverride All
Options FollowSymlinks
Require all granted
php_admin_value open_basedir "/srv/:/tmp/:/usr/share/webapps/:/etc/webapps:/usr/share/pear/:/var/lib/drupal"
</Directory>

To

/etc/httpd/conf/extra/drupal.conf

And include it in httpd.conf if you haven’t already:

Include conf/extra/drupal.conf

Finally change the ownership of Drupal’s install folder to the http group:

chown -R http:http /var/lib/drupal

Configuring Drupal

If you installed via a package manager edit:

/usr/share/webapps/drupal/.htaccess

And replace

Require all denied

with

Require all granted

Before we move on I should note that I won’t be covering any of the steps needed to secure these tools against the big bad web, this is only intended for a local install which will be exposed to, at most, a trusted LAN.

Now that we’ve finished configuring Apache, PHP and MariaDB we can restart Apache using:

systemctl restart httpd

Now we should be able to access drupal via http://localhost/drupal

From here it’s a simple matter of choosing localisation options and connecting to the database using the credentials you chose earlier.

If everything went well, you should now see the Drupal dashboard which looks something like this:

This post was written as an entry task for Google Code-In, a competition designed to get teenagers interested in programming and open-source.