UbuntuUbuntu Based

How To Install Drupal on Ubuntu 24.04 LTS

Install Drupal on Ubuntu 24.04

Drupal is a powerful content management system (CMS) used worldwide for websites of all sizes, including simple blogs, online communities, and complex enterprise applications. Its open-source nature, flexibility, and extensive community support make it a popular choice for developers and content creators. By installing Drupal on Ubuntu 24.04 LTS, you gain a stable, secure, and modern environment for building a robust web presence.

Introduction

Drupal is written primarily in PHP and leverages databases like MySQL or MariaDB for storing site content. Its modular architecture lets you install a broad range of community-contributed modules and themes. This adaptability is a reason many educational institutions, businesses, nonprofits, and government agencies rely on Drupal. With the release of Ubuntu 24.04 LTS, you benefit from a long-term support system that emphasizes security, stability, and performance—a perfect foundation for your Drupal website.

In this article, you’ll learn how to install and configure Drupal on Ubuntu 24.04 LTS step by step. We will walk through verifying prerequisites, installing the necessary packages, securing and configuring the database, downloading Drupal, adjusting permissions, and finalizing installation via the web interface.

Prerequisites

Before you start the Drupal installation process on Ubuntu 24.04, you need to ensure the following prerequisites are met. This will help you avoid common pitfalls and streamline the setup process.

1. Operating System and Access

You should have Ubuntu 24.04 LTS installed on your server or virtual machine. Ensure you have administrative (sudo) privileges to install software and configure services.

2. System Requirements

  • RAM: At least 1GB of RAM (for smaller sites). More memory is recommended for higher traffic or resource-intensive websites.
  • Disk Space: A minimum of 2GB of free space is advisable. Larger sites or those hosting a lot of media will need extra storage.
  • Processor: A modern 64-bit CPU capable of running Ubuntu 24.04 LTS efficiently.

3. LAMP Stack Overview

Drupal commonly runs on a LAMP stack, which includes:

  • Linux: Ubuntu 24.04 LTS
  • Apache: A reliable web server software
  • MySQL/MariaDB: A database server to store site data
  • PHP 8.3 or higher: The scripting language Drupal relies on

Preparing the System

To begin, you need to update your Ubuntu repositories and install all available upgrades. These steps ensure security patches are in place and packages are up to date.

1. Update and Upgrade

sudo apt update && sudo apt upgrade -y

This command updates the package lists and installs any upgrades. Depending on your system, you may be prompted to confirm certain changes. After completion, reboot if any kernel updates were installed:

sudo reboot

2. Install Apache Web Server

sudo apt install apache2 -y

After installation, enable and start Apache so it automatically runs after reboots:

sudo systemctl enable apache2
sudo systemctl start apache2

You can verify that Apache is active by visiting http://server-ip in a web browser. You should see the default Apache welcome page.

3. Install PHP 8.3 and Extensions

Drupal requires PHP along with some extensions to handle text, images, and database interactions properly. Install PHP 8.3 and the commonly needed extensions:

sudo apt install php8.3 php8.3-mysql php8.3-gd php8.3-xml php8.3-mbstring php8.3-curl php8.3-zip php8.3-json -y

You can confirm your PHP version:

php -v

Database Configuration

Next, set up MySQL or MariaDB for your Drupal installation. Both database servers are supported by Drupal. The commands below illustrate MariaDB installation and configuration.

1. Install MariaDB

sudo apt install mariadb-server -y

After installing, verify it’s running and enable it to start at boot:

sudo systemctl enable mariadb
sudo systemctl start mariadb

2. Secure MariaDB

MariaDB includes a script to harden defaults and remove unsafe settings:

sudo mysql_secure_installation

You’ll be prompted to set a root password, remove anonymous users, disable remote root login, and discard the test database. For a production environment, it’s recommended to answer “yes” to these prompts.

3. Create Drupal Database and User

Log in to the MySQL/MariaDB shell:

sudo mysql -u root -p

Enter your root password and create a database and user for Drupal:

CREATE DATABASE drupal_db CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'drupal_user'@'localhost' IDENTIFIED BY 'StrongPassword123!';
GRANT ALL PRIVILEGES ON drupal_db.* TO 'drupal_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Installing Drupal

With the system and database ready, the next step is to download and configure the Drupal source files. Ensuring proper ownership and permissions ensures seamless site operation and added security.

1. Download the Latest Drupal Release

Navigate to the web server’s document root. Often, it’s located at /var/www/:

cd /var/www/

Download the latest Drupal tar.gz or zip archive:

wget https://www.drupal.org/download-latest/tar.gz -O drupal.tar.gz

Extract the archive and rename the extracted folder to drupal:

tar -xvf drupal.tar.gz
mv drupal-* drupal

2. Configure Permissions

Ensure the Apache user (www-data on Ubuntu) has the right ownership:

sudo chown -R www-data:www-data /var/www/drupal
sudo chmod -R 755 /var/www/drupal

Proper permissions guarantee Drupal can manage files, create directories, and interact with its settings securely. Incorrect file permissions often lead to installation or module update failures.

3. Create an Apache Virtual Host

Although you can use the default Apache configuration, setting a dedicated virtual host is cleaner and easier to manage, especially if you plan to host multiple sites.

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

Include the following sample configuration, replacing example.com with your domain or IP address:

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /var/www/drupal

    <Directory /var/www/drupal>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/drupal_error.log
    CustomLog ${APACHE_LOG_DIR}/drupal_access.log combined
</VirtualHost>

Enable this site and the Apache rewrite module:

sudo a2ensite drupal.conf
sudo a2enmod rewrite
sudo systemctl reload apache2

Drupal Configuration

Once the files are in place and the virtual host is configured, you can finalize remaining setup steps via the web interface. Ensure you have your database name, username, and password handy.

1. Access the Installation Wizard

Open a browser and navigate to http://example.com or http://your_server_ip. You should see the Drupal language selection screen. Choose your preferred language and click “Save and continue.”

Install Drupal on Ubuntu 24.04 LTS

2. Select Installation Profile

Drupal offers profiles such as “Standard” (includes common modules) or “Minimal” (smaller feature set). If you’re new to Drupal or want to explore typical features, choose “Standard.” Click “Save and continue.”

3. Database Connection

Enter your database credentials:

  • Database name: drupal_db
  • Database username: drupal_user
  • Database password: StrongPassword123!

For “Advanced options,” you can specify localhost as the hostname for local databases. Click “Save and continue” to begin the installation cycle.

4. Configure Site Information

After the modules finish installing, you’ll be prompted to set up basic site configuration:

  • Site Name: Choose a descriptive name
  • Site Email Address: Used for administrative notifications
  • Username & Password: Administrator credentials
  • Default Country & Time Zone: Adjust per your local details

Click “Save and continue” to initialize your new Drupal site. When the install completes, you’ll see a success message and a link to access your site’s main dashboard.

Post-Installation Steps

Your Drupal site is now online, but there are additional measures to optimize security, usability, and site performance. Let’s explore important recommended actions.

1. Secure the settings.php File

It’s advisable to revert permissions on the settings.php file so unauthorized users cannot edit it:

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

2. Update Drupal Core and Modules

Frequent Drupal core and contributed module updates help protect your site from vulnerabilities. Access the administrator dashboard, click “Reports,” then “Available updates” to check for updates. Alternatively, use the command line with Drush to apply security patches promptly.

3. Install Trusted SSL Certificates

For better security, enable HTTPS using a free Let’s Encrypt certificate, or any certificate provider of your choice. On Ubuntu, you can install Certbot to manage certificates for Apache.

sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache -d example.com -d www.example.com

Certbot will configure Apache to auto-redirect HTTP traffic to HTTPS, ensuring data travels securely between your server and visitors.

Performance Optimization

With Drupal installed, you can boost site speed and responsiveness by applying a few optimization tips. Site load time is very important for user experience and for improving SEO ranks.

1. Enable Caching

Drupal has built-in caching settings. By default, the “Internal Page Cache” module improves performance for anonymous visitors. Under “Configuration” > “Performance,” enable caching granted your site doesn’t require real-time content for every user.

2. Optimize PHP Settings

Editing php.ini for recommended values can help with memory usage and script execution. Increase memory_limit and max_execution_time if you expect to handle large files or resource-intensive modules:

sudo nano /etc/php/8.3/apache2/php.ini

Adjust the settings accordingly, then reload Apache:

sudo systemctl reload apache2

3. Consider a Reverse Proxy Cache (Optional)

If you serve high traffic, deploying a reverse proxy cache like Varnish can reduce server load. Varnish sits in front of Apache, caching content and delivering responses faster. You’ll need to configure your Drupal site’s settings to work effectively with Varnish, which can further reduce page load times.

4. Use a Content Delivery Network (CDN)

For widespread traffic, a CDN caches static assets (images, CSS, JavaScript) at nodes worldwide. That reduces latency for distant visitors. Drupal’s straightforward integration with many CDN solutions ensures content is served from the closest location to your audience.

Troubleshooting Common Issues

While installing Drupal on Ubuntu 24.04 is relatively straightforward, occasional hiccups can arise. Below are some pointers to handle frequent errors.

1. Permission or Ownership Problems

If you see a “Failed to create directory” or “Cannot write to settings.php file” error, confirm the Drupal folder ownership matches the Apache user. Also verify file permissions are set correctly. Run:

sudo chown -R www-data:www-data /var/www/drupal
sudo chmod -R 755 /var/www/drupal

2. Database Connection Issues

Review your database credentials in settings.php if Drupal cannot connect. Double-check that the user has the right privileges and the password matches. Also ensure that MariaDB or MySQL is running properly:

sudo systemctl status mariadb

3. PHP Configuration Errors

If you encounter unresponsive pages or blank screens, verify your PHP version is supported. Ensure all needed extensions (php8.3-gd, php8.3-xml, php8.3-mbstring, etc.) are installed. Enable or disable certain extensions in php.ini or the relevant configuration files, followed by an Apache restart.

4. Rewrite Module Not Enabled

If Drupal page URLs lead to “404 Not Found” errors, verify that mod_rewrite is activated and that “Clean URLs” is enabled in Drupal. Confirm your .htaccess file is present in the Drupal root directory:

sudo a2enmod rewrite
sudo systemctl reload apache2

Congratulations! You have successfully installed Drupal. Thanks for using this tutorial for installing Drupal on Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the Drupal website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button