Wednesday, 31 July 2013

Insalling Liferay on Amazon Cloud - Step by Step

It was fun installing Liferay on Amazon. My happiness had no bounds when I saw the cost that I am going to incur at Amazon and the robust infrastructure it offers.
You will find tons of articles on Amazon Cloud and its features and hence I will not spend time here explaining the same. Instead I prefer delving directly into what you need to do in order to setup liferay on Amazon Cloud. I will document the entire procedure in a step-by-step format.

Apache2, Liferay 6.0.5, MySQL & phpmyadmin

1.    Create an account at Amazon and subscribe for ec2 service. It will ask credit card info. Do not worry, you will be billed only when you start using the service. In the process of creating an account you might have definitely received a .pem file which contains the security information. Amazon does not allow connecting to the instance using user and password instead it uses this identity file (.pem) to identify the user logging on to the system.
2.    Go to AWS Management Console (Amazon Web Service Management Console) and select the EC2tab. This tab is used to create a new Amazon EC2 instance.
3.    Launch a new instance by selecting ami-a6f504cf as the AMI (Amazon Machine Image). You can search for this image under Community AMI(s). This is a small instance with 1.7 GB of RAM (ubuntu server) which is quite sufficient for Liferay 6.0.5.
4.    Also ensure that you select the right location of your instance; it does affect your billing. I being from India, have selected: us-east-1b
5.    Create an Elastic IP from the Elastic IP section and associate it to the instance created. Now you will be able to access your server instance using the IP address created in this process say : 50.19.110.20 for e.g. Through out this tutorial I will now consider that this the I.P address of your instance.
6.    Connect to the instance using ssh specifying the identity file as follows:
ssh -i /ec2/AmazonKeyPair.pemubuntu@50.19.110.20 (On my mac machine I have saved AmazonKeyPair.pem in ec2 folder.
7.    Once you are get access to the machine, you can start installing the required software
8.    Installing the software(s)
          I.        First you need to ensure that existing components are up-to-date and hence need to run apt-get -y update
         II.        Also run
apt-get -y upgrade and
apt-get -y install build-essential
       III.        It is not advisable to run tomcat on port 80. Instead you can run tomcat behind apache2 server. In order to install apache2 server run
apt-get -y install apache2
       IV.        You will also need the sun java sdk
apt-get -y install sun-java6-jdk
        V.        Now you must install mysql 5.x so that you can point your liferay server to this database. Run
apt-get -y install mysql-server-5.0 (Set the password for the database when asked for)
       VI.        If you want to test the mail server and send a test mail, then do the following:
apt-get -y install mailx
Test the installation as follows:
echo "The data is successfully copied to S3" |mailx -s "Data Backup to S3 successful"youremailaddress@youremaildomain.com
Check whether you receive the mail to the email address specified above.
     VII.        Change the date to the timezone you want using
dpkg-reconfigure tzdata
9.    You can now download phpmyadmin and make the application available through apache2
apt-get -y install phpmyadmin
          I.        Open apache2.conf and put the following as last line
Include /etc/phpmyadmin/apache.conf
         II.        Check with http:// 50.19.110.20/phpmyadmin. You must get a page which asks the username and password to MySQL Server.
10. Installing Liferay: You can download the latest bundle of liferay from liferay.com. However, I have uploaded the Liferay Bundle that was there on my local machine to Amazon instance using scp. I zipped the entire folder of my liferay bundle and uploaded and also took the back up of complete database from local machine and uploaded it to the MySQL instance running on Amazon instance.
11. MySQL table names: MySQL server on ubuntu is automatically configured to be case-sensitive. If you have created database structure with mixed case or upper case on your local machine (windows or mac) and have backed up the database and uploaded it on MySQL on any linux based machine, then your application will fail. This is because in your application you might have used the name of the table in the mixed case where as sql will say that the table does not exist because it searches for the name of the table exactly in mixed case. In order to work-around this problem, you have to make the following setting:
In etc/mysql/my.cnf file look for the section [mysqld]. Under that section add the following after skip-external-locking
lower_case_table_names = 1
For detailed explanation on this refer to : http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html

Configuring jk mod to make apache2 proxy for tomcat

JK Mod: This is a module that sets up apache2 as a proxy server for tomcat.
1.    apache2.conf file: Add the following in apache.conf in /etc/apache2
JkWorkersFile /etc/apache2/workers.properties
JkShmFile /var/log/apache2/mod_jk.shm
JkLogFile /var/log/apache2/mod_jk.log
JkLogLevel error
JkRequestLogFormat "%U %q "
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkMount /* tomcat
2.    workers.properties: In /etc/apache2, create a file called workers.properties and add the following
worker.list=tomcat
worker.tomcat.type=ajp13
worker.tomcat.host:127.0.0.1
worker.tomcat.port=8009
3.    Using no-jk: phmyadmin application is installed on apache2. Once you configure apache2 as proxy for tomcat, each and every request will land on tomcat and this would fail running of your phpmyadmin because phpmyadmin is installed on apache2 and not tomcat. So you need to tell apache2 that all calls like http://www.<domain-name>/phpmyadmin/* must not use mod jk. In order to achieve this, open /etc/apache2/sites-available/default file and the following entry just below DocumentRoot /var/www

JkMountCopy On
SetEnvIf Request_URI "/phpmyadmin/*" no-jk
4.    Rewrite module: You will notice on many web sites that the request to web sites without www will result in a redirect with www.<domain-name>.com. Check this out: On the address bar of your web browser type oracle.com and hit the enter key. You will notice that it redirects to www.oracle.com. If you wish to do the same with apache2 then, in /etc/apache2/sites-available/default file write the following towards the end of the file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mslearningandresearch\.com$ [NC]
RewriteRule ^(.*)$ http://www.mslearningandresearch.com$1 [R=301,L]

In the above snippet I have mentioned my domain name, you replace it with your domain name.
You will have to do two more important things before things work as per your expectations and which is as follows:
a) Change AllowOverRide None in /etc/apache2/sites-available/default toAllowOverRide All (or something else, but not None)
b) Run the command (ensure that rewrite.load file is present in mods-available folder)
a2enmod rewrite

5.    Restart apache2 service by running the following command
service apache2 restart

PS: If you are running a multiple portal instances as I am running (mslearnignandresearch.com and liferayaddict.com) then do not forget to make the following entries in your portal-ext.properties file :

web.server.http.port=80
auth.token.check.enabled=false
redirect.url.ips.allowed=127.0.0.1,50.17.221.17
redirect.url.security.mode=domain
redirect.url.domains.allowed=www.mslearningandresearch.com,www.liferayaddict.com


No comments:

Post a Comment