Drupal In A Cloud - Part V
Drupal: Install Me
In the previous article we learned how to create a public subnet and install an EC2 instance in a public subnet. We also learned how to install MySql client and test connection to the MySql database.
Now, it's time to install Drupal on the EC2 instance. We will install and configure,
- PHP 5.x
- Apache Web Server
- PEAR
- Drush
- Drupal
PHP
Connect to your EC2 instance from the terminal.
Riteshs-MacBook-Pro-2:SMX rpatel$ ssh -i rpatel-kp.pem ec2-user@52.4.116.244
Next, install PHP and relevant packages from the EC2 terminal.
sudo yum -y install httpd php php-cli php-gd php-intl php-mbstring php-mysql php-pdo php-pear php-xml php-xmlrpc
Running this command will download and install PHP packages on the EC2 instance. Let's verify PHP version.
[root@ip-10-0-1-165 ~]# php --version
PHP 5.3.29 (cli) (built: May 12 2015 22:42:19)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2014 Zend Technologies
And we have a PHP installed on our instance.
Next we will configure Apache.
Configure Apache
Modify Apache config file and add,
ServerName localhost
find **** and under that change AllowOverride None to AllowOverride All
[root@ip-10-0-1-165 httpd] cd /etc/httpd/conf
[root@ip-10-0-1-165 httpd] vi httpd.conf
Next we make sure the httpd service is configured to start automatically on reboot.
[root@ip-10-0-1-165 httpd] sudo chkconfig httpd on
Next we start the Apache Server.
[root@ip-10-0-1-165 httpd] sudo service httpd start
Starting httpd:
Now open a browser on your local machine and test the connection to Apache with the public DNS of the EC2 instance.
And voila! I see a default Apache webpage in my browser.
Next, let's create a database for Drupal on MySql RDS instance. We already tested the connection to RDS instance from the EC2 and therefore let's fire up the MySql client.
mysql -h drupalmysql.cwrdcab4ee8c.us-east-1.rds.amazonaws.com -P 3306 -u admin -p
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 648
Server version: 5.6.23-log MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
Next, we will list all databases from the RDS instance.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| innodb |
| mysql |
| mysqldb |
| performance_schema |
+--------------------+
5 rows in set (0.01 sec)
Finally, we will create the database named drupaldb.
mysql> create database drupaldb;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| drupaldb |
| innodb |
| mysql |
| mysqldb |
| performance_schema |
+--------------------+
6 rows in set (0.01 sec)
As you noticed we have a drupaldb database in our list now. Now moving on to PEAR installation.
Install PEAR
PEAR is a framework and distribution system for reusable PHP components.
We will install PEAR to help us download and install Drush. So now what is Drush?
Drush is a command line shell and Unix scripting interface for Drupal. Drush core ships with lots of useful commands for interacting with code like modules/themes/profiles.
Back to terminal.
sudo pear upgrade
sudo pear channel-discover pear.drush.org
sudo pear install drush/drush
Go to Apache web root on the EC2 instance: /var/www/html and download the most recent drupal version in the web root.
[root@ip-10-0-1-165 ~]# cd /var/www/html
[root@ip-10-0-1-165 ~]# sudo drush dl
And you should see something like below in your terminal. Which means the most recent Drupal version is downloaded under the web root.
Install Drupal
Now let's move all files under drupal-7.38 directory to the web root and finally remove the drupal-7.38 folder.
//move drupal files
sudo mv drupal-7.38/* ./
//move the .htaccess file
sudo mv drupal-7.38/.htaccess ./
//remove drupal download
sudo rm -r drupal-7.x
Next we need a location to place the files for our new Drupal site. Each Drupal site need a site-specific configuration file. Drupal provides a default configuration file. We will make a copy of this file for our new site.
//create a new folder to store drupal site files
sudo mkdir sites/default/files
//change permissions on the new folder
sudo chmod 777 sites/default/files/
//copy the default settings file for the new site
sudo cp sites/default/default.settings.php sites/default/settings.php
//change permissions on the settings.php file
sudo chmod 777 sites/default/settings.php
Now open up your browser and enter EC2 dns name. Remember, just few minutes ago when we did that it showed us the default Apache page. Now it should show you the Drupal Installation Screen like below.
You guessed it right. We will go through installation screen and complete Drupal installation. In the process have the MySql credentials handy, you will need them. Remember, I had mentioned earlier that Drupal silently creates database objects for which it will need the information about the MySql RDS instance.
Click Save and Continue and select English as a default language.
Click Save and Continue. If you did not create the settings.php file then Drupal installation will show you a warning about the missing configuration file else you will be redirected to the Set up Database page.
Let's have a closer look at the screen above.
- We specify database name: drupaldb
- We specify database username: admin
- We specify database password: ****** (this was the password you created when you setup the RDS instance)
Under Advanced Options,
- We specify the RDS endpoint without the port: drupalmysql.cwrdcab4ee8c.us-east-1.rds.amazonaws.com
- If you are running MySql on a non-default port then please specify the port
Click Save and Continue. Next you will see a progress bar showing you the progress of Drupal install. When completed, you should see a site configure screen as below.
In the screen above we created an admin account for Drupal Administration. We named the user drupaladmin, specified a password, email address and few other options. When done, click Save and Continue.
Voila! I see a message on my screen Congratulations, you installed Drupal.
In the screen above I also see a link Visit your new site. Quite anxiously I clicked on it and whoa! I got my first Drupal Website.
We had allowed read-write-execute permissions on settings.php. Since the installation is complete, we need to revert permissions back to read-only.
[root@ip-10-0-1-165 html]# sudo chmod 644 sites/default/settings.php
Note: Drupal will show you a warning if you have open and less restrictive permissions on this file.
With Drupal installation complete, let's look at how to configure Clean URLs before we call it a day!
Clean URL(s)
By default Drupal will show you URL(s) with query strings. Ugly! I truly am a fan of clean URL(s).
Ugly default URL: http://drupal-website/?=page1
Clean URL: http://drupal-website/i-like-drupal
Much better, right? So how do you enable clean URLs?
You are already logged in as a drupaladmin and therefore from the Drupal website click on Configuration.
Click on Clean URLs.
Select Enable Clean URLs and then click Save Configuration.
And now our Drupal site should serve pages with Clean URLs.
With this I conclude Drupal In A Cloud series. Now go play with your new Drupal website, will ya?
Cheers!
Hi, I am Ritesh Patel. I live in a beautiful town surrounded by the mountains. C&O Canal is few miles away. State parks are only a distance away & bike trails galore. It is home sweet home Frederick, MD. A passionate developer. Love to cook. Enjoy playing "Bollywood Tunes" on my harmonica. Apart from that just a normal guy.