Thursday, 2 May 2013

Installing Drupal CMS

Now that I have started a business I need to have a professional looking webpage.  I also wanted to learn how to set this up myself using Linux as this skill may be useful in the future.  This post describes how I did that using a cloud Linux server and Drupal.


Sorting out the hosting hardware

Having played around with a home Linux server I decided I did not want the noise or hassle so I rented a simple cloud server.  After some research I used ToggleBox for $10/month (April 2013) which I found to be the cheapest especially as they had a deal on (50% off for first month and $30 credit).  There are a few options to choose when setting up a cloud server - I went for the lowest level server with 1 core, 1 IP address, 10GB storage and 512MB of RAM.  I also went for CentOS 6.2 out of a list of dozens of operating systems (including Windows Server) mostly because I hadn't used it before.  These choices kept the cost to $10/month and if more oomph or space becomes necessary in the future it can be changed with a few mouse clicks and a few extra $$.  A really major benefit for me was that I had a static IP address which I couldn't have from home (Sky Broadband IP addresses change occasionally) - simplifying pointing my URL to it.


Choosing the software

I could have written a page in html but it would have looked very old-fashioned and unprofessional and it would have taken me ages.  I could have bought some software such as Adobe Dreamweaver and designed the website.  In the end I decided to use a Content Management System because of the many templates, plug-ins, modules and other open source stuff to use as lego blocks rather than stacking atoms.  Quick and good-looking but with options to do more advanced stuff in the future was what was required.

I had been playing around with Wordpress which is great for blog style sites but didn't feel this could provide for the more advanced stuff I had in mind in the future.  Reading around a bit (e.g. LinuxLinks, INT3c and Rackspace) the most popular alternatives are Joomla and Drupal which are both open source and have the usual fervent supporters/detractors.  Some sites I read comparing the two are Digital Point, CMS2CMS (which might come in handy later!), with particular detail Computer World and finally Drupalist.  There doesn't seem to be much to choose between Joomla and Drupal as such, but the requirement for more advanced stuff in the future swung the decision to Drupal.

How to install Drupal

LAMP setup

I followed a couple of guides to installing Drupal - the official documentation and the 3rd party Digital Ocean.

The first thing I did was go to my cloud server web management page and rebuild it to include a LAMP distro (CentOS 6.2 Lamp x64).  I checked this was working by going to its IP address in a browser and seeing a phpinfo() screen.

For the next steps I needed to have a secure shell connection (ssh).  I had ssh'd into the server for a previous build so my local RSA key no longer matched the server giving me the error message:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
57:af:ea:3b:94:38:ae:8d:96:ad:c9:6f:f5:66:2a:ee.
Please contact your system administrator.
Add correct host key in /Users/mattmapleston/.ssh/known_hosts to get rid of this message.
Offending key in /Users/mattmapleston/.ssh/known_hosts:8
RSA host key for xxx.xxx.xxx.xxx has changed and you have requested strict checking.
Host key verification failed.

This was fixed by removing the key for the server identified by its IP address xxx.xxx.xxx.xxx by running the following from the user's home directory:
(null):~ mattmapleston$ nano .ssh/known_hosts


Once at the terminal prompt having logged in to the remote server at togglebox I checked the version of the distro:

[root@chanzachanzo ~]# cat /etc/issue
CentOS release 6.2 (Final)
Kernel \r on an \m


A quick (actually not so quick) update using yum update and I was ready to check the requirements were met by looking at the phpinfo() output seen when I point a browser to the server and executing the shell command mysqladmin version.
Drupal recommends Apache 2.x and this distro had Apache 2.2.15
Other requirements (and my versions) were: PHP 5.3 (5.3.3); MySQL 5.0.15 (5.1.69)

So the basic LAMP software was installed and apparently working (check MySQL with mysqladmin -u root -p status) but not quite configured properly.  MySQL default is to have no password i.e. blank and this must be reset using the command mysql_secure_installation.  This goes through a few options to improve security including setting the all important don't-you-ever-forget-it MySQL password.

Extra installs were needed using yum install <pkg-name listed below>
nano (this somehow was removed sometime around the update)
php-mysql (this also installs the PDO dependency mentioned in MySQL requirements for Drupal)

Get and install Drupal

The Drupal website showed the recommended version of Drupal was 7.22 so I navigated to the /var/www/html directory where my website(s) will be and issued the following commands to download, unpack the approximately 3MB file.

curl -O http://drupal.org/files/projects/drupal-7.22.tar.gz
tar -xzvf drupal-7.22.tar.gz
Now the contents of the drupal-7.22 folder need to be moved up one level into var/www/html as follows:
mv drupal-7.22/* drupal-7.22/.htaccess drupal-7.22/.gitignore ./
rm drupal-7.22/

Now return to your browser and refresh the page to your server that previously showed phpinfo.  This will take you to a web based installation screen which (in step 3) checks the base requirements and proper installation.  A number of problems came up and were solved thus:

yum install php-gd php-xml php-mbstring
/sbin/service/ httpd restart

cd /var/www/html/sites
chmod a+w default

cd default
cp default.settings.php settings.php
chmod a+w settings.php

Possibly important missing files and directories that I created just in case:
/sites/default/files
/sites/default/private
/sites/default/private/files

Before moving onto the next step a MySQL database must be set up.

Set up MySQL database

Digital Ocean's instructions were very clear for this step.  Here's what was done following those instructions:

#mysqladmin -u root -p create drupal7db
#mysql -u root -p
#<asks for password>
mysql> CREATE USER d7user@localhost;
mysql> SET PASSWORD FOR d7user@localhost= PASSWORD("password");
mysql> GRANT ALL PRIVILEGES ON drupal7db.* TO d7user@localhost IDENTIFIED BY 'password';
mysql> FLUSH PRIVILEGES;
mysql> EXIT

After each command you should get a response of Query OK, 0 rows affected (0.00 sec).  If you get -> it's because you didn't end the command with ; so type ; and press return.

Here are some other useful mysql commands:
mysql> show databases;
mysql> use <database name>;
mysql> show tables;
and lots more at pantz.org (small snigger).

Continue Drupal Installation

Next go back to the web page to continue the installation process.  Once you get to the configure site page nip back over to your terminal/command line and change one or two permissions for a bit of security:
[root@chanzachanzo default]# ls -l
total 52
-rw-r--r-- 1   6226   6226 23202 Apr  3 21:29 default.settings.php
drwxrwxr-x 3 apache apache  4096 May  2 00:11 files
-rwxrwxrwx 1 root   root   23508 May  2 00:11 settings.php
[root@chanzachanzo default]# chmod 644 settings.php 
[root@chanzachanzo default]# ls -l
total 52
-rw-r--r-- 1   6226   6226 23202 Apr  3 21:29 default.settings.php
drwxrwxr-x 3 apache apache  4096 May  2 00:11 files
-rw-r--r-- 1 root   root   23508 May  2 00:11 settings.php

Finally come back to the browser to finish off the installation process which finishes with the drupal log on page.

Sorted.  Now to find out how to use it...
My take on Drupal Basic Concepts