Installing Drupal with Apache and Let’s Encrypt SSL on Debian 11 can seem like a daunting task, but with the right instructions and a little bit of patience, it can be done relatively easily. This article will provide a detailed, step-by-step guide on how to get everything set up and running smoothly.
First, let’s go over the prerequisites for this installation. You will need a server running Debian 11, access to the root user account, and a registered domain name. You will also need to have Apache, MySQL, and PHP installed on your server.
Once you have these prerequisites in place, you can begin the installation process.
- Log in to your server as the root user and update the package manager index:
apt update
- Install the Apache web server, PHP, and the necessary PHP extensions by running the following command:
apt install apache2 php php-mysql php-gd php-xml php-mbstring
- Enable the Apache
mod_rewrite
module, which is required for Drupal’s clean URLs feature:
a2enmod rewrite
- Restart the Apache web server to apply the changes:
systemctl restart apache2
- Next, we’ll need to create a MySQL database and user for Drupal. Log in to the MySQL shell as the root user:
mysql -u root -p
- Once you’re logged in, create a new database for Drupal:
CREATE DATABASE drupal;
- Then, create a new MySQL user and grant them access to the Drupal database:
CREATE USER 'drupaluser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON drupal.* TO 'drupaluser'@'localhost';
- Finally, flush the MySQL privileges to apply the changes and exit the MySQL shell:
FLUSH PRIVILEGES;
EXIT;
- Now, we can download and install Drupal. First, download the latest stable version of Drupal using
wget
:
wget <https://www.drupal.org/download-latest/tar.gz>
- Extract the downloaded archive and move the resulting directory to the Apache web root directory:
tar xzf tar.gz
mv drupal-* /var/www/html/drupal
- Next, we need to set the correct permissions for the Drupal directory. Run the following commands to give the Apache user ownership of the Drupal directory and its contents:
cd /var/www/html/drupal
chown -R www-data:www-data .
- Now, we need to configure Apache to serve Drupal. Create a new Apache configuration file for Drupal by running the following command:
nano /etc/apache2/sites-available/drupal.conf
- Paste the following configuration into the file, replacing
example.com
with your registered domain name:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html/drupal
<Directory /var/www/html/drupal>
Options -Indexes +
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
- Save and close the file, then enable the new Apache configuration by running the following commands:
a2ensite drupal.conf
systemctl reload apache2
- Now, open a web browser and navigate to your domain name (e.g.,
http://example.com
). You should see the Drupal installation page. Follow the on-screen instructions to complete the installation process. - Once Drupal is installed, we can proceed to installing Let’s Encrypt SSL to secure our website. Install the Let’s Encrypt client
certbot
by running the following command:
apt install certbot
- To obtain a SSL certificate from Let’s Encrypt, run the following command, replacing
example.com
with your domain name:
certbot --apache -d example.com -d www.example.com
- This will automatically obtain a SSL certificate for your domain and configure Apache to use it. You should now be able to access your Drupal website over HTTPS.
- Finally, to ensure that your SSL certificate stays valid and is automatically renewed, you can set up a cron job to run the
certbot
renewal command periodically. Edit the crontab by running the following command:
crontab -e
- Add the following line to the end of the file, which will run the
certbot
renewal command every week:
0 0 * * 0 /usr/bin/certbot renew --quiet
And that’s it! Your Drupal website should now be up and running, securely served over HTTPS using Apache and Let’s Encrypt SSL on Debian 11.