Vagrant, Apache, Tomcat, OpenCms en


Hi all, This is mostly a vagrant guide for me, which may be useful for somebody. Don't be mad if there is something wrong...


First, you need to install virtualbox. Then go to vagrant home page and install get the last version of the software.


To start an environment :

$ vagrant init precise32
$ vagrant up

This will create a virtual machine based on Ubuntu Precise Pangolin (12.04 LTS 32bits).

You can ssh the box, the user is vagrant and the password is also vagrant.

opencms !

I actually used this for an OpenCms project, so I'll explain here the steps to get a working installation of OpenCms (with Apache, Tomcat etc.)

apt-get all the things !

Run the following commands :

  • sudo apt-get update retrieves the last packages informations
  • sudo apt-get install vim vim-nox installs vim (because it rocks)
  • sudo apt-get install openjdk-7-jdk installs java 7
  • sudo apt-get install mysql-server installs mysql (it asks for a password for the root user)
  • sudo apt-get install tomcat7 tomcat7-admin installs tomcat7

That's all we need for now !

tomcat configuration

Edit the tomcat configuration with sudo vi /etc/tomcat7/server.xml to add:


mysql configuration

Edit the mysql configuration with sudo vi /etc/mysql/my.cnf to change this line :

max_allowed_packet = 64M

The default value is 16M, which means you can't upload files bigger than 16M into OpenCms. 64M is a large but reasonable value.

Connect to mysql with mysql -u root -p and enter your password.

Create a database for your new project (reference):


Create a user with nice permissions for this database (reference):

CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';

It's time to restart mysql with sudo /etc/init.d/mysql restart

opencms, finally !

Create a "www" folder with mkdir www, then cd www to go into it and run :


This is the current version, check the link on OpenCms home page. Unzip the file.

It's time to restart tomcat with sudo /etc/init.d/tomcat7 restart. It will deploy the opencms.war file.

Run sudo vi /etc/hosts to add:

  • back-leproject.ehret
  • leproject.ehret

Run sudo chmod -R 777 opencms in the "www" folder to give full right to Tomcat (it's a development platform, so who cares ?).

You can go now to http://back-leproject.ehret:8080/opencms/setup to install OpenCms. Once installed, you can go to http://back-leproject.ehret:8080/opencms/opencms/system/login with user name Admin and password admin.

i can has moar ?

Yes. We're going to set nicer urls and hide tomcat behind apache.

opencms configuration

Run the following commands :

  • cd ~/www to go in the folder where OpenCms is installed
  • mv opencms ROOT to rename opencms root folder

While you are in the "www" folder, edit the opencms configuration file with vi ROOT/WEB-INF/config/opencms-system.xml and update the following:


This will enable the "http://back-leproject.ehret" url to reach the OpenCms Workplace, and a "http://leproject.ehret" url for the frontend.

If you are still in the "www" folder, edit another opencms configuration file with vi ROOT/WEB-INF/config/opencms-importexport.xml and update the following:

  • to

apache / tomcat connection

We don't want to use the 8080 port ! First, install apache2 and mod_jk :

  • sudo apt-get install apache2 installs apache
  • sudo apt-get install libapache2-mod-jk installs apache / tomcat connector

tomcat configuration

Edit the tomcat configuration with sudo vi /etc/tomcat7/server.xml and uncomment the following line:

Also, update the server declaration like :


apache configuration


You can edit the worker properties with sudo vi /etc/libapache2-mod-jk/ I actually only changed the path to tomcat and the jvm. The default name is "ajp13_worker".


Create a new file with sudo vi /etc/apache2/sites-available/leproject.ehret with the following content:

  ServerName back-project.ehret
  ServerAlias project.ehret

  DocumentRoot /home/vagrant/www/

  # Possible values include: debug, info, notice, warn, error, crit,
  # alert, emerg.
  LogLevel warn

  CustomLog ${APACHE_LOG_DIR}/access.log combined

  JkMount /opencms/* ajp13_worker
  JkMount /export/* ajp13_worker
  JkMount /resources/* ajp13_worker
  JkMount /manager/* ajp13_worker

  RewriteEngine On

  RewriteCond %{REQUEST_URI} \/export\/(.*)
  RewriteCond /home/vagrant/www/ROOT%{REQUEST_URI} -f
  RewriteRule .* /ROOT%{REQUEST_URI} [PT]

  RewriteCond %{REQUEST_URI} !^/opencms/.*$
  RewriteCond %{REQUEST_URI} !^/export/.*$
  RewriteCond %{REQUEST_URI} !^/resources/.*$
  RewriteCond %{REQUEST_URI} !^/stats/.*$
  RewriteCond %{REQUEST_URI} !^/manager/.*$
  RewriteRule .* /opencms%{REQUEST_URI} [QSA,PT]

Then run cd /etc/apache2/sites-enabled/ and sudo ln -s ../sites/available/leproject.ehret to enable the site in apache.


  • Restart tomcat with sudo /etc/init.d/tomcat7 restart
  • Restart apache with sudo /etc/init.d/apache2 restart

You should be able to reach the back office at http://back-leproject.ehret/system/login and the front at http://leproject.ehret/.