Drupal is an open source content management system written in PHP and distributed under the GNU General Public License. Drupal is also popular like WordPress and it is used by millions of people and organizations to build their sites.
In this tutorial we will guide you on how to install Drupal 9 using the LAMP stack.
Let’s start with the installation.
Installing PHP and PHP extensions
In this section we will install PHP and PHP extensions required to run Drupal.
First Let us update our system.
sudo apt update && apt upgrade
Let us install PHP and PHP extensions.
sudo apt install php libapache2-mod-php php-common php-mbstring php-xmlrpc php-soap php-gd php-xml php-intl php-mysql php-cli php-zip php-curl -y
2. Creating Database and Database user
In this step we will create a Database and Database user for our Drupal site. To do that we first we need to enter to the MySQL terminal.
mysql -u root -p
Let us create a database.
MariaDB [(none)]> create database drupal;
Let’s create a user and grant all privileges to the database drupal.
MariaDB [(none)]> grant all privileges on drupal.* to 'drupal_user'@'localhost' identified by 'mypassword';
Please don’t forget to change ‘mypassword‘ to your desired password.
Let us save the chages we made and exit;
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;
3. Download Drupal
Now that PHP and MySQL is setup we will now download Drupal. The version of Drupal as of this writing is 9.3.0.
First we need to change directory.
cd /var/www/
Let us download Drupal.
wget https://www.drupal.org/download-latest/tar.gz -O drupal.tar.gz
Let’s extract the file.
tar -xvzf drupal.tar.gz
Remove the tar.gz file and rename the extracted directory.
rm -r drupal.tar.gz
mv drupal-* drupal
Change the ownership of the drupal directory to the Apache user www-data.
chown -R www-data:www-data /var/www/drupal/
Fix the permission of the Drupal directory.
sudo find /var/www/drupal/ -type d -exec chmod 755 {} \;
sudo find /var/www/drupal/ -type f -exec chmod 644 {} \;
The first command will find and set all directories to 755 and the second will look for all the files and set the permission to 644.
4. Creating Apache Virtual Host
Let us create a virtual host for our Drupal site.
sudo nano /etc/apache2/sites-available/drupal.com.conf
Add the following on the drupal.com.conf file.
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/drupal
ServerName domain.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/smf/>
Options +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Don’t forget to change the Servername directive to your domain.
Then save and exit.
Before we restart the Apache web server we need to enable the Apache mod_rewrite. To do that run this command.
sudo a2enmod rewrite
Now Let’s enable the virtual host we created.
sudo a2ensite drupal.com.conf
Then restart the Apache webserver.
sudo systemctl restart apache2
5. Finalizing the Drupal Installation
Now that the Apache virtual host is setup you can now access your site to finalize the Drupal installation. To do that you need to open your Web Browser and access your site http://domain.com.
Choose your preferred language and click Save and continue.
Select an installation profile. Just select the default option standard and click Save and continue.
Provide the Database name, the Database Username, and the Database user password that we created in step 2 then click Save and continue.
Wait for the installation to finish.
Fill up the forms with your site information and site maintenance account then click Save and continue.
Congratulations the installation was successful.
Conclusion
You have learned how easy to install Drupal on Ubuntu 20.04 with the LAMP stack. If you like this article you might like also our article on WordPress.
If you have questions, feel free to leave a comment and we will try to answer it.
Thank you and hope you enjoy our tutorial ?