Install Drupal on Apache Web Server

In my previous Drupal article, I covered everything you needed to know about Drupal, including how to install Drupal on a LiteSpeed web server. In this tutorial, I’ll show you how to install Drupal safely on an Apache web server.

Apache is a well-known web server on the Internet. According to w3techs, Apache web server hosts 31.5 percent of websites.

Drupal is a popular content management system (CMS) used to build websites and web applications of all types and sizes. It provides a flexible and extensible framework for developers to create custom websites and applications easily. If you plan to use Drupal to build your website, you must install it on a web server. In this tutorial, we will guide you through installing Drupal on an Apache web server.

Apache is a popular open-source web server widely used to host websites and web applications. It is known for its stability, scalability, and reliability, which makes it a popular choice among developers. In this tutorial, we assume you already have Apache installed and configured on your server.

Before we get started with the installation process, there are a few things you should know –

  • You must know how to use the command line interface (CLI) to run commands on your server.
  • You will need access to your server as a root user or a user with sudo privileges.
  • You must have a database server installed and configured on your server.
  • We will be using MySQL in this tutorial.

With that said, let’s get started with the installation process of Drupal on the Apache web server. Follow the steps carefully to avoid errors and successfully install Drupal on your server.

Install Drupal on Apache web server

In this tutorial, I’ll also show you how to install and configure basic security tools to keep hackers out of your website.

So, without further ado, let us begin the instruction on how to install Drupal 9 on an Apache web server.

Install and set up Firewall

Please see my detailed article on UFW here. It is not difficult to get started with UFW; it only requires a few lines to set up and run a firewall on any Linux distribution.

Install UFW on Fedora

sudo dnf install ufw

Install UFW on CentOS

sudo yum install ufw

Install UFW on Debian, Ubuntu or derivatives

sudo apt install ufw

Install UFW on Arch Linux

sudo pacman -S ufw

Enable firewall –

sudo ufw enable

It is important to note that once the UFW firewall is enabled, it will block all server ports, including port 22 for SSH connections. Before restarting the server or quitting the current ssh session, it is recommended to allow port 22 and other essential ports.

sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https

Install Fail2Ban

Fail2ban is an exceptionally useful tool for monitoring server-side services. Fail2ban is a system for detecting intrusions. It continuously monitors services and prevents any malicious attempt to gain access to the system.

For example, fail2ban monitors SSH port by default. Hackers attempt to guess users’ passwords via brute forcing SSH port. If your root password is weak, it is possible to guess it in a matter of minutes or hours. Fail2ban monitors SSH and blocks hosts that make multiple failed attempts.

sudo apt install fail2ban
sudo systemctl enable fail2ban
sudo systemctl start fail2ban
sudo systemctl status fail2ban

Install PHP 8

PHP 8 in Ubuntu or derivatives

sudo add-apt-repository ppa:ondrej/php

PHP 8 in Debian or derivatives

sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
sudo apt update
sudo apt install php php-zip php-cli php-xml php-gd php-mysql php-curl php-mbstring

Install MySQL Server

sudo apt install mariadb-server

Run mysql_secure_installation to set up root password.

Create database for Drupal site.

Login to mysql command-line –

mysql -u root -p

Create a new database user –

create user 'username'@'localhost' identified by 'password';

Create database for Drupal site –

create database drupal;

Grant newly create user access to drupal database –

grant all privileges on drupal.* to 'username'@'localhost';
flush privileges;

Install Composer (PHP Package manager)

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
sudo php composer-setup.php --install-dir=/bin --filename=composer

Now we can create virtual host to host our Drupal site. We can create a new configuration or copy the default configuration for our new site.

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/gaminggroup.online.conf
sudo nano /etc/apache2/sites-available/gaminggroup.online.conf

Change ServerName, ServerAlias, and DocumentRoot as following –

ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/drupal/web
sudo ln -s /etc/apache2/sites-available/gaminggroup.online.conf /etc/apache2/sites-enabled/
sudo systemctl restart apache2

Download Drupal 9 using composer

cd /var/www

Running composer as root is not recommended. The best option is to modify /var/ww permissions to provide logged-in user access to the directory.

sudo chown -R $USER /var/www
composer create-project drupal/recommended-project drupal

Fix drupal directory permissions to make it accessible by Apache web server –

sudo chown -R www-data:www-data /var/www/drupal/web
sudo find . -type d -exec chmod 755 {} \;
sudo find . -type f -exec chmod 650 {} \;

Enable Apache rewrite module –

sudo a2enmod rewrite
nano /etc/apache2/apache2.conf

Change AllowOverride None to AllowOverride All.

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>
apache configuration
apache configuration
sudo systemctl restart apache2

That’s all there is to it. Now, update the DNS for your domain to point to the server IP address. When DNS propagation is complete, you will be able to run Drupal setup from a web browser by visiting your domain name.

For this article, for example, I used gaminggroup.online and pointed it to the IP address of my Drupal server.

Drupal setup wizard is simple. If you followed all the above instructions correctly, there should not be any problem at all.

Drupal Select language
Drupal Select language
Drupal installation profile
Drupal installation profile

The Drupal setup determines whether the server fits all of the requirements and, if so, lists it on the next page. If you followed this article correctly and installed everything, you should not have any requirements left.

Requirements problem Drupal
Requirements problem Drupal

On the next page, enter the database information we created in this article. Enter database name, database username, and database password.

Database configuration Drupal
Database configuration Drupal

Enter site’s information including admin panel’s username and password.

Configure site Drupal
Configure site Drupal

Once completed, Drupal setup will redirect you to the following page, confirming that the setup was successful.

Drupal
Drupal

Conclusion

And that’s the end of it. Apache is an advanced web server. It uses somewhat more system resources than competitors like LiteSpeed and Nginx, but it is far more versatile and adaptable than any other web server.

If you have any questions about anything in this article, please leave them in the comments section below or join our Discord server. If you want to learn more specific features of Drupal, please visit Drupal documentation.

Frequently Asked Questions

Does Drupal run on Apache?

Yes, Drupal can run on an Apache web server. Apache is a popular and widely-used open-source web server that can host Drupal websites and web applications. Apache is one of the most commonly used web servers for hosting Drupal sites.

Where is Drupal installed on Linux?

In Linux, Drupal can be installed in any directory accessible by the web server. However, the most common location to install Drupal on Linux is within the document root of the Apache web server, which is usually located in the “/var/www/html” directory.

SHARE THIS POST

MassiveGRID Banner

YOU MIGHT ALSO LIKE

Leave a Reply

Your email address will not be published. Required fields are marked *