Drupal 7 Installation on Centos 6.5 - Part 2

Drupal Logo ​This is Part 2 of an article showing how to install Drupal 7.28 on Centos 6.5.  Part 1 covered the LAMP stack build necessary for supporting Drupal.  This part covers the installation of a single website in its own directory using Drupal.

This site will be setup to allow all commonly used functionality of Drupal but will not represent a full 'enterprise lockdown' of the system.  This will be dealt with by a separate article and involves a detailed permissioning schema for the various directories of the system.  For now, the goal is to create a partially secured' installation suitable for use on the Internet.

Part 1 delivered a fully working, 'Drupal ready' LAMP stack with the following software versions:

  • MySQL 5.1.73
  • Apache web server 2.2.15
  • PHP 5.3.3

To ensure correct functioning of Drupal the following PHP modules were installed:

  • php-pdo
  • php-gd
  • php-mbstring
  • php-xml
  • php-mysql
  • php-pear

Quick Test

To ensure that all settings are persistent, reboot the server and again visit the PHP validation web page http://<ip_address_of_server/validate.php.  The output should be similar to this:

PHP validation page

Assuming the validation page appears as above, now might be a good time to take a snapshot of the installation.

Now, onto the Drupal installation.

Download and Extract Drupal

  • Install wget so that installation source can be downloaded
yum install -y wget

Create and move to installation target directory.  Installation target is up to the individual.  Here is a workable example.

mkdir /var/www/sites
​cd /var/www/sites
  • Download source files
wget http://ftp.drupal.org/files/projects/drupal-7.28.tar.gz
  • Unpack the files
tar -zxvf drupal-7.28.tar.gz
  • Rename the top level Drupal directory (drupal-7.28) to drupal_01.  A better naming idea for the directory would be to name the directory according to the planned website name (or perhaps to a customers ID and a numeric counter suffix.
rename drupal-7.28 drupal_01
  • Delete the .gz file
rm drupal-7.28.tar.gz

Assign Ownership, Permission Website Directory Structure

  • Assign apache user account ownership of the Drupal directory structure

chown -R apache:apache /var/www/sites/drupal_01

  • Permission the files and directory
find /var/www/sites/drupal_01 -type d -exec chmod 755 {} \;
find /var/www/sites/drupal_01 -type f -exec chmod 644 {} \;

Directory for the site should look like this:

drwxr-xr-x.  9 apache apache  4096 May  8 06:18 .
drwxr-xr-x.  3 root   root    4096 May 21 21:07 ..
-rw-r--r--.  1 apache apache  6604 May  8 06:05 authorize.php
-rw-r--r--.  1 apache apache 88691 May  8 06:05 CHANGELOG.txt
-rw-r--r--.  1 apache apache  1481 May  8 06:05 COPYRIGHT.txt
-rw-r--r--.  1 apache apache   720 May  8 06:05 cron.php
-rw-r--r--.  1 apache apache   174 May  8 06:05 .gitignore
-rw-r--r--.  1 apache apache  5767 May  8 06:05 .htaccess
drwxr-xr-x.  4 apache apache  4096 May  8 06:05 includes
-rw-r--r--.  1 apache apache   529 May  8 06:05 index.php
-rw-r--r--.  1 apache apache  1717 May  8 06:05 INSTALL.mysql.txt
-rw-r--r--.  1 apache apache  1874 May  8 06:05 INSTALL.pgsql.txt
-rw-r--r--.  1 apache apache   703 May  8 06:05 install.php
-rw-r--r--.  1 apache apache  1298 May  8 06:05 INSTALL.sqlite.txt
-rw-r--r--.  1 apache apache 17995 May  8 06:05 INSTALL.txt
-rw-r--r--.  1 apache apache 18092 Nov  1  2013 LICENSE.txt
-rw-r--r--.  1 apache apache  8191 May  8 06:05 MAINTAINERS.txt
drwxr-xr-x.  4 apache apache  4096 May  8 06:05 misc
drwxr-xr-x. 42 apache apache  4096 May  8 06:05 modules
drwxr-xr-x.  5 apache apache  4096 May  8 06:05 profiles
-rw-r--r--.  1 apache apache  5382 May  8 06:05 README.txt
-rw-r--r--.  1 apache apache  1561 May  8 06:05 robots.txt
drwxr-xr-x.  2 apache apache  4096 May  8 06:05 scripts
drwxr-xr-x.  4 apache apache  4096 May  8 06:05 sites
drwxr-xr-x.  7 apache apache  4096 May  8 06:05 themes
-rw-r--r--.  1 apache apache 19986 May  8 06:05 update.php
-rw-r--r--.  1 apache apache  9642 May  8 06:05 UPGRADE.txt
-rw-r--r--.  1 apache apache  2178 May  8 06:05 web.config
-rw-r--r--.  1 apache apache   417 May  8 06:05 xmlrpc.php

Create a Site Configuration File

This server is being setup to handle multiple Drupal sites, each in their own directory alongside the 'drupal_01' site and each via its own unique URL.  In order for the apache web server to know where to send site URL requests, a site specific configuration file must be created

  • Create a file called 'drupal_01.conf in /etc/httpd/conf.d.  
  • Copy the below lines to the file
<VirtualHost *:80>
    ServerName test.drupal.local
    DocumentRoot /var/www/sites/drupal_01
    <Directory /var/www/sites/drupal_01>
        AllowOverride All
        Options Indexes FollowSymLinks
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>
  • Ensure that the following line in /etc/httpd/conf/httpd.conf is NOT commented out:
  • Include conf.d/*.conf

Remove the comment in the following line so that it is read by apache (i.e. it should NOT be commented out either):

​NameVirtualHost *:80

Restart apache web server

service httpd restart

Create a Settings.php

Settings.php is a critical file for your Drupal web site.  It is important that it is protected via file permissions once the site has been installed to prevent future alterations (accidental or otherwise)

  • Go to /var/www/sites/drupal_01/sites/default
  • Copy the existing default.settings.php
cp default.settings.php settings.php
  • Temporarily permission the file such that the installation process can write data (specifically the MySQL connection string) to the file.
chmod 777 /var/www/sites/drupal_01/sites/default/settings.php

Create a site database

The Drupal software does not create a database on the database server for you.  You need to first create an empty database and then tell the Drupal installation web UI (later) the details of the db. Right now we simply need to create the empty database ready for Drupal

  • Log into the database server
mysql -u root -p
  • Create an empty database
create database drupal01; 
  • Create a user that has the correct permissions within the database
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES, CREATE TEMPORARY TABLES, CREATE VIEW ON drupal01.* TO 'dpl01usr'@'localHost' IDENTIFIED BY '<insert_password_here>';

Note:  You could simply 'GRANT ALL' but the string above are the permission requirements accumulated during the creation of many sites.  I prefer the policy of providing minimum proven required permissions

Setup name resolution

There are a couple of ways to achieve this.  Either you could add a DNS entry for your elected website name or simply alter the client-local hosts file on the machine from which you will navigate to the new test site.  In my case I added the following line to c:\windows\system32\drivers\etc\hosts

192.168.1.78    test.drupal.local

The most important thing is that the host name added to your hosts file or DNS server is the same as that placed in the  /etc/httpd/conf.d/drupal_01.conf file.

Install and Configure the Site

Now you are ready to Create a Drupal installation that will host a single web site.

Choose Profile

  • Leave it as default (Standard) and click 'Save and Continue'

Page One, Drupal Installation

Choose Language

  • Click 'Save and continue'.  In the default Drupal download the only language option is English.

Page Two, Drupal Installation

Verify Requirements

The Drupal Installation process performs a high level check on the base requirements on the target system.  If there are any serious issues, they will be highlighted in red.  You should correct these before continuing.  If all is good you will move directly to the database set-up page.  Here's a screen shot to show what happens if you forget to permission the settings.php file:

Page Three, Drupal Installation - Verification Error

Set Up Database

  • Leave the database type button untouched (i.e. on 'MySQL, MariaDB or equivalent'.  
  • Do not touch the 'Advanced options'

In this screen of the installation process you need to

  • Enter the database name: drupal01
  • Enter the database username: dpl01usr
  • Database password: <password used in user creation process in mysql client>

Page Four, Drupal Installation

  • Click 'Save and continue'

The installation process now installs all of the database tables for the system's modules.  You will see a progress bar at the top of the screen

Configure Profile

Note the message in the yellow box at the top of the screen here.  It is informing you that all writes to the settings.php file have been completed.

File Permission Change Recommendation

  • Lock down the settings file
chmod 444 /var/www/sites/drupal_01/sites/default/settings.php

At this point you are personalising the site with key information.  Fill in the form appropriately.  Here are some suggestions (this information can be edited later in the UI of the system, if you desire)

  • Site name: My First Drupal Site
  • Site e-mail: An e-mail address that mail recipients would see.  This would generally have the same domain as the site.
  • Site maintenance account: dpl01admin
  • E-mail address: Your e-mail address
  • Password: A suitably complex password
  • Default country: Select correct country for final destination of website

I advise leaving both 'Check for updates automatically' and 'Receive e-mail updates' selected

Site Configuration, Drupal Installation ​ ​

  • Click 'Save and continue'

Finished

Your site is now complete.  Click the 'Visit your new site' and you will be taken to the front page.

Installation CompleteHome page

You are now ready to create the content of your new site and introduce new functionality to the system via some of the 20,000 plus modules that are available.  A future article will deal with the most useful modules for creating a great Drupal site.