Amazon Lightsail is the easiest way to get started with AWS for developers who just need virtual private servers. Lightsail includes everything you need to launch your project quickly – a virtual machine, SSD-based storage, data transfer, DNS management, and a static IP – for a low, predictable price.This is one of the latest offerings from Amazon Web Services. With the help of Lightsail, you can avoid all the low level plumbing of hosting an EC2 instance but rather spin off your instances at real rapid speed. To know more about this service you can have a look at this blog.
In this blog, i am going to give you the most simplistic steps required to launch Liferay 7/DXP on Amazon. Many of us would have done a similar hosting with Amazon EC2 but this hosting is even simpler. The objective of this blog is to document those steps so that any one that wants Liferay 7/DXP production instance up and running in the least possible time can make use of the steps.
Creating your Lightsail Instance:
All you need to get your first instance with Lightsail is an AWS account. If you do not have an account already, create one by visiting https://aws.amazon.com. Once you have successfully created your AWS account, login to the AWS Management Console. From the Management Console, click Lightsail under "Compute" category.
This will open a new window with the Lightsail dashboard. This dashboard is the one-stop shop to create, manage and monitor your Lightsail instances. You can click on the "Create Instance" button to get started with your first instance. For hosting Liferay you need at least an instance with atleast 2GB RAB of any Operating System of your choice. My OS preference is usually Ubuntu 16.04 LTS.
In less than a minute you will see your Virtual Machine up and running. It would have assigned an IP address by default and also keep some ports opened to access the instance from outside the world. Right from this dashboard, you can also invoke the server console by clicking the button "Connect Using SSH". But for matured systems administrators this might not be the right approach.
Connecting to the Instance:
Seasoned server administrators would usually prefer connecting to this newly created instance from a conventional command prompt (non-windows) or from putty client (windows). For both these approaches you need the private key. Download the private key from the "Account" page. There will be one Default private key. It will get downloaded as a ".pem" file. Once it is downloaded keep it in a secure location and also change the permission to this file by tying the command,
>chmod 400 sample.pem
Rename "sample.pem" to the actual file name that you have downloaded. After changing the permissions you can remotely connect to your instance with the command,
>ssh -i sample.pem ubuntu@IP-ADDRESS
Replace the IP-ADDRESS with the actual public IP address of this instance provided by Lightsail. For the first time while connecting through SSH it will ask you to allow the access and you should type in "yes". In case of windows, you will have to upload the PPK file in the putty client. There are tools available to convert your ".pem" file to ".ppk" file. You can do this with the help of a tool called PuttyGen. Once you have successfully connected to your instance through SSH you should see the following screen.
Preparing the Ground:
Now that you have successfully connected to your Lightsail instance, you have to do the following eight things as a "root" user. In order to switch the user as root, give the command,
1) Update & Upgrade the OS
The first thing is to get the patches and update the operating system. Run the command,
Once the packagas are updated, now run the command to upgrade the OS with the latest set of packages
After you have performed an upgrade, it might ask you to restart the system. You can do this either from the Lightsail console by clicking the "restart" menu item or issuing the command "
init 6" from the command prompt.
2) Changing TimeZone
Based the country and locale that you want to host your Liferay 7/DXP change the TimeZone. On a Linux system, this can be done by the command,
You can set the timezone in the resulting screens.
3) Install Apache2 WebServer
Apache is the most commonly used Web server on Linux systems. Web servers are used to serve Web pages requested by client computers. All the requests to Liferay will be routed through Apache. For installing Apache2, use this command,
>apt-get -y install apache2
Apache Webserver listens on port 80 which is opened by default on your Lightsail instance. To test apache is successfully intalled. Open a web browser and type the IP-ADDRESS of your VM. You should get this page.
4) Enable Apache Module "proxy_ajp"
The next step is to connect Apache2 with the Tomcat (Liferay). We are going to establish this connection with the help of an Apache module called "proxy_ajp". First you need to enable the module by issuing the command,
Once it is enabled successfully, you have to create a file named "proxy_ajp.conf" under "/etc/apache2/conf-enabled" folder and put these two lines,
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
Save and close the file. Restart Apache by running,
>service apache2 restart
To confirm that the proxy_ajp module is enabled and configured properly, open the brower and type the IP-ADDRESS. You should get the following message.
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
Apache/2.4.18 (Ubuntu) Server at 18.104.22.168 Port 80
The proxy_ajp module is trying to invoke the Tomcat (Liferay) server on the back. But the Tomcat (Liferay) is still not installed, this message is justified for the time being.
5) Install MySQL Database
The next step is to install and configure MySQL Database to hold all Liferay tables. This can be done with the command,
>apt-get -y install mysql-server
During the installation of MySQL you will be prompted to set the password for the mysql user "root". Give the password of your choice. After the successful installation of MySQL, get inside the MySQL prompt,
>mysql -u root -pPASSWORD
When you are inside the MySQL prompt, create an empty database,
mysql> create database lportal character set utf8;
Confirm that the database is created nicely. You can "exit" from the prompt back to the shell.
6) Install Java Runtime Environment
Liferay is purely based on Java and all it needs to run is a JRE. Lets install the default JRE that comes with Ubuntu Operating System with the command,
>apt-get -y install default-jre
Lets confirm that the JRE is installed properly by issuing the command,
It should display the below result,
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-2ubuntu1.16.04.3-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)
Great, you are done with the installation of JRE.
7) Install MailUtils
We need the ability for Liferay to fire emails from the portal. For this we need to setup the SMTP server. This can be done with the command,
>apt-get -y install mailutils
At the time of installation of the postfix mail server, it will ask you to select the type. Go with the option "Internet Site". Confirm that the email server is configured properly, by sending a test mail from the command line,
>echo "My message" | mail -s "subject" email@example.com
8) Install Unzip Utility
This is the last and final step. As we have to unzip the Liferay Tomcat bundle we need an unzip utility. Install it with the command,
>apt-get -y install unzip
Congratulations, you are done with all the seven steps inorder to prepare the ground. Now, it is time to install Liferay 7/DXP. Till now we have done everything as a "root" user. Exit as a "root" and switch to the "ubuntu" user.
Install Liferay 7/DXP:
This is the final thing towards getting our Liferay Portal up and running. From the home folder "/home/ubuntu" download the latest version of Liferay Tomcat bundle. You can get the link of this file by going to http://releases.liferay.com. Based on your current location you may download this file from a different mirror.
After the download of this bundle, unzip it with the command,
The whole bundle gets unzipped in the folder "liferay-ce-portal-7.0-ga4" which will be the LIFERAY_HOME. "cd" into this folder and then to "tomcat-8.0.32/bin/" for starting the tomcat server. Before starting the server you have to do one small thing. Open the file "setenv.sh" inside this folder and remove the last parameter "-XX:MaxPermSize=384m" as it is no longer required in Java 8. Now start the server by invoking "./startup.sh".
You can view the console by typing "tail -f ../logs/catalina.out". Once the server is completely started, you can open the open the browser and hit the IP-ADDRESS. You should get the Basic Configuration page of Liferay.
The last step is to complete the basic configuration. You can uncheck the option for not adding the sample data. Also point do the database configuration by pointing to the MySQL database that we have created earlier. Click "Finish Configuration". Post this you may have to restart the server again for the changes to take effect. After the second restart when you open the browser and hit the IP-ADDRESS you will land in the default landing page of Liferay 7/DXP.
Congratulations!! You have successfully setup Liferay 7/DXP on Amazon Lightsail Cloud. Enjoy playing around with the great features of Liferay 7/DXP. You just have to point your custom domain to this IP-ADDRESS in order for your website to be live in the production environment
Liferay Architect, Trainer & Consultant