How to Install Drupal on Ubuntu
Drupal is an enterprise-grade, open-source content management framework known for its powerful taxonomy system, granular user permissions, and extensibility. It is widely used for government websites, universities, and large-scale media platforms. This guide covers installing Drupal on a Breeze instance running Ubuntu.
Prerequisites
- A Breeze instance with Ubuntu 22.04 or later
- A LAMP or LEMP stack installed
- Composer installed globally
- PHP 8.2 or later with required extensions
Step 1 — Install PHP Extensions
Drupal requires specific PHP extensions. Install them:
sudo apt update
sudo apt install -y php-gd php-xml php-mbstring php-curl php-zip php-mysql php-opcache php-apcu
Verify your PHP version meets the minimum requirement:
php -v
Step 2 — Create the Database
Create a dedicated MySQL database for Drupal:
sudo mysql -u root -p
CREATE DATABASE drupal_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'drupal_user'@'localhost' IDENTIFIED BY 'strong_password_here';
GRANT ALL PRIVILEGES ON drupal_db.* TO 'drupal_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Step 3 — Install Drupal via Composer
The recommended way to install Drupal is through Composer, which handles dependencies automatically:
cd /var/www
sudo composer create-project drupal/recommended-project drupal
sudo chown -R www-data:www-data /var/www/drupal
sudo chmod -R 755 /var/www/drupal
Step 4 — Configure Apache
Create a virtual host for Drupal:
sudo nano /etc/apache2/sites-available/drupal.conf
<VirtualHost *:80>
ServerName yourdomain.com
DocumentRoot /var/www/drupal/web
<Directory /var/www/drupal/web>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/drupal_error.log
CustomLog ${APACHE_LOG_DIR}/drupal_access.log combined
</VirtualHost>
sudo a2ensite drupal.conf
sudo a2enmod rewrite
sudo systemctl reload apache2
Step 5 — Prepare the Settings File
Copy the default settings file and set up the files directory:
cd /var/www/drupal/web
cp sites/default/default.settings.php sites/default/settings.php
mkdir -p sites/default/files
sudo chown -R www-data:www-data sites/default/files
sudo chmod 666 sites/default/settings.php
Step 6 — Complete the Web Installation
Navigate to http://yourdomain.com in your browser. The Drupal installer will walk you through selecting an installation profile, entering database credentials, and configuring your site. After installation, tighten the settings file permissions:
sudo chmod 444 /var/www/drupal/web/sites/default/settings.php
Post-Installation Tips
- Enable the BigPipe module for faster perceived page loads
- Configure cron to run Drupal maintenance tasks:
crontab -eand add0 * * * * cd /var/www/drupal && vendor/bin/drush cron - Install Drush for command-line site management:
composer require drush/drush - Secure your site with an SSL certificate via Certbot