Setup liferay 6.2 on EC2 ubuntu instance with Apache2


Recently We are deployed our application named TOURFILLA(Travel social networking site, ) on AWS EC2 instance. For doing that I refer a plenty of blogs and experiment on that , really J ., Finally we did that. So I decided to write a blog about the way which working for me.

In this blog, I am trying to explain how to install oracle JDK in Ubuntu environment , how to setup and run Liferay 6.2 Tomcat server, how to install and Liferay Tomcat with Apache2,  how to write re-direct rules and how to make apache to serve static files directly rather than having to go through Tomcat.

This blogs assumes that you have already setup amazon EC2 Ubuntu 14.04 LTS instance. It doesn't go through how to setup Ubuntu Server 14.04 LTS on a EC2.

Connect the amazon instance using ssh, once you are get access to the machine, you can start installing the required software.

1.       Installing Oracle JDK

  The Oracle JDK is the official JDK; however, it is no longer provided by Oracle as a default installation for Ubuntu.

To install any version, first execute the following commands:


sudo apt-get update

sudo apt-get install python-software-properties

sudo add-apt-repository ppa:webupd8team/java

sudo apt-get update


for install oracle jdk7 run,

sudo apt-get install oracle-java7-installer


When there are multiple Java installations on your instance, the Java version to use as default can be chosen. To do this, execute the following command:


sudo update-alternatives --config java

after running that command , if you have 2 installations it will show you, so you can choose one you prefer.


More details on how to install JDK on Ubuntu environment I personally recommend you to refer following url;


2.       Download the latest bundle of liferay from or upload from your system.


To download the latest bundle of liferay from sourceforge, execute the following commands :


sudo wget


To unzip:

sudo unzip


Then navigate to inside bin directory and start liferay server using,


sudo ./


After server starting process completed , you can access liferay tomcat on browser usin user instance public ip:running port number of the server. In my case is my public ip,

through out this tutorial I will now consider that this the I.P address of your instance. So I can access it http://

Now our prime focus is to make available our server by typing http:// instead of http:// in the browser. For doing that we have two way.


  Way 1: We have to make your portal server running on port 80 by just modifying server.xml

  And  change the line <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" />


Connector port to 80.


And restart the server, now you can access liferay by using     BUT IT IS NOT ADVISIBLE TO RUN TOMCAT ON PORT 80. INSTEAD YOU CAN RUN TOMCAT BEHIND APACHE2 SERVER. So our next step is to install Appache2. Now I assume that liferay server running in 8080 port.


Way :2 Fronting Liferay Tomcat with Apache2



3.       Download Apache2 and run

For downloading appach2 run command:


sudo apt-get install apache2


After successful installation you can access appache2 page by entering

http:// . So far so good..


Our next step is to make Liferay tomcat server  front-ended with appache2. Which simply means if we access usin http:// url we need to show our liferay portal page instead of apache2 landing page.


4.       Fronting Liferay Tomcat with Apache2

Install Mod Jk

sudo apt-get install libapache2-mod-jk


then restart the apache2

sudo service apache2 restart

Edit or create the /etc/apache2/ file

Add following line into /etc/apache2/ file,






apache2.conf file: Add the following in apache.conf in /etc/apache2


JkWorkersFile /etc/apache2/

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


then restart the apache2

sudo service apache2 restart


When restarting the Apache web server, it's possible that you may get a JkWorkersFile only allowed once error message after making that last modification to apache.conf; that's because the workers file has been defined elsewhere.
If that happens, you can check the mods-available directory for the jk.conf file, which will contain an entry to the JkWorkersFile directive. The directive will specify where file is located, and you can edit it to either add your own worker configuration to it, or, what is more likely, to use a worker that's already defined there that takes care of the AJP connector.
In that case, all you have to do if undo the changes you made to the apache2.conf file, and reference the worker in the 000-default file. That step is covered in the next section.


# enable mod_proxy and mod_proxy_ajp for httpd

sudo a2enmod proxy proxy_ajp

sudo service apache2 restart


000-default file: Add the following in apache.conf in /etc/apache2/ sites-enabled/000-default

Before the end of VirtualHost tag, place the ProxyPass and ProxyPassReverse with the appropriate path to the target tomcat app.


      # this will forward the requests to /my-app to tomcat7

      ProxyPass /my-app ajp://localhost:8009/my-app 

      ProxyPassReverse /my-app ajp://localhost:8009/my-app 


      # this will pass all the requests from httpd to tomcat7

      ProxyPass / ajp://localhost:8009/

      ProxyPassReverse / ajp://localhost:8009/


   Then save and close the file.And restart the apache httpd server

   sudo service apache2 restart


Now you can access your liferay portal usin http:// url instead of http:// Liferay tomcat is now front-ended with Apache!! Cheer up smiley


5.  Make Apache2 to serve static content


First copy the /opt/liferay/tomcat/webapps/ROOT/html directory to Apache's htdocs directory, /var/www/localhost/htdocs in my case. You should also copy all of the other webapps directories (all except for ROOT) to the htdocs directory. By copying all of these directories, any incoming requests for static content will be handled by Apache rather than Tomcat.


default_vhost.include file: Add the following in default_vhost.include in /etc/apache2/vhosts.d/default_vhost

<IfModule jk_module>

  JkMount /* ajp13


  JkUnmount /*.jpg ajp13

  JkUnmount /*.jpeg ajp13

  JkUnmount /*.gif ajp13

  JkUnmount /*.png ajp13

  JkUnmount /*.ico ajp13

  JkUnmount /*.css ajp13

  JkUnmount /*.js ajp13



By using JkUnmount, you're indicating to Apache that it should handle requests with the given extension(s) rather than passing them through to Tomcat.

Then restart apache2 sudo service apache2 restart


I hope my blog will help someone who struggles with EC2 lifery setup..


 My sincere thanks to My Ahamed Hasan , David H Nebinger and Muhammed Shakir for their blogs and forum post.

And I am strongly recommend to refer following links,





Muhammed Shafeek


With these instructions, you'll have Tomcat and Liferay running as root - you don't want this - rather run as an unprivileged user.
Can you guide me sir for running tomcat as an unprivileged user ?..
I'll run a workshop at the NAS symposium. It will be summarized in a blog post later - as I'm expecting various participants to bring in their own additions and policies.
Here you are - the documentation to not run as root (also check the related articles):
Excellent post !!!
It is mandatory or optional configuration of the static content?