Difference between revisions of "MythWeb on Jetty"
Lwoggardner (talk | contribs) (→php-cgi-fix) |
m |
||
Line 210: | Line 210: | ||
[[Category:HOWTO]] | [[Category:HOWTO]] | ||
+ | [[Category:MythWeb]] |
Latest revision as of 19:36, 11 August 2010
Jetty is a full featured Java based web server.
MythWeb runs nicely on Apache but relies on the mod-rewrite capability and the .htaccess file to get things working smoothly so running it up under a different webserver is non trivial.
These instructions refer to mythweb 0.20 (fixes branch), Jetty 5 and PHP 5. Something similar should be possible for other Java containers such as Tomcat.
Contents
Basic Approach
Mythweb is treated like a Java webapplication and is configured with a few extra files in a WEB-INF directory. The mythweb files need to be dropped somewhere that jetty will look for webapplications. Depending on how you have PHP configured, you may need to put a link to mythweb in PHP's doc_root
A UrlRewrite Filter is applied to the mythweb context as equivalent to mod-rewrite
A CGI Servlet is used for both mythweb.php and mythweb.pl
mythweb.php is added as a welcome file (this could also have been done using urlrewrite)
Finally, Jetty 5 has a HTAccessHandler that can use .htaccess authorisation. Alternatively the security features of the J2EE spec (JAAS) could be used
Note that the video and music plugins to mythweb create symbolic links to the media locations. Jetty needs to be configured to serve symbolic links which can be a security issue. (See checkAlias directive in jetty.xml)
Configuration Files
WEB-INF/web.xml
You'll need to set your database password info and location of PHP
<?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/n s/j2ee/web-app_2_4.xsd" version="2.4"> <display-name>MythWeb</display-name> <filter> <filter-name>UrlRewriteFilter</filter-name> <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class> <init-param> <param-name>logLevel</param-name> <param-value>WARN</param-value> </init-param> </filter> <filter-mapping> <filter-name>UrlRewriteFilter</filter-name> <url-pattern>*</url-pattern> </filter-mapping> <servlet> <servlet-name>PHP</servlet-name> <servlet-class>org.mortbay.servlet.CGI</servlet-class> <init-param> <param-name>ENV_REDIRECT_STATUS</param-name> <param-value>200</param-value> </init-param> <init-param> <param-name>commandPrefix</param-name> <!-- Location of php-cgi on your system!! --> <param-value>/usr/local/bin/php-fix-cgi</param-value> </init-param> <init-param> <param-name>ENV_db_server</param-name> <param-value>localhost</param-value> </init-param> <init-param> <param-name>ENV_db_name</param-name> <param-value>mythconverg</param-value> </init-param> <init-param> <param-name>ENV_db_login</param-name> <param-value>mythtv</param-value> </init-param> <init-param> <param-name>ENV_db_password</param-name> <param-value>YOUR PASSWORD!!</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>PHP</servlet-name> <url-pattern>/mythweb.php/*</url-pattern> </servlet-mapping> <servlet> <servlet-name>Perl</servlet-name> <servlet-class>org.mortbay.servlet.CGI</servlet-class> <init-param> <param-name>ENV_db_server</param-name> <param-value>localhost</param-value> </init-param> <init-param> <param-name>ENV_db_name</param-name> <param-value>mythconverg</param-value> </init-param> <init-param> <param-name>ENV_db_login</param-name> <param-value>mythtv</param-value> </init-param> <init-param> <param-name>ENV_db_password</param-name> <param-value>YOUR PASSWORD</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Perl</servlet-name> <url-pattern>/mythweb.pl/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>mythweb.php</welcome-file> </welcome-file-list> </web-app>
WEB-INF/urlrewrite.xml
rewrite rules
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 2.6//EN" "http://tuckey.org/res/dtds/urlrewrite2.6.dtd"> <urlrewrite> <rule> <note>Bug in skinurl produces skins/...//xxx.css instead of skins/.../xxx.css</note> <from>^(.+)//(.+)$</from> <to>$1/$2</to> </rule> <rule> <note> RewriteRule ^(css|data|images|js|themes|skins|[a-z_]+\.(php|pl))(/|$) - [L]</note> <from>^/(css|data|images|js|themes|skins|[a-z_]+\.(php|pl))(/|$)</from> <to last="true">$0</to> </rule> <rule> <note> RewriteRule ^(pl(/.*)?)$ mythweb.pl/$1 [QSA,L]</note> <from>^/(pl(/.*)?)$</from> <to last="true">/mythweb.pl/$1</to> </rule> <rule> <note> RewriteRule ^(.+)$ mythweb.php/$1 [QSA,L]</note> <from>^/(.+)$</from> <to last="true">/mythweb.php/$1</to> </rule> </urlrewrite>
WEB-INF/jetty-web.xml
Not required unless you want HTAccess authorisation.
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd"> <Configure class="org.mortbay.jetty.servlet.WebApplicationContext"> <Call name="addHandler"> <Arg type="int">0</Arg> <Arg> <New class="org.mortbay.http.handler.HTAccessHandler"/> </Arg> </Call> </Configure>
and Jetty's HTAccessHandler is not very forgiving on the format of the .htaccessfile. You'll want something like...
AuthName MythTV AuthType Basic AuthUserFile /path/to/htpasswd AuthGroupFile /path/to/htgroups <Limit GET POST> satisfy all require valid-user </Limit>
php-cgi-fix
PHP CGI is a bit borked. But this wrapper and config settings fixes it up nicely on PHP 5.1.2. YMMV
#!/bin/sh #php-cgi-fix: Set non standard CGI var, SCRIPT_FILENAME instead of passing as an argument. export SCRIPT_FILENAME=$1 <your path to php-cgi>
and in php.ini...
;leave doc_root unset doc_root= ;don't let php try to fix path info cgi.fix_pathinfo=0