Install Drupal 7 content management system

Table of Contents

Note

Drupal is a web site content management system serving web pages to the internet.

Prepare

Install Apache2 web server if not already installed.

Enable Apache2 rewrite module:

$ sudo a2enmod rewrite

Configure Apache2:

$ gksudo gedit /etc/apache2/apache2.conf

Specify, keeping "<" and ">":

<Directory /var/www/>
    Options Indexes FollowSymLinks
    # AllowOverride None # replaced with next line
    AllowOverride All
    Require all granted
</Directory>

Restart Apache2 service:

$ sudo systemctl restart apache2
or
$ sudo service apache2 restart

Install MySQL server + PHP5 + phpMyAdmin, and create a user with database both called "drupal7".

Install

Download Drupal 7.53 (filename drupal-7.53.tar.gz) from https://drupal.org/project/drupal, usually to own "Downloads" directory.

Use the file manager to extract the contents of the compressed file under the "Downloads" directory as "drupal-7.53".

Create a folder for Drupal but using a directory name of "web" instead of the default of "drupal":

$ sudo mkdir /var/www/web

Move the contents under drupal-7.53:

$ sudo mv /home/<own account name>/Downloads/drupal-7.53/* /var/www/web/

See if there are hidden files beginning with ".", e.g. ".htaccess", ".gitignore":

$ sudo ls -la /home/<own account name>/Downloads/drupal-7.53

Move the hidden files also:

$ sudo mv /home/<own account name>/Downloads/drupal-7.53/<hidden file name> /var/www/web

Create a location for site files:

$ sudo mkdir /var/www/web/sites/default/files

Change ownership:

$ sudo chown www-data:www-data /var/www/web/sites/default/files

Create the initial configuration file for the default site:

$ sudo cp /var/www/web/sites/default/default.settings.php /var/www/web/sites/default/settings.php

Change ownership:

$ sudo chown www-data:www-data /var/www/web/sites/default/settings.php

Restart Apache2 service:

$ sudo systemctl restart apache2
or
$ sudo service apache2 restart

Complete the Drupal Installation through a Browser by pointing to http://localhost/web/install.php, and follow the instructions there, using:

  • Standard profile: English language
  • MySQL database name, user name and password as defined above
  • Site name: www.kctang.com.hk
  • Site e-mail address: <>@kctang.com.hk
  • Site maintenance username:
  • Site maintenance user e-mail address: <>@kctang.com.hk
  • Default country: Hong Kong S.A.R., China
  • Default time zone: Asia/Hong Kong
  • Check for updates automatically
  • Receive e-mail notifications

Disable "install.php" file:

$ sudo mv /var/www/web/install.php /var/www/web/<some new name>

Move ".htaccess" file up one level:

$ sudo mv /var/www/web/.htaccess /var/www

Edit ".htaccess" file:

$ sudo nano /var/www/.htaccess

Specify:

# To redirect all users to access the site WITHOUT the 'www.' prefix,
# (http://www.example.com/... will be redirected to http://example.com/...)
# uncomment the following:
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]
# last 2 lines uncommented
 
# RewriteBase /drupal
# add the next line after the last line
RewriteBase /web
 
RewriteRule ^ index.php [L]
# add the next line after the last line to change "http:/[ ]/" to ["http:/[ ]/web/welcome"
RewriteRule ^$ web/index.php [L]

Change folder permissions:

$ sudo chmod 555 /var/www/web/sites/default
$ sudo chmod 444 /var/www/web/sites/default/settings.php

Create folders for and permit installation of additional modules:

$ sudo mkdir /var/www/web/sites/all
$ sudo mkdir /var/www/web/sites/all/modules
$ sudo mkdir /var/www/web/sites/all/themes
$ sudo chown www-data:www-data -R /var/www/web/sites

Increase upload file size limit:

$ gksudo gedit /etc/php/7.0/apache2/php.ini

Change existing to:

post_max_size = 200M
upload_max_filesize = 50M
max_file_uploads = 100

Restart Apache2 service:

$ sudo systemctl restart apache2
or
$ sudo service apache2 restart

Do the following if the web pages do not show up after restoring the mysql database for drupal:

  • Rename back "install.php" mentioned at "Disable install.php"
  • Rename "settings.php" to some backup file name
  • Do steps from "Create the initial configuration file for the default site" to "Complete the Drupal Installation"
  • At the last one, after entering the database name, user name and password, a message of "Drupal already installed" should be displayed
  • Choose the option of "View your existing site", the web pages should show up, and the website should be back to life
  • Do "Disable install.php"