How to Install Drupal 7 on CentOS 7 With LEMP

In a previous tutorial, I showed you how to install LEMP on CentOS 7 Server. Now If you want to build a website on top of that, you can either install WordPress or Drupal, both are good choice of content managemet system. This tutorial will show you how to install Drupal 7.

Install Drupal 7 on CentOS

First, upgrade all your system software to the lastest version available in your software repository using the following command:

sudo yum update

Next, download Drupal from the official website. You can use wget to do that:

wget http://ftp.drupal.org/files/projects/drupal-7.41.tar.gz

When you read this turorial, there maybe a newer version of drupal avaiable, you can check it at https://www.drupal.org/project/drupal

Once the download is completed, unpack it using the following command. This will create a drupal-7.41 directory under the current directory.

tar xzvf drupal-7.41.tar.gz

Now copy all the file in the drupal-7.41 directory to the web root. If you followed the previous tutorial, then your web root will be /usr/share/nginx/html

sudo mv drupal-7.41/* /usr/share/nginx/html/

Setting up the database

Log into the MariaDB shell, this can be done using the command:

mysql -u root -p

Once you are in the MariaDB shell, create a new database for Drupal using the following command. I name it drupal, you can use whatever name you like.

create database drupal;

Then create a new database user using the following SQL statement. Again, I name it drupaluser, you can use whatever name you like.

create user drupaluser@localhost;

Set a password for the user:

set password for drupaluser@localhost= password("your-password");

Then grant all permission of the new database to the new user:

grant all privileges on drupal.* to drupaluser@localhost identified by 'your-password';

Flush your database:

flush privileges;

Exit MariaDB Shell:

exit;

Configuring Drupal

Change your working directory to the web root:

cd /usr/share/nginx/html

Copy the default settings to a new file:

sudo cp sites/default/default.settings.php sites/default/settings.php

Add write permission to settings.php file and sites/default directory

sudo chmod a+w sites/default/settings.php
sudo chmod a+w sites/default

Last, we need to change the owner of web root directory to the Nginx user. The nginx user is usually nginx or www-data. You can check it in /etc/nignx/nginx.conf file In addtion, we need to add the current user to the www-data group, so that we can edit files under web root directory.

sudo chown nginx:nginx /usr/share/nginx/html/ -R

sudo usermod -a -G nginx your-username

newgrp nginx

Installing Drupal 7 in your browser

Before you go to your browser, we need to install php-gd so that the Drupal installation script can run without problems. This can be done using the command

sudo yum install php-gd php-xml php-mbstring

Edit /etc/php.ini file, put the following text to it.

extension=dom.so

Save the file and restart php-fpm

sudo systemctl restart php-fpm

Now head over to your web browser and type the following

http://server-domain or ip/install.php

You will see the Drupal installation wizard. Follow the instructions and finish the Drupal 7 installation.

After you installed Drupal, you should remove the index.html file in web root:

rm index.html
Rate this tutorial
[Total: 2 Average: 4.5]

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here