Last days I worked a lot trying to run Liferay in the Cloud with using new CloudFoundry service, just announced by SpringSource and want finally share my experience
What we had before
Until last days there was no proper way to launch Liferay in the Cloud environment (including such features like Auto-Scaling):
- It was discussion in Liferay Forum about possibility to run Liferay in Google AppEngine Environment. Speaking about me - I'm very skeptic about it - liferay is closely related to Hibernate and SQL-based database - and - I do not see a way to run it on top of Google DB;
- Of course it is possible to prepare own AMI to run in Amazon EC2, but, in that case you should also care about all configuration issues, autoscaling and so on;
- Some services, provided "Java in the Cloud" - like stax or Mor.ph was not able to run Liferay because of memory-limitation (in fact, Liferay required quite a lot of memory)
So, only one way I see - is to run Liferay in EC2, but - cannot say it is easy way (many configuration need to be done by hand)
CloudFoundry
CloudFoundry is a new service, just launched by SpringSource few days ago. OK, that service already presented for some time, but currently acquired by SpringSource and they started new promotion for that service. On two words - CloudFoundry is set of preconfigured AMIs to run on Amazon EC2, with services required to run Java Application run, plus comfortable web-console to deploy, run & control your web-application, plus monitoring with using Hyperic.
AMIs has everything you need:
- Front-End HTTP server (Apache), which also working as load-balancer in multi-instance topology
- Back-End application Server (tomcat 5.5 or Spring tc 6 servers plus some bonuses)
- MySQL DB (with possibility to configure Master-Slave connection with extra MySQL )
All of these come preconfigured and ready to use - with many options like topology (single-instance or multi-instance), AutoScaling (available only for multi-instance topology), using different ways to store MySQL DB (in local instance FS, on EBS Volume), automatic periodical backups for used EBS volumes and so on and so on.
Currently CloudFoundry working on top of Amazon AWS (but in future it is supposed to work in Private Clouds, based on VMWare technologies) with using user's credentials - so, user should pay for all Amazon services, but - user also has control on everything:
- All data stored on user's S3 or EBS and may be easily copied
- Servers run in user's EC2 instances, so, user can login via ssh and do any additional configuration
Liferay in CloudFoundry
Then I read about CloudFoundry I decided to try to run Liferay in it. In general - it runs, but with some limitations, tricks and one surprise :)
So, to run liferay you need:
- register in CloudFoundry and configure your AWS account settings
- You need to download latest liferay war from SourceForge and zip with liferay dependencies
- place portal-ext.properties into liferay.war - it is required to configure liferay to use correct DB connection. In my case it has followed properties:
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://dbmaster/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=lportal
jdbc.default.password=lportal
liferay.home=/usr/share/tomcat5
Here you configured Liferay to use MySQL database on dbmaster server (dbmaster is a special host-name pointed to where mysql server is run). Of course you can specify own username, password and theme name.
Also - need configure liferay.home to store liferay files in folder with right-permissions.
- Unzip dependencies, remove hsql.jar from jars, and add mysql-driver jar, jta.jar and mail.jar
- Pack dependencies again, but so, all jars are placed in root folder in zip (not in subfolder)
Ok in general - you are ready to run Liferay in CloudFoundry
Run Liferay in CloudFoundry

Now, go into CloudFoundry web-console and "Create Application". In opened wizard set followed values:
- Application Name - any you like, for example Liferay
- JVM Options: -Xmx1024m -XX:MaxPermSize=256m -Dfile.encoding=UTF8 -Duser.timezone=GMT -Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false
- WAR File - Select liferay war (with portal-ext.properties inside)
- Context Path: ROOT
- Database Name, User Name, Password - use same as were used in portal-ext.properties (in my case lportal, lportal, lportal)
- Shared JARs: select Deploy and add you dependencies archive
- Press "Save"
Application is ready - now, we can deploy it into the cloud - go to "Deployments" tab create new Deployment:
- Enter Any Name for Deployment you like
- Topology: select "Single Instance" - we will discuss multiple instances later
- Public IP: select some if you like
- Container: Select Tomcat 5.5.23 or tc
- Database Storage: use Local for experiments, but, for production system you should keep in mind - Local DB will be lost if instance will stop, so, it is better to use "New EBS Volume" - and configure size for new volume (as well as backup)

What is all - press "Deploy" wait some time (5-10 minutes) - and you should have your Liferay run. Later you can manage run instance, restart different services, monitor the state.
Multiple Instances Topology
To run Liferay in multiple instances topology Liferay should be correctly configured to work in clustered environment - cache settings, jack-rabbit settings, also, I think it make sense to configure Lucene to keep search index in DB (to be available between different instances). I will discuss it in later post
Surprise?
During creating new deployment I found very interesting item in "Container" drop-down: Liferay. After clarifying in CloudFoundry forum, and playing a little bit I found - yes, CloudFoundry already have Liferay preinstalled! In that case, it is expected user use portlet war during application creation to deploy later int liferay. But - there are some issues prevented from using it in production:
- Minor one - Liferay 5.2.2 used (not latest version)
- Deployment done incorrectly - portlet simple deployed into web-server (not into Liferay hot-deploy folder) - as result - some steps done by Liferay (like copy required jars & TLDs) was not done - and portlets are not usable
- Not clear how DB is configured
- Liferay used in that case is not configured to be run in Clustered Environment - so, it is not possible to use it in Multi-Instances Topology
- Liferay included some demo-portlets like 7Coz hook and WOL Portlet. They are nice for demo, but not good for production system.
Of course - all of these issues may be fixed by hand after instance is started - since we have access to the system via ssh, but - it is not "Out-Of-Box" solution
Price
Of course, since user's AWS credentials used, user should pay for all Amazon services. CloudFoundry itself is free - at least during beta-stage. I hope after it will not be too expensive.
Conclusion
I think CloudFoundry is a very interesting project. As soon as it can run Liferay - it may run any java-applications (not used J2EE technologies like EJB and so on - since only tomcat server is used for now).
Speaking about Liferay on CloudFoundry - it is especially interesting having Liferay as container - but, Liferay support should be improved. I think it make sense for Liferay team to help CloudFoundry community to complete this job - because I think it will be helpful collaboration for all sides: CloudFoundry will get properly-configured Liferay, Liferay may provide to end-users "Enterprise Edition" and charge money via CloudFoundry.