DEV Community

Full Stack Hacker
Full Stack Hacker

Posted on • Edited on

2 1

Install Drupal on Ubuntu with LAMP Stack

Prerequisites

Step 1 — Creating a MySQL Database and User for Drupal

To get started, log into the MySQL root (administrative) account by issuing the following command: sudo mysql -u root -p To create a database, database user, and grant all privileges to the database user run the following commands:

mysql> CREATE DATABASE drupal DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
mysql> CREATE USER 'drupaluser'@'%' IDENTIFIED WITH mysql_native_password BY 'your_password';
mysql> GRANT ALL ON drupal.* TO 'drupaluser'@'%';
mysql> FLUSH PRIVILEGES;
mysql> \q

Step 2 - Install PHP and PHP extensions for Drupal

sudo apt update
sudo apt install php libapache2-mod-php php-dev php-bcmath php-intl php-soap php-zip php-curl php-mbstring php-mysql php-gd php-xml

Step 3 - Download Drupal

We will now download Drupal from the Drupal Official site. Use the following command to download Drupal:

sudo wget https://ftp.drupal.org/files/projects/drupal-9.4.4.zip

Extract file into the folder /var/www/html/ with the following command:

sudo apt -y install unzip
sudo unzip drupal-9.4.4.zip -d /var/www/html/

To make things simpler, rename the extracted directory drupal-9.4.4 to just drupal:

sudo mv /var/www/html/drupal-9.4.4/ /var/www/html/drupal/

Enable permission for the Apache webserver user to access the files:

sudo chown -R www-data:www-data /var/www/html/drupal/

Step 4 - Configure Apache Web Server for Drupal

Navigate to /etc/apache2/sites-available directory and run the following command to create a configuration file for your installation:

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

Add the following content:

<VirtualHost *:80>

ServerAdmin webmaster@your-domain.com

ServerName your-domain.com
ServerAlias www.your-domain.com
DocumentRoot /var/www/html/drupal

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

ErrorLog ${APACHE_LOG_DIR}/your-domain.com_error.log
CustomLog ${APACHE_LOG_DIR}/your-domain.com_access.log combined

</VirtualHost>

Save the file and Exit.

Enable the Drupal virtual host: sudo a2ensite drupal.conf

Restart the Apache web server: sudo systemctl restart apache2

Step 5 - Access Drupal Web Installer

Open your browser type your domain e.g http://your-domain.com and complete the required steps to finish the installation. Choose your preferred language and hit Save and continue, you will get the following screen:

Choose Standard and hit Save and continue. Error appear:

To fix this error:

  • First confirm that you have directory /var/www/html/drupal/sites/default/files. If doesn't exist you should create it by doing:
sudo mkdir /var/www/html/drupal/sites/default/files
sudo chmod -R 777  /var/www/html/drupal/sites/default/files
  • Secondly copy settings template to another file by doing:
cp /var/www/html/drupal/sites/default/default.settings.php /var/www/html/drupal/sites/default/settings.php 
sudo chmod -R 777  /var/www/html/drupal/sites/default/settings.php

Enter DB, User, password as created below: Fill in your database settings and hit Save and continue. Fill in some basic information about your site and then hit Save and continue. You will get the dashboard in the following screen: Installation of Drupal has been completed. Now revert the permissions for the settings.php file:

sudo chmod 644 /var/www/html/drupal/sites/default/settings.php

When configuring the drupal system, I get an error: "Page Not Found" Errors on every page except homepage To fix this error:

  • Run sudo a2enmod rewrite to enabling "rewrite" module
  • In /etc/apache2/apache2.conf and look at the block <Directory /var/www/> changed from AllowOverride None to AllowOverride All
  • Run sudo service apache2 restart

All pages are working properly

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more