The simplest way to run Liferay is to download a specific bundle from the Liferay official site. A Liferay bundle is just a compressed archive that contains all that is needed to host the Liferay Portal. A bundle consists of a Java-based application server and the deployed Liferay Portal core application. Liferay provides these bundle runtimes with different application servers (that is, Tomcat, JBoss, Geronimo, and so on) so that you can use any one based on your choice. This method is recommended for people who just want to run Liferay Portal, look at its functionalities, and configure their site using the GUI. In this recipe, you will learn the art of setting up Liferay on Tomcat and the MySQL database engine.
First, make sure that JRE or JDK is properly installed. Type the following command line:
The result should be similar to this:
Also, check out the Java SDK version. Liferay recommends Java 7 or later.
Moreover, determine whether the MySQL server installation is done:
As a result, the actual installed version should be displayed. Here is an example:
Also, check out the MySQL version. We recommend 5.5 version or later.
Running the Liferay Portal from a prepared bundle is quite an easy task to accomplish. However, it is worth knowing what exactly happens when Tomcat is being started. Take a brief look at the catalina.out
log and try to examine it line by line.
Loading the configuration descriptor
The first thing is to deploy ROOT.xml
. In our catalina.out
file, there is a line present, which is shown as follows:
It means that the configuration file turns on the crossContext
attribute in Tomcat 7. This setting is required because Liferay is a portlet container. Hence, it is an application that should have access to other applications called portlets. The Apache Tomcat documentation says:
"Set to true if you want calls within this application to ServletContext.getContext() to successfully return a request dispatcher for other web applications running on this virtual host."
Loading system properties and portal properties
The next few lines of the logfile show portal properties and system properties that are loaded from specific locations:
The main configuration file for Liferay Portal is portal.properties
, which contains a detailed explanation about the properties that it defines. There are at least three possible ways to override portal.properties
. There is a functionality to put portal-ext.properties
in the ext
plugin, in the ${liferay.home}
directory, or in portal-setup-wizard.properties
. But which file is the most important? The answer is placed in portal.properties
file. The default read order is portal.properties
, portal-bundle.properties
, portal-ext.properties
, and then portal-setup-wizard.properties
:
Detecting the database and database dialect
The next step is to recognize the database's dialect:
Liferay supports many database engines, such as DB2, Derby, Hypersonic, Ingres, MySQL, Oracle, P6Spy, PostgreSQL, and Sybase. The default database is Hypersonic, which stores all data in the ${liferay.home}/data/hsql/lportal
directory. This is a good option for developers who want to run JUnit tests, which modify data by testing the persistence layer or business process.
On every restart, Liferay tries to get the build number (Liferay version) from the Release_
table. If this table doesn't exist, it calls ReleaseLocalService.createTablesAndPopulate()
.
If it is not possible to get the build number, Liferay logs the following information:
The createTablesAndPopulate
method runs following scripts:
liferay-portal/sql/portal-tables.sql
: This creates the required tablesliferay-portal/sql/portal-data-common.sql
: This adds the default dataliferay-portal/sql/portal-data-counter.sql
: This inits the unique key generatorliferay-portal/sql/portal-data-release.sql
: This sets the release dateliferay-portal/sql/indexes.sql
: This adds database indexesliferay-portal/sql/sequences.sql
: By default, this file is empty.
Apart from creating tables and populating data, Liferay triggers the VerifyProcess
mechanism. This process will run on every startup to verify and fix any integrity problems found in the database. This is the perfect place for developers to add custom code to check the integrity of specific cases.
Starting the autodeploy scanner and deploying plugins
The last step is initializing the autodeploy and the hotdeploy listeners. In general, these mechanisms install all the plugins into the Tomcat container and register them as portlets, hooks, themes, and so on. In particular, there are at least three deploying approaches: sandbox deploy, autodeploy, and hotdeploy.
Note
By default, Liferay uses the autodeploy and hotdeploy listeners. In fact, sandbox can currently deploy only themes and portlets.
The autodeploy mechanism is responsible for listening on a specific directory to install on-the-fly new plugins and copying them into the Tomcat hotdeploy process. A definition of that directory is placed in portal.properties
, and by default, it is in the deploy
folder:
Every type of plugin has its own autodeploy mechanism. This mechanism runs all the necessary steps to install it correctly in the Liferay container. In simple terms, the autodeploy mechanism generates the web.xml
file and adds the required libraries to specific plugins. Definitions of these classes are placed in the portal.properties
file with an auto.deploy.*
prefix. Each class extends BaseAutoDeployListener
.
The second process, hotdeploy, is responsible for registering plugins in Liferay. There are many steps, such as creating database tables, setting preferences, registering Spring application contexts, and so on. Of course, each step depends on the type of plugin. In portal.properties
, there are definitions for each type of class:
Tip
In the deployment process, the Liferay deployer modifies the web.xml
file, adds specific dependencies, and packs it again. Ensure that you do not copy the WAR
file directly to the Tomcat webapps
folder. If you do so, the plugin will not work.
Often, enterprises have an established Java EE infrastructure upon which they would like to install Liferay. You must consider also the enterprise's security policies. These policies sometimes prevent the download and installation of the Tomcat bundle into a location of your choice. In this situation, a bundle will not suffice, and you have to manually install Liferay from its WAR archive into an already existing Apache Tomcat application server.
There are six steps to achieve this goal. They are as follows:
- Copy specific JAR files and dependencies to the Tomcat global
lib
folder, $TOMCAT_HOME/lib/ext
. - Enable
crossContext
by adding the ROOT.xml
file to the $TOMCAT_HOME/conf/Catalina/localhost
folder. - Set custom
$JAVA_OPTS
parameters in the $TOMCAT_HOME/bin/setenv.sh
file: - Update the
common.loader
property located in $TOMCAT_HOME/conf/catalina.properties
with the following lines of code: - Specify the URI encoding as UTF-8 in
$TOMCAT_HOME/conf/server.xml
as follows: - Deploy Liferay Portal using Tomcat manager or manually put the WAR archive into the
$TOMCAT_HOME/webapps
folder. The WAR file is available at http://www.liferay.com/downloads/liferay-portal/available-releases#additional-versions.
For information about running Liferay on the clustered environment, refer to the Clustering Liferay Portal recipe in Chapter 11, Quick Tricks and Advanced Knowledge, and the Scalable infrastructure recipe in Chapter 12, Basic Performance Tuning. For information about setting the developer's environment, refer to the next recipe.