How to host a Drupal web-site with Amazon EC2 having RDS- MySQL DB

DrupalDrupal is a popular content management system (CMS) used to run some of the largest blogs and websites across the internet. Due to the stability of the base, the adaptability of the platform, and its active community, Drupal remains a popular choice after more than a decade on the scene.

Before we get the Drupal site and install them into our web directory, we need to prepare our system. We need to install Apache, PHP, and MySQL and we need to make some additional changes to each of these for our installation.

Here below I am going describe the steps that how to host a drupal site having Amazon EC2 instance and having Amazon RDS for DB host.We need to have AWS account if already had then fine otherwise register an account on AWS.

  1. There are lot of services chose EC2 one from them, it will open a EC2 dashboard now from here we can launch new instance as per our requirement like CPU core, RAM etc, with configuration of VPC, subnet etc. or we can launch in classic wizards.
  1. Now launch EC2 instance by chossing the AMI let’s assume we select the ubuntu, VPC, Subnets, Storage and configure Security group here we will assign some security rule and enable http, SSH connection to our instance. http port range is 80 SSH port range is 22, about source you can give any IP range as you need or just leave default for now. And create a key pair and launch.
  2. Now our EC2 micro instance is running. And now we setup LAMP in our Ubuntu  For this we access our Ubuntu instance from terminal and setup LAMP in that.

Below are the steps and commands to access and setup your LAMP in Ubuntu Ec2 instance.

Step 1: Install Apache
  • Open your terminal and type this command for ssh in ec2-instance with the key.pem file from where you installed give the absolute path in command line.
$ sudo  ssh  -i   durpal_key.pem    ubuntu@<pub-ip>

Now we have to update the cache’s package and install Apache and Php

$ sudo  apt-get  update 

$ sudo  apt-get  install  apache2    –y

Step 2: Install php

To install PHP, put this command on terminal and install php lib.

$ sudo apt-get install php5  –y

$ sudo apt-get install libapache2-mod-php5   php5-mcrypt –y 

$ sudo apt-get install  php-pear  php5-mysql    php5-suhosin    –y

We have to make small change to our PHP configuration file.

$ sudo vim /etc/php5/apache2/php.ini

Search for the expose_php directive and the allow_url_fopen directive and set them both to “Off”:

(insert mode i)
. . .
expose_php = Off
. . .
allow_url_fopen = Off
. . .
 (esc and save and exit by :wq)

Now we have the Apache and php in our instance and  we just need to restart the web server to implement our changes to Apache

$ sudo    service    apache2    restart

Step 2 : Install Mysql or Create and configure RDS with Mysql DB
1.      Launch a MySQL DB instance

· Login with you AWS account and select RDS from AWS resources

· In left there are navigation bar click on Instances and click the Launch DB Instance  then it will show more than one DB engine select MySQL DB engine.

2.Specify DB Details

DB Engine                  Mysql

License model              general-public-license

DB Engine Version          5.6

· In next there are lot of things to configure as per your requirement like deployment type and the Provisioned IOPS storage and much more.

DB Instance class          db.m1.small

Multi-AZ Deployment    no/yes (as requirement yes for replica )           

Storage Type               General Purpose (SSD)

Alocation storage           10 GB

3. Settings

DB instance Identifire *       drupaltest

Master Username                 drupaluser

Master password                **********

After that click on Next Step for Configure Advanced Settings

4.   Network & Security

VPC

Subnet

Public Accessible    no

VPC  Security Groups       drupalSG

5.    Database Options

Database Name               drupaldemo

Database Port               3306

DB parameter Group          default.mysql5.6

6.     Backup  

Backup Retention Period       10 days

And there are option for monitoring and Maintenance we can configure

Now click on the Launch DB instance.

So now we have DB instance it will give a endpoint (host)

Host :    drupaltest.rds.us-east-2.amazon.com

DB Name : drupaldemo

DB_User : drupaluser
Step 3 : Configure durpalSG security group allow EC2 instance where the Application installed by CIDR and open the Mysql port in EC2’s SG (3306) for internally connection.

Take a bckup of database

$ mysqldump    –h <>    -u <>      --database    <>    -p     > drupaldump.sql 

Now Check the connectivity of RDS and EC2 instance following below step

sudo  ssh  -i   durpal_key.pem    ubuntu@<pub-ip>

$ telnet  drupaltest.rds.us-east-2.amazon.com:3306

Restore the dump with the new drupal database.

$ myql  -h  drupaltest.rds.us-east-2.amazon.com  -u  drupaluser   --database drupaldemo   -p     <   drupaldump.sql

$ mysql –h  drupaltest.rds.us-east-2.amazon.com  –u  drupaluser   –database   drupaldemo   -p

mysql> show databases;

mysql> /q

Step 4: Install Durpal

Again login in ec2 instance by the ssh command as above  and  download the Durpal  by go to the durpal official page and download the latest version and copy the link any download by command

$  sudo  ssh  -i   durpal_key.pem    ubuntu@<pub-ip>

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

$ tar xvf    drupal*

Now go to the newly extracted directory drupal and copy the  all content to web root directory (/var/www/html) we can copy cp but we need to safely copy so we use ‘rsync

$ cd   drupal

$ rsync    -avz  *  /var/www/html

Now there are need to do some changes in drupal configuration file . so we have to copy of  default.settings.php  file in settings.php  and we need to make change in setting.php file for Database’s configuration.

$ cd   /var/www/html/sites/default 

$ cp  default.settings.php  /var/www/html/sites/default/settings.php

$ sudo chmod 664 /var/www/html/sites/default/settings.php

Next, we need to give group ownership of our files to the web user, which in Ubuntu is www-data. We want to give the entire Drupal installation these ownership properties:

$ sudo   chown  -R    :www-data            /var/www/html/*

 Step 5 :

We need to cross check or test all configuration and  services which I had done and security, logs root etc  Again restart all services 

$ sudo service apache2 restart

$ sudo service   php   restart 

 Now server are configured with drupal (CMS)  

Step 6 :

The remaining installation will be from the web browser now open the browser and type url http://<ip&gt; or server_doamin (local host) There will be open a page of Drupal installation profile  like

durpal_config

Choose Profile –    standard    (save and continue)After one or more than one step we get the Database configuration Page Fill the all details which have created and click on save and continue. DB name, Password, DB_User  Click the “Save and Continue” button a final time to complete the installation.

Now we have successfully complete the configuration of a Drupal site and you can now visit your site by going to your domain name or IP.
installed_site
It is configuration for Drupal Website for one Instance from above steps. If we need to install and configuration on  group of servers-Instances we need of Automation. 

Ansible – configuration management toolsCreate paly book for installation Apache Php etcBash Script – Make scripts for drupal .

Drupal- Scalable and Performance

For high performing Drupal website with proper caching, CSS and JS compression, optimized images etc. We take systematic approach and leveled planning to deliver sustainable end-product, like:

  • Adding complexity incrementally
  • Scale vertically first
  • Focus on users not system administrators
  • Code optimization

Thank you i hope you enjoyed it.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s