Archive

Archive for November 16, 2011

Adding new sites to Railo demystified

November 16, 2011 5 comments

One of the questions that comes up quite often on the Railo Google Group is how to add sites to Railo after the initial installation. I can understand the frustration many new users feel because I was in their shoes many moons ago. I will agree that ACF does a fair bit of magic with the JRun connector, but with a little know how you will have your sites up and running in no time at all.

As a rule of thumb, every site you configure with Railo requires you to edit two configuration files no matter what OS you are running on. First you will need to add an entry in Railo’s server.xml to make it aware of your new site and finally add the site to Apache. I am going to assume you are using Jordan’s excellent Railo installer and you have completed the install process and Railo is connected to Apache. If you are on Windows you can refer to this post which covers installing the Apache connector.

First let us add our new context to Railo. Assuming you used the installer with your default options you can find your server.xml file in /opt/railo/tomcat/conf. The default context is already configured for you and we won’t mess with that. Commented out you will see a template for adding additional sites.

<!--
  Add additional VIRTUALHOSTS by copying the following example config:
  REPLACE:
  [ENTER DOMAIN NAME] with a domain, IE: www.mysite.com
  [ENTER SYSTEM PATH] with your web site's base directory. IE: /home/user/public_html/ or C:\websites\www.mysite.com\ etc...
  Don't forget to remove comments! ;)
-->
<!--
  <Host name="[ENTER DOMAIN NAME]" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
       <Context path="" docBase="[ENTER SYSTEM PATH]" />
  </Host>
-->

So using this as a template, we are going to add in a new Railo host

<Host name="www.domain.com" appBase="webapps"
     unpackWARs="true" autoDeploy="true"
     xmlValidation="false" xmlNamespaceAware="false">
     <Context path="" docBase="/var/www/www.domain.com" />
</Host>

As you can see, we are adding a new host for http://www.domain.com where the template had [ENTER DOMAIN HERE]. Next we enter the docBase where [ENTER SYSTEM PATH] is the location of the web root in the file system. In this case I have my webroot in /var/www/www.domain.com. This is important because the WEB-INF for this context will be created in this directory. Also note that this directory must be writable to the user assigned to the Railo service otherwise Railo will not be able to write the WEB-INF folder and all sorts of tomfoolery will happen. After saving the file you will need to restart the Railo service for your changes to take effect. On Linux this is easy as:

sudo /opt/railo/railo_ctl restart

If your changes were successful you should now be the proud new owner of a WEB-INF folder in /var/www/www.domain.com. If everything went smoothly here you are ready to move to the next step, which is adding your host configuration to Apache. If the folder is not there, more than likely there is a permission issue with your Railo user account. To see which user your Railo service is running under go to open up /opt/railo/railo_ctl with your favorite editor or just cat the file and look for the $TOMCAT_OWNER variable and check the permission on your webroot and make sure that user has write access to the folder.

So assuming everything went smoothly getting your site setup in Railo the next step is getting your virtual host configured in Apache. The location of your configuration files depends on your distribution, but assuming you are running Apache 2.2 on a Debian-based distribution you will need to add a new virtual host into /etc/apache2/sites-available.

Here are the contents of the /etc/apache2/sites-available/www.domain.com.conf file:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName www.domain.com
        DocumentRoot /var/www/www.domain.com
        DirectoryIndex index.cfm
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/www.domain.com/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        RewriteEngine on
        RewriteRule ^/railo-context/admin/(.*) - [F]
        RewriteRule ^/securelocation/(.*) /railo-context/admin/$1 [PT]

        ErrorLog ${APACHE_LOG_DIR}/www.domain.com-error.log

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

        CustomLog ${APACHE_LOG_DIR}/www.domain.com-access.log combined

</VirtualHost>

This is a basic virtual host configuration file. I set the DocumentRoot for this host. It should exactly match the docBase set when adding the Railo host. We also set the Apache directory permissions for the web root directory. For extra credit we are also adding some default rewrite rules to hide the Railo administrator and move it to a more secure location. The rewrite rules require that mod_rewrite is enabled on your server so check your main httpd.conf file to ensure it is enabled otherwise you will receive an error when trying to start Apache and it will fail.

To enable the new site we will need to create a symlink in /etc/apache2/sites-enabled. Forgive me if the parameters are wrong below, I am just doing this from memory.

sudo ln -s /etc/apache2/sites-available/www.domain.com.conf /etc/apache2/sites-enabled/www.domain.com.conf

Now it is time to restart Apache to start serving from your new virtual host. This is generally as simple as sudo service apache2 restart, but this may vary from distribution to distribution.

Once Apache is restarted, you should now be able to point your browser to http://www.domain.com and view your web site. You can reach your admin pages by going to http://www.domain.com/securelocation/web.cfm.

Categories: Railo Tags:
Follow

Get every new post delivered to your Inbox.

Join 765 other followers