
How to Install Drupal on Ubuntu
Installing Drupal on Ubuntu involves several steps, including setting up a web server, a database server, and PHP. Here’s a step-by-step guide to help you install Drupal on your Ubuntu system:
Step 1: Update Your System
Open your terminal and update your package index:
1sudo apt update 2sudo apt upgrade
Step 2: Install Required Packages
Install Apache, MySQL (or MariaDB), and PHP along with the necessary PHP extensions:
1sudo apt install apache2 mysql-server php php-mysql libapache2-mod-php php-xml php-mbstring php-curl php-zip php-gd php-json
Step 3: Start and Enable Apache and MySQL
Make sure Apache and MySQL services are running and set to start on boot:
1sudo systemctl start apache2 2sudo systemctl enable apache2 3 4sudo systemctl start mysql 5sudo systemctl enable mysql
Step 4: Create a MySQL Database and User for Drupal
Log into MySQL:
1sudo mysql -u root -p
Then create a database and user for Drupal. Replace drupal_db
, drupal_user
, and password
with your preferred database name, username, and password:
1CREATE DATABASE drupal_db; 2CREATE USER 'drupal_user'@'localhost' IDENTIFIED BY 'password'; 3GRANT ALL PRIVILEGES ON drupal_db.* TO 'drupal_user'@'localhost'; 4FLUSH PRIVILEGES; 5EXIT;
Step 5: Download Drupal
Navigate to the /var/www/html
directory and download the latest version of Drupal:
1cd /var/www/html 2sudo wget https://www.drupal.org/download-latest/tar.gz -O drupal.tar.gz
Extract the downloaded file:
1sudo tar -xvzf drupal.tar.gz 2sudo mv drupal-* drupal
Step 6: Set Permissions
Set the proper permissions for the Drupal directory:
1sudo chown -R www-data:www-data /var/www/html/drupal 2sudo chmod -R 755 /var/www/html/drupal
Step 7: Configure Apache
Create a new configuration file for your Drupal site:
1sudo nano /etc/apache2/sites-available/drupal.conf
Add the following configuration, replacing example.com
with your domain name or IP address:
1<VirtualHost *:80> 2 ServerAdmin admin@example.com 3 DocumentRoot /var/www/html/drupal 4 ServerName example.com 5 <Directory /var/www/html/drupal> 6 AllowOverride All 7 </Directory> 8 ErrorLog ${APACHE_LOG_DIR}/error.log 9 CustomLog ${APACHE_LOG_DIR}/access.log combined 10</VirtualHost>
Step 8: Enable the New Site and Rewrite Module
Enable the new site configuration and the rewrite module:
1sudo a2ensite drupal.conf 2sudo a2enmod rewrite
Step 9: Restart Apache
Restart Apache to apply the changes:
1sudo systemctl restart apache2
Step 10: Complete the Drupal Installation via Web Interface
- Open your web browser and navigate to
http://your_domain_or_IP/drupal
. - Follow the on-screen instructions to complete the installation.
- You’ll need to select the language, set up the database (use the database name, username, and password you created earlier), and configure the site settings.
Step 11: Secure Your Installation (Optional)
For a production environment, consider securing your installation by:
- Setting up HTTPS with a tool like Certbot.
- Configuring firewall rules.
- Regularly backing up your database and files.