Web Application Redirect Tutorial

From SME Server
Revision as of 21:26, 23 December 2008 by Electroman00 (talk | contribs) (Make the see disscussion page bold)
Jump to navigationJump to search
Edit-find-replace.png Not reviewed:
This howto or contrib has not been reviewed and might contain code that could harm your installation. For more information on the review process have a look at the Development Review page.


Web Application Redirect Tutorial

Warning.png Warning:
The method outlined in this Howto, whilst being functional, may cause some as yet to be defined odd problems with the primary domain, so you are advised to use it with discretion. Further testing needs to be carried out to correctly identify the exact source and nature of these problems. Please test these modifications on your system and if you notice issues report them to the bugtracker. Work is continuing to develop a better method, see the discussion page.



Overview

This Howto gives a practical example of redirecting (virtual) domains to web applications located in the /opt/... folder.

It utilises information published in http://wiki.contribs.org/Web_Application_RPM and applies it to an example installation of Joomla CMS using http://wiki.contribs.org/Joomla

The same concepts will apply to other web applications or content installed in /opt/....


Scenario

You want to have a web application in /opt

You want to have a virtual domain(s) on your sme server

You want to access the web app in /opt/appname using the virtual domain ie www.myvirtualdomain.com

Based on information in http://forums.contribs.org/index.php?topic=38878.15 and utilising the information in http://wiki.contribs.org/Web_Application_RPM here's what I did as a redirect example.


Procedure

Install Joomla using http://wiki.contribs.org/Joomla

This installs the Joomla CMS application in /opt/joomla

It also installs a fragment /etc/e-smith/templates/etc/httpd/conf/httpd.conf/92joomla

Create another fragment

pico -w /etc/e-smith/templates/etc/httpd/conf/httpd.conf/80OptDomainJoomla

Enter the following code, having replaced foo with joomla, and save the file

It is taken from http://wiki.contribs.org/Web_Application_RPM Webserver Templates - a workaround to enable the application to be located in a domain or subdomain root with joomla

{
  my $status = $joomla{'status'} || "disabled";
  return "    # joomla-status is disabled.\n"
          unless $status eq 'enabled';

  my $domain = $joomla{'domain'} || "disabled";
  return "    # no hostname or domain for joomla defined\n"
          if $domain eq 'disabled';

  my $DocRoot = "/opt/joomla";

  $OUT  = "";
  $OUT .= "\n";
  $OUT .= "# Redirect an existing hostname or domain to $DocRoot.\n";
  $OUT .= "<VirtualHost 0.0.0.0:80>\n";
  $OUT .= "    ServerName  $domain\n";
  $OUT .= "    DocumentRoot $DocRoot\n";
  $OUT .= "</VirtualHost>\n";
  $OUT .= "<VirtualHost 0.0.0.0:443>\n";
  $OUT .= "    ServerName  $domain\n";
  $OUT .= "    DocumentRoot  $DocRoot\n";
  $OUT .= "    SSLEngine on\n";
  $OUT .= "</VirtualHost>\n";
}


Then use the db command to configure the system to run joomla from the root of a virtual domain ie www.myvirtualdomain.com

The virtual domain must exist in the Domains panel and be correctly configured in external DNS.

The domain panel content location ie Primary or an ibay, will be overridden by the following db setting.

You will also need to set the status to enabled as the code reads this db property (even though the default status is enabled it needs to be set).

config setprop joomla status enabled
config setprop joomla domain www.myvirtualdomain.com
expand-template /etc/httpd/conf/httpd.conf
sv h /service/httpd-e-smith


Warning.png Warning:
This example refers to installation using the joomla rpm. When using the SiteMaker contrib, or doing additional installations of joomla or installing other rpms that do not setup default configuration db entries, it will be necessary to manually create the service entry and other db entries. In those cases you would do something like the following, as necessary.
config set joomla2 service
config setprop joomla2 DbName joomla2
config setprop joomla2 DbPassword joomla2passwordxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
config setprop joomla2 DbUser joomla2user
config setprop joomla2 Name Joomla2
config setprop joomla2 PublicAccess global
expand-template /etc/httpd/conf/httpd.conf
sv h /service/httpd-e-smith

Make sure you use the correct mysql db name, password & user, as already created for the joomla2 (or whichever) db in mysql.



Then open your browser and type in the URL http://www.myvirtualdomain.com

The Joomla CMS should open and the browser will display the same URL

Remember to Refresh your browser cache to clear old cached data.


As indicated in http://wiki.contribs.org/Web_Application_RPM you can also use a URL in the form

mymaindomain.com/cms

or

myvirtualdomain.com/cms

Remove any previous domain entry first

config setprop joomla status enabled
config delprop joomla domain
config setprop joomla URL cms
expand-template /etc/httpd/conf/httpd.conf
sv h /service/httpd-e-smith


Apply the above concepts to any other application installed in /opt/appname, keeping in mind the template fragments should conform to the code shown in the examples posted in

http://wiki.contribs.org/Web_Application_RPM

and should be renamed appropriately eg

92webappname

and

80OptDomainWebappname

The fragments should also be edited to suit the webappname


To view the db settings do

config show joomla

which should give output like

joomla=service
   DbName=joomla
   DbPassword=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
   DbUser=joomlauser
   Name=Joomla
   PublicAccess=global
   domain=www.myvirtualdomain.com
   status=enabled

or

joomla=service
   DbName=joomla
   DbPassword=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
   DbUser=joomlauser
   Name=Joomla
   PublicAccess=global
   URL=cms
   status=enabled

Reference links

http://forums.contribs.org/index.php?topic=38878.15

http://wiki.contribs.org/Web_Application_RPM

http://wiki.contribs.org/Joomla