Search:  
Gentoo Wiki

HOWTO_Setup_MythWeb_with_Lighttpd

This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc

MythTV Series

MythTV

Installation

Tips/Tweaking

Usage

edit

This HOWTO describes how to get MythWeb working with the Lighttpd web server. By default, MythWeb uses the Apache webserver, but Lighttpd is a popular and lightweight alternative.

Contents

Prerequisites

With these prerequisites, only a few configuration changes are needed.

Install LightTPD and PHP

Follow the tutorials PHP and LightTPD. Be sure, you have compiled LightTPD with the USE flags fastcgi, pcre and php. PHP must be built with cgi, mysql, mysqli, posix and session support. So, put at least the following USE flags set in /etc/portage/package.use:

File: /etc/portage/package.use
 www-servers/lighttpd php pcre fastcgi
 dev-lang/php         cgi pcre mysql mysqli posix

You may be interested in investigation how to configure webapp-config as well. This document assumes that the document-root is /var/www/localhost/htdocs.

Install and Configure MythWeb

Once you have installed LightTPD and PHP, install MythWeb using emerge -av mythweb. This should install MythWeb into /var/www/localhost/htdocs/mythweb. By default MythWeb uses Apache's .htaccess file to set the database access options and define some address re-directs for the PHP scripts. First, we have to tell MythWeb where the to find the MythTV database. Edit /var/www/localhost/htdocs/mythweb/includes/init.php and add these lines near the top:

// Define db access for Lighttpd.
$_SERVER["db_server"] = "localhost";  // change if MythTV MySQL db is elsewhere
$_SERVER["db_name"] = "mythconverg";
$_SERVER["db_login"] = "mythtv";  
$_SERVER["db_password"] = "mythtv_password";
// End of change

Note: This will be overwritten if MythWeb is updated. It may be wise to put an entry in CONFIG_PROTECT for this file.

These MySQL login and password variables may be observable from the outside. If you want more security, use LightTPD's password authentication on the MythWeb directory.

Note: the proper way to fix this would be to add a setenv.add-environment option inside the mythtv host configuration in lighttpd.conf (see below). But this doesn't work currently because lighttpd translates the variable names to capitals. See http://trac.lighttpd.net/trac/ticket/420.

Another option is to add the bin-environment option to php fastcgi.server section in lighttpd.conf. The advantage is that init.php does not have to be modified after every mythweb upgrade. But be aware that this affects the configuration of all PHP scripts run on the server, not just mythweb, so it could be security issue (other scripts can see your mythtv database password). These lines should be added in the lighttpd.conf .php section, immediately after the "broken-scriptfilename" option (don't forget a comma):

File: /etc/lighttpd/lighttpd.conf
                       "bin-environment" => ("db_server" => "localhost",
                                             "db_name" => "mythconverg",
                                             "db_login" => "mythtv",
                                             "db_password" => "mythtv_password")

Configure LightTPD and PHP

MythWeb needs this option to be set in your php.ini:

File: php.ini
 allow_url_fopen = On

See LightTPD on how to install LightTPD. Be sure, you have enabled PHP (FastCGI) support.

MythWeb requires address rewrites, so we edit /etc/lighttpd/lighttpd.conf:

File: /etc/lighttpd/lighttpd.conf
...
 server.modules += ("mod_rewrite")
...

Finally, we need to setup address re-writes. I think the best way to do this is to use a virtual domain, as (1) it has minimal impact on other things your webserver might be doing, and (2) it made the address rewrite regex simpler. Edit /etc/lighttpd/lighttpd.conf

$HTTP["host"] == "mythtv.my-domain.tld" {
    server.document-root = "/var/www/localhost/htdocs/mythweb"
    index-file.names = ("mythweb.php")
    url.rewrite = ( "^/(tv|music|video|weather|settings|status|stats|backend_log).*$"   =>   "mythweb.php/$0" )
   #
   ## As described above, this should work for defining the mythweb configuration,
   ## but currently lighttpd translates the variable names to uppercase.
   ## Should work correctly in lighttpd 1.4.18.
   #setenv.add-environment = ("db_server" => "localhost",
   #                          "db_name" => "mythconverg",
   #                          "db_login" => "mythtv",
   #                          "db_password" => "mythtv_password")
   #
   ## It may be wise to use password authetication.
   ## If you do this, add a similar auth section to the general server settings
   ## for the directory /mythweb
   #auth.require  = ( "/" => (  "method"  => "basic",
   #                             "realm"   => "Private",
   #                             "require" => "valid-user"
   #                           ))
}

Now, restart lighttpd and point a browser at http://mythtv.my-domain.tld

Retrieved from "http://www.gentoo-wiki.info/HOWTO_Setup_MythWeb_with_Lighttpd"

Last modified: Sat, 28 Jun 2008 08:47:00 +0000 Hits: 2,838