1. Home
  2. Linux
  3. Install drupal on ubuntu server

How To Install Drupal On Ubuntu Server

A great way to build a website is to use a content management system. One of the best CMS tools to use, especially on Linux servers is Drupal. It’s an advanced site tool with dozens of features that lets users quickly build a website easily, on their own terms. Here’s how to install Drupal on Ubuntu server.

Prerequisites

Before you deploy Drupal on your Ubuntu server, it’s a good idea to use the update tool to refresh everything. This will make sure that all software running on it is up to date.

sudo apt update

sudo apt upgrade -y

Following that, you’ll also need to install dependencies. These are critical for the Drupal CMS software to function correctly.

sudo apt-get install php php-mysql php-gd php-curl php-ssh2

In addition to these dependencies, be sure that you’ve already got a LAMP (or LEMP if you use Nginx) stack installed on Ubuntu. If not, quickly install everything needed to run web applications on Ubuntu server with:

sudo apt install lamp-server^

During the LAMP installation, you’ll be prompted to set up a root password for MySQL. Be sure to choose something secure so that it won’t be compromised. In addition, be sure that this password is different from the root user of the server. Using the same root password for your Ubuntu Linux root user and the SQL database is a dangerous thing to do and will lead to very, very bad things.

After installing everything, you’ll need to start Apache manually:

sudo service apache2 start

Install Drupal

The dependencies are satisfied, and all the necessary web applications are installed and working properly. The next step is to download the latest version of Drupal to the server. Go to the drupal.org website, and grab the tar.gz version. To make downloading directly to the server easier, right-click on the download button, click “copy link location”, and go to the terminal.

Then, use wget to download the tool over SSH to your server. Don’t use SSH? Consider downloading the tar.gz to a flash drive, and then plug it in.

wget -P /tmp/ https://ftp.drupal.org/files/projects/drupal-8.4.4.tar.gz

Drupal is downloaded, now it’s time to install it to the root web server directory.

tar xzvf /tmp/drupal-8.4.4.tar.gz -C /var/www/html/ --strip-components=1

Next, update the permissions of the HTML directory.

chown www-data:www-data -R /var/www/html/
chmod -R 755 /var/www/html/

Setting Up The Drupal Database

Drupal needs a database to interact with before the server software itself will load correctly. To create a new database, use this command and log in to the system using the root password set up for SQL earlier.

mysql -u root -p

Now that you’re logged in, it’s time to start interacting with the database software. Start out by making the database itself:

create database drupal;

Next, create a new user for the database that the Drupal CMS software can use. Be sure to change the “securepassword” area with a new password.

Note: DO NOT use the same password for this user as the one you’ve set up for the root SQL user. Instead, go generate a unique, secure one.

Keep in mind that the username Drupal will use is: drupalsite.

grant all privileges on drupal.* to drupalsite@localhost identified by 'securepassword';

When done, flush the SQL database privileges, and log out.

flush privileges;

exit

Configuring Drupal

Drupal has several configuration changes and tweaks that need to be made before the Drupal CMS software will start working correctly. The first bit of tweaks has to do with the Apache web server.

First, enable the rewrite module so that Drupal can change things at will.

sudo a2enmod rewrite

Then, create a new empty Drupal configuration file to use in the “sites-available” folder.

sudo touch /etc/apache2/sites-available/drupal.conf

Make a symlink and link the new config file created in the “sites-available” folder and link it to the “sites-enabled” folder. Doing this will make it so that the Apache2 web server enables the Drupal CMS software.

sudo ln -s /etc/apache2/sites-available/drupal.conf /etc/apache2/sites-enabled/drupal.conf

Lastly, use the nano text editor tool to set everything up.

sudo nano /etc/apache2/sites-available/drupal.conf

In drupal.conf, paste the following code:

<VirtualHost *:80>
ServerAdmin admin@domain.com
DocumentRoot /var/www/html/
ServerName domain.com
ServerAlias www.domain.com
<Directory /var/www/html/>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/domain.com-error_log
CustomLog /var/log/apache2/domain.com-access_log common
</VirtualHost>

Save the file with Ctrl + O and exit with Ctrl + X.

Lastly, restart the Apache web server to reflect the changes.

sudo service apache2 restart

Using Drupal

Drupal is all set up, and ready to use. The next step is to go through and run the Drupal Installation script. The software will walk you through creating an account, and get everything running correctly.

When Drupal is fully set up, you’ll be able to create your new website!