Installation

We used Liferay on Apache Tomcat, so it has to be installed first. Tomcat requires Java, but we did not want to use sun-jdk, mostly because of the fact that there are so many archives needed to download manually in order to install it on FreeBSD.
We used java/diablo-jdk16 port, which required only to download two packages manually.

Install Java

# cd /usr/ports/java/diablo-jdk16
# make install clean
Please access
     http://www.FreeBSDFoundation.org/cgi-bin/download?download=diablo-caffe-freebsd7-amd64-1.6.0_07-b02.tar.bz2
 with a web browser and "Accept" the End User License Agreement for
 "Caffe Diablo 1.6.0".
 Please open http://www.oracle.com/technetwork/java/javase/downloads/index.html
 in a web browser and follow the "Download" link for
 "JDK DST Timezone Update Tool - 1_3_45" to obtain the
 time zone update file, tzupdater-1_3_45-2011n.zip.
 Please place the downloaded file(s) in /usr/ports/distfiles.

Accept, download, build and install.
Unfortunately all Java ports install bunch of X11 related packages. And that is even when WITHOUT_X11=yes is set in /etc/make.conf. There has been many mailing threads in the net about this, but every port has something like USE_XORG+= xi xp xt xtst in their Makefile, because AWT uses those libs, so there is nothing reasonable to do about it.

Install Tomcat

# cd /usr/ports/www/tomcat7# make install clean

If you do not install Java first, it defaults to java/sun-jdk.

Configure Tomcat Startup

The FreeBSD port installs all the files into the /usr/local/apache-tomcat-7.0. Since I don’t like the idea of having all the temporary files (Tomcat’s temp and log directories) in my /usr partition, I decided to move them to /var instead.

# mkdir /var/log/tomcat
# chown www:www /var/log/tomcat

Now set up the proper variables in /etc/rc.conf:

tomcat7_enable="YES"
tomcat7_catalina_tmpdir="/var/tmp"
tomcat7_catalina_log=">> /var/log/tomcat/catalina.out 2>&1"
tomcat7_java_opts="-XX:MaxPermSize=256M"

Liferay needs the -XX:MaxPermSize=256M otherwise Tomcat will run out of memory when initializing the Liferay’s database.

Enable Access to Admin Console

By default there are no users which are allowed access to Tomcat’s web console located under http://domain.tld:8080/manager/html and http://domain.tld:8080/host-manager/html.
Edit /usr/local/apache-tomcat-7.0/conf/tomcat-users.xml:

<role rolename="manager-gui" />
<role rolename="admin-gui" />
<user username="tomcat" password="my_password" roles="manager-gui,admin-gui" />

Now start the Tomcat from /usr/local/etc/rc.d/tomcat7. The default website should be displayed on port 8080.

Install Liferay

Download the war-file from Liferay Download section. Install the package into Tomcat. We decided to copy the file into the Tomcat’s /usr/local/apache-tomcat-7.0/webapps directory. The server instance found it and extracted it automatically. The admin console should display the Liferay webapp in stopped state. Starting it will fail.
Liferay needs some external libraries to function properly. Although there is a link in their website where the support libraries can be downloaded, some of them still seem to be missing from that archive. So it will fail again even with the Tomcat Bundle installed. The solution for us was to download the entire Liferay Tomcat package from the main download page.
Extract it, and copy the whole tomcat7/lib/ext directory to /usr/local/apache-tomcat-7.0/lib.
Now edit the /usr/local/apache-tomcat-7.0/conf/catalina.properties file to instruct Tomcat to load all the JAR-files from that directory as well:

common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar,${catalina.base}/lib/ext,${catalina.base}/lib/ext/*.jar

Note that on FreeBSD the base directory is stored in ${catalina.base}. The Liferay archive has the same common.loader line with the variable ${catalina.home} which will not reference to proper location.

Set Up Liferay Environment

Since Liferay is running on Tomcat as one of the webapps with the root context of /liferay, the URL suffix must be specified in Liferay’s configuration file. Otherwise the links generated by it will not point to proper location.
We also configured Liferay’s working directory where it can put all the files it generates.
So create the working directory:

# mkdir /srv/liferay
# chown www:www /srv/liferay

Then create Liferay’s preferences file /usr/local/apache-tomcat-7.0/webapps/liferay/WEB-INF/classes/portal-ext.properties:

liferay.home=/srv/liferay
portal.ctx=/liferay

Now start the Liferay webapp from the admin console. The catalina.log should show what’s going on. It will take some time to create the initial database but eventually the http://domain.tld:8080/liferay/ should display the basic configuration dialog for initial setup.