Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Setting Up Drupal Environment

1. Introduction

Drupal is a powerful content management system (CMS) that allows you to create and manage complex websites. To get started with Drupal, you need to set up a development environment on your local machine or on a server. This tutorial will guide you through the steps required to set up a Drupal environment from scratch.

2. Prerequisites

Before you begin setting up Drupal, ensure you have the following prerequisites:

  • A web server (Apache, Nginx, etc.)
  • PHP version 7.3 or higher
  • MySQL version 5.7 or higher or MariaDB
  • Composer - a dependency manager for PHP

3. Setting Up the Web Server

To serve your Drupal application, you need to install and configure a web server. Here, we'll use Apache as our web server.

3.1. Installing Apache

On Ubuntu, you can install Apache using the following command:

sudo apt update && sudo apt install apache2

After installation, start the Apache server:

sudo systemctl start apache2

Enable Apache to start on boot:

sudo systemctl enable apache2

Verify that Apache is running by visiting http://localhost in your web browser.

4. Installing PHP

Drupal requires PHP to run. Install PHP and necessary extensions by executing:

sudo apt install php libapache2-mod-php php-mysql php-xml php-mbstring php-json

After installation, restart Apache to load PHP:

sudo systemctl restart apache2

5. Setting Up MySQL Database

Drupal uses a database to store content and configuration. We will set up a MySQL database for Drupal.

5.1. Installing MySQL

Install MySQL Server with the following command:

sudo apt install mysql-server

Secure your MySQL installation:

sudo mysql_secure_installation

Log into MySQL to create a database for Drupal:

sudo mysql -u root -p

Within the MySQL shell, execute the following commands:

CREATE DATABASE drupal;
CREATE USER 'drupaluser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON drupal.* TO 'drupaluser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

6. Installing Composer

Composer is essential for managing Drupal's dependencies. Install Composer by running:

curl -sS https://getcomposer.org/installer | php

To make Composer globally accessible, move it to the local bin:

sudo mv composer.phar /usr/local/bin/composer

7. Downloading Drupal

Now, we will download Drupal using Composer. Navigate to the directory where you want to install Drupal:

cd /var/www/html

Use Composer to create a new Drupal project:

composer create-project drupal/recommended-project drupal

8. Configuring Apache for Drupal

Next, we need to configure Apache to serve the Drupal site. Create a new configuration file:

sudo nano /etc/apache2/sites-available/drupal.conf

Add the following configuration:


DocumentRoot /var/www/html/drupal/web

AllowOverride All
Require all granted

Enable the new site and rewrite module:

sudo a2ensite drupal.conf && sudo a2enmod rewrite

Restart Apache:

sudo systemctl restart apache2

9. Running the Drupal Installation

Visit http://localhost in your web browser to start the Drupal installation process. Follow the on-screen instructions to complete the setup, including providing database credentials and configuring your site.

10. Conclusion

Congratulations! You have successfully set up a Drupal environment on your local machine. You can now start building your website using Drupal's powerful features.