Recently I gave a talk on deploying the Magnolia CMS on OpenShift at the Magnolia CMS annual conference in Basel, Switzerland. The talk was well attended and some fellow developers asked me if I could document the process. In this step-by-step blog post, I will show you how you can have a Magnolia CMS instance up and running on OpenShift within minutes. OpenShift is Red Hat’s open source, polyglot,and scalable Platform as a Service.
Before we can start building the application, we’ll have to do a few set-up tasks:
Basic Magnolia CMS knowledge is required. You can refer to the Magnolia CMS documentation for more information.
Basic Git knowledge is required. Git is a distributed revision-control and source code management system. For more information on Git, you can refer to this tutorial.
Sign up for an OpenShift Account. It is completely free and Red Hat gives every user three free gears on which to run your applications. At the time of writing, the combined resources allocated for each user was 1.5GB of memory and 3GB of disk space.
Install the RHC client tool on your machine. RHC is a Ruby Gem so you need to have Ruby 1.8.7 or above on your machine. To install RHC, just type
sudo gem install rhcon the command line. If you already have the Gem installed, make sure it is the latest one. To update RHC, execute the command
sudo gem update rhc. For more assistance setting up the RHC command-line tool, see the following page: https://openshift.redhat.com/community/developers/rhc-client-tools-install.
Set up your OpenShift account using the command
rhc setup. This command will help you create a namespace and upload your SSH key to the OpenShift server.
Step 1: Create Tomcat 7 Application
The biggest advantage of working with a PaaS like OpenShift is that it lets you focus on application development. Rather than configuring and managing virtual machines, you get a preconfigured application stack that is ready to be used for application development. In my talk, I asked which server people used for Magnolia deployment. The majority of people in attendance said they deployed Magnolia CMS on Apache Tomcat. So, in this blog post I will show you how to deploy Magnolia CMS on Tomcat 7 running on the OpenShift PaaS. OpenShift also supports Tomcat 6, JBoss AS7, and JBoss EAP 6, so you can use those as well.
To create an Apache Tomcat 7 application on OpenShift, type the command shown below.
$ rhc create-app magnoliacms tomcat-7
This command will create an application container for us, called a gear, and set up all of the required SELinux policies and Cgroup configuration. Next, it will install all the required software on your gear. OpenShift will also set up a private Git repository with some template code, and then clone the repository to your local system. Finally, OpenShift will propagate the DNS to the outside world.
You can view the application details using the command shown below.
$ rhc show-app magnoliacms magnoliacms @ http://magnoliacms-domainname.rhcloud.com/ (uuid: 52412e3d4xx2ecc611000052) -------------------------------------------------------------------------------------------- Domain: domainname Created: 11:46 AM Gears: 1 (defaults to small) Git URL: ssh://email@example.com/~/git/magnoliacms.git/ SSH: firstname.lastname@example.org jbossews-2.0 (Tomcat 7 (JBoss EWS 2.0)) --------------------------------------- Gears: 1 small
Step 2: Download Magnolia CMS WAR
The default application created by OpenShift is a Maven-based Java project. You can very easily do source code deployment by updating the template source code generated by OpenShift with your application source code. You can also use Ant or Gradle. However, in this blog post, we will be doing binary deployment, i.e. we will deploy the prebuilt Magnolia WAR.
Download the latest Magnolia CMS WAR file from SourceForge. We are downloading the community edition of the Magnolia CMS, but you could also use the Magnolia Enterprise edition. Download the WAR package as shown below. At the time of writing, 5.0.4 was the latest Magnolia CMS Community Edition version.
Next, remove the src folder and pom.xml file from the Git repository, as we will be deploying the WAR file.
$ git rm -rf src/ pom.xml $ git commit -am "deleted template source code"
Step 3 : Copy Magnolia CMS WAR to webapps
The template project created by OpenShift has a webapps folder. This folder is used for WAR deployment. Copy the Magnolia CMS WAR into the webapps folder. Once the WAR file is copied, rename it to ROOT.war. This will make Magnolia CMS available at the root URL.
$ cd webapps $ mv magnolia-5.0.4.war ROOT.war
Step 4 : Set unpackWARs to True
The Tomcat 7 installation created by OpenShift has the unpackWARs attribute in Tomcat’s server.xml set to false. This means that WAR files will not be unpacked, so either you deploy unpacked WAR files or override the unpackWARs attribute. According to the Tomcat documentation:
If false, the unpackWARs attribute of the owning Host will be overridden and the WAR file will not be unpacked. If true, the value of the owning Host’s unpackWARs attribute will determine if the WAR is unpacked. If not specified, the default value is true. Note that WAR files located outside of a Host’s appBase are never unpacked.
To override this value, we have to update the .openshift/config/server.xml file. OpenShift gives you the flexibility to override or update Tomcat configuration files. Update server.xml as shown below. Change
<Host name="localhost" appBase="webapps" unpackWARs="false" autoDeploy="true">
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
Step 5 : Deploy Magnolia CMS
Next, you can deploy the Magnolia WAR by committing the changes to your local Git repository and then pushing the changes to the OpenShift application gear.
$ git add . $ git commit -am "set unpackWAR to true and added MagnoliaCMS WAR" $ git push
This will take a few minutes, depending on your internet connection. Once the Git push is done, you can view the status of the WAR deployment by tailing the log files as shown below.
$ rhc tail magnoliacms 2013-09-24 03:45:40,182 INFO info.magnolia.module.ui.ModuleManagerWebUI : ********************************************************************************************************* * * * Magnolia needs module updates or installs, point your browser to your Magnolia instance and confirm ! * * * ********************************************************************************************************* 2013-09-24 03:45:40,182 INFO info.magnolia.cms.i18n.DefaultMessagesManager : Loading i18n configuration - /server/i18n/system 2013-09-24 03:45:40,183 WARN info.magnolia.cms.i18n.DefaultMessagesManager : /server/i18n/system does not exist yet; skipping. 2013-09-24 03:45:40,183 INFO info.magnolia.cms.i18n.DefaultMessagesManager : Registering event listener for i18n 2013-09-24 03:45:40,186 INFO info.magnolia.cms.beans.config.MIMEMapping : Initializing MIMEMapping from /server/MIMEMapping 2013-09-24 03:45:40,194 WARN info.magnolia.cms.beans.config.MIMEMapping : No MIMEMapping info configured at /server/MIMEMapping 2013-09-24 03:45:40,194 INFO info.magnolia.cms.beans.config.MIMEMapping : Registering event listener for MIMEMapping 2013-09-24 03:45:40,196 INFO info.magnolia.cms.beans.config.ConfigLoader : Configuration loaded (took 39 seconds) Sep 24, 2013 3:45:40 AM org.icepush.EmailNotificationProvider$AutoRegister contextInitialized INFO: ICEpush Email Notification Provider Registered. 2013-09-24 03:45:40,268 INFO info.magnolia.cms.filters.FilterManagerImpl : Initializing filters 2013-09-24 03:45:40,268 INFO info.magnolia.cms.filters.CompositeFilter : Initializing filter [Wrapper for ClasspathSpool Servlet servlet] 2013-09-24 03:45:40,280 INFO info.magnolia.cms.filters.CompositeFilter : Initializing filter [install] Sep 24, 2013 3:45:40 AM org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler ["http-bio-127.4.201.129-8080"] Sep 24, 2013 3:45:40 AM org.apache.catalina.startup.Catalina start INFO: Server startup in 65724 ms
Step 6 : Install Magnolia Modules
Once the deployment in finished, open the browser and go to http://magnoliacms-domainname.rhcloud.com and install Magnolia modules by clicking the “Start install” button.
After you press the “Start install” button, you will start seeing installation progress.
Step 7 : Start up Magnolia
Once all the Magnolia modules are installed, you will see a screen as shown below asking you to start Magnolia. Press the “Start up Magnolia” button.
Finally, you will be forwarded to the login page, where you can sign in to the Magnolia CMS using “superuser/superuser” username/password credentials.
Step 8 : View the Magnolia CMS Demo Project
Sign in to the Magnolia CMS using superuser credentials and then go to http://magnoliacms-domainname.rhcloud.com/demo-project. Please replace domainname with your own OpenShift domain name. You will see the demo project as shown below.
Step 9 : Publish Your First Page
Before we can publish our first change, we have to make a couple of configuration changes. Go to Magnolia CMS admin central at http://magnoliacms-domainname.rhcloud.com/.magnolia/admincentral and click on “Configuration”.
Once you are on the configuration tab, you need to update the defaultBaseUrl property (server > defaultBaseUrl) as shown below. Replace shekhargulati with your own domain name.
Next you need to update the active subscriber URL (server > activation > subscribers > magnoliaPublic8080 > URL), as shown below.
Publish the changes.
Next, go to the Pages app and under demo-project add a new page as shown below.
To publish the page, click on “Test Page” and click “Publish” as shown below.
Go to http://magnoliacms-domainname.rhcloud.com/demo-project and you will see the test page published, as shown below.
That’s it for this blog post. Happy Publishing!