Drupal is one of the most widely used open-source CMS platforms in the world. Written in PHP, it powers everything from personal blogs to large government and enterprise sites. Its strength comes from flexible content types, a granular permissions system, and thousands of contributed modules that extend it in almost any direction.
This guide shows you how to install Drupal on Ubuntu 18.04 using Composer and the official drupal-project template, with Nginx, PHP 7.2, and MySQL.
Prerequisites:
Update your system packages before starting:
bashsudo apt update && sudo apt upgrade
Set up the MySQL database. Log into MySQL and create a dedicated database and user:
bashmysql -u root -p
sqlCREATE DATABASE drupal CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES ON drupal.* TO 'drupaluser'@'localhost' IDENTIFIED BY 'change-with-strong-password';
Replace the password with a strong one. The GRANT statement gives the user only the permissions Drupal needs and nothing more.
Install PHP 7.2 with all the modules Drupal requires:
bashsudo apt install php7.2-cli php7.2-fpm php7.2-mysql php7.2-json php7.2-opcache php7.2-mbstring php7.2-xml php7.2-gd php7.2-curl
PHP-FPM starts automatically after installation. Confirm it is running with systemctl status php7.2-fpm.
Install Composer globally to manage Drupal’s PHP dependencies:
bashcurl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
Verify with composer --version before continuing.
Create a new Drupal project using the official Composer template:
bashsudo composer create-project drupal-composer/drupal-project:8.x-dev /var/www/my_drupal --stability dev --no-interaction
This downloads Drupal and all required PHP packages. The process may take a few minutes.
Install Drupal using Drush, passing in the database credentials you created earlier:
bashcd /var/www/my_drupalsudo vendor/bin/drush site-install --db-url=mysql://drupaluser:change-with-strong-password@localhost/drupal
When the installer finishes, Drush prints the admin username and a generated password. Note these down before closing the terminal.
Set file ownership so Nginx and PHP-FPM can read and write site files:
bashsudo chown -R www-data: /var/www/my_drupal
Create an Nginx server block at /etc/nginx/sites-available/example.com. The config requires three server blocks: one to redirect HTTP to HTTPS, one to redirect www to the non-www domain, and a main block with its root set to /var/www/my_drupal/web. The main block passes PHP requests to the PHP-FPM socket at unix:/run/php/php7.2-fpm.sock and blocks access to vendor PHP files, private directories, and hidden dot files. Use the official Drupal Nginx recipe for the complete config and replace example.com with your domain and your actual SSL certificate paths.
Enable the site, test the configuration, and restart Nginx:
bashsudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/sudo nginx -tsudo systemctl restart nginx
Open your domain in a browser. The Drupal welcome screen confirms the installation worked.
Modules and themes are managed through Composer. To add a module, navigate to the project directory and run:
bashcd /var/www/my_drupalsudo -u www-data composer require drupal/pathauto
Composer installs the module and resolves all of its dependencies automatically.
Before updating Drupal core, always back up your files and database first:
bashsudo rsync -a /var/www/my_drupal/ /var/www/my_drupal_$(date +%F)mysqldump -u root -p drupal > /var/www/my_drupal_database_$(date +%F).sql
Then run the core update:
bashsudo -u www-data composer update drupal/core webflo/drupal-core-require-dev symfony/* --with-dependencies
The --with-dependencies flag updates all related packages at the same time, preventing version conflicts between Drupal core and its dependencies.
Drupal 8 is now installed on your Ubuntu 18.04 server. Visit the Drupal User Guide to learn how to manage content, configure settings, and build your site. Leave a comment below if you run into any issues.
FTP (File Transfer Protocol) is a standard network protocol for transferring files between a local client…
A Python virtual environment is a self-contained directory that holds an isolated Python installation and its own…
Slack is one of the most popular collaboration platforms in the world. Teams use it to…
The hostname is the label that identifies a machine on a network. It appears in your terminal…
Redis is an open-source, in-memory data structure store used as a database, cache, and message broker.…
Ubuntu 18.04 LTS (Bionic Beaver) was released on April 26, 2018, with five years of official…