How To Install Drupal on a VPS Running Ubuntu 24.04
Are you ready to unleash the power of a flexible and robust content management system (CMS) that can handle everything from personal blogs to corporate websites? Look no further than Drupal! In this post, we’ll guide you through the process of installing Drupal on a Virtual Private Server (VPS) running Ubuntu 24.04. Whether you’re a seasoned developer or a newcomer eager to learn, this step-by-step guide will help you set up your very own Drupal site with ease.
What You’ll Need
Before we get started, ensure that you have the following prerequisites:
- A VPS running Ubuntu 24.04.
- Root access to the server or a user with sudo privileges.
- A registered domain name (optional, but recommended).
- Basic knowledge of the command line.
Step 1: Update Your System
First, before installing any software, it’s essential to update your system packages to their latest versions. Connect to your VPS using SSH and run the following commands:
sudo apt update
sudo apt upgrade -y
This will ensure that all dependencies are up to date, minimizing the risk of compatibility issues.
Step 2: Install Apache, MySQL, and PHP
Drupal requires a web server, a database management system, and PHP. For this guide, we’ll use Apache, MySQL, and PHP.
A. Install Apache
sudo apt install apache2 -y
After installation, you can enable Apache to start on boot and check its status:
sudo systemctl enable apache2
sudo systemctl start apache2
sudo systemctl status apache2
B. Install MySQL
Next, install the MySQL server:
sudo apt install mysql-server -y
Once installed, secure your MySQL installation:
sudo mysql_secure_installation
Follow the on-screen prompts to set a root password and secure your installation. This includes removing test databases and restricting remote access.
C. Install PHP and Required Extensions
Now, let’s install PHP along with some necessary extensions for Drupal:
sudo apt install php libapache2-mod-php php-mysql php-xml php-mbstring php-zip php-gd php-curl php-json -y
D. Restart Apache
After installing PHP, you should restart Apache to ensure that it recognizes the new PHP installation:
sudo systemctl restart apache2
Step 3: Create a MySQL Database for Drupal
Next, you need to create a database and a user for your Drupal installation. Log in to the MySQL shell:
sudo mysql -u root -p
Once inside MySQL, run the following commands to create a new database and user:
CREATE DATABASE drupaldb;
CREATE USER 'drupaluser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON drupaldb.* TO 'drupaluser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Make sure to replace 'password'
with a strong and secure password of your choice.
Step 4: Download and Install Drupal
Now that your server environment is set up, it’s time to download and install Drupal.
A. Download Drupal
Navigate to the /var/www/html
directory:
cd /var/www/html
Download the latest version of Drupal using wget
:
wget https://www.drupal.org/download-latest/tar.gz -O drupal.tar.gz
B. Extract the Files
Extract the downloaded archive:
tar -xvf drupal.tar.gz
Rename the extracted folder for easier access:
mv drupal-* drupal
C. Set Permissions
Set the appropriate permissions for the Drupal directory:
sudo chown -R www-data:www-data /var/www/html/drupal
sudo chmod -R 755 /var/www/html/drupal
Step 5: Configure Apache
To make your Drupal site accessible, you need to set up a virtual host configuration for Apache.
A. Create a New Configuration File
Create a new configuration file for your Drupal site:
sudo nano /etc/apache2/sites-available/drupal.conf
Add the following content, adjusting the ServerName
to your domain or IP address:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName yourdomain.com
DocumentRoot /var/www/html/drupal
<Directory /var/www/html/drupal>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
B. Enable the Site and Rewrite Module
Enable the new site and the rewrite
module:
sudo a2ensite drupal.conf
sudo a2enmod rewrite
C. Restart Apache
To apply the changes, restart Apache:
sudo systemctl restart apache2
Step 6: Complete Drupal Installation
Now that everything is set up, you can complete the Drupal installation through the web interface.
- Open your web browser and navigate to your server’s domain or IP address.
- You should see the Drupal installation page. Select your preferred language and click “Save and continue.”
- Next, choose “Standard” installation and click “Save and continue.”
- Enter your database details (database name, username, password) and click “Save and continue.”
- Fill in your site information (site name, admin username, email, etc.) and finalize the installation.
Once completed, you’ll see a success message and can log into your new Drupal site!
Conclusion
Congratulations! You now have a fully functional Drupal site running on your VPS with Ubuntu 24.04. With its flexible architecture, rich feature set, and extensive community support, Drupal is an excellent choice for building a variety of websites.
Don’t forget to explore the numerous themes and modules available to customize your site to fit your needs. Happy Drupal-ing!