Difference between revisions of "MythWeb on Lighttpd"

From MythTV Official Wiki
Jump to: navigation, search
Line 150: Line 150:
  
 
Lighttpd is now configure for MythWeb usage but we need to restart Lighttpd for all the changes to take place.
 
Lighttpd is now configure for MythWeb usage but we need to restart Lighttpd for all the changes to take place.
 +
  
 
=== MythWeb ===
 
=== MythWeb ===

Revision as of 01:09, 19 August 2007

MythWeb on Lighttpd

MythWeb provides a frontend for scheduling and managing recordings on your MythBox from a web browser located on another machine. In addition it allows for changing key bindings and other settings.

This guide will provide you with a way to run MythWeb on Lighttpd rather then apache. The benefit to this is faster loading times for MythWeb but the disadvantages is the time it takes to setup which should be shortened if you follow this guide.


Installing

Before we get anywhere we need to install the programs needed for this. Use your package manager or compile from source.

PHP

PHP just needs the following options compiled as a minimum:

./configure --enable-fastcgi --enable-discard-path --enable-force-redirect --with-mysql

Gentoo would use the following USE Flags: cgi cli discard-path force-cgi-redirect mysql ssl pcre


Lighttpd

A default compile should pull everything needed in and the USE Flags for Gentoo would be: fastcgi mysql pcre php ssl


MythWeb

You need to copy the MythWeb files over to your web server's path in my case it was /var/www/localhost/htdocs/ I also put MythWeb into a directory called mythweb and the rest of the guide will follow the layout of the path being /var/www/localhost/htdocs/mythweb/ and the address being http://localhost/mythweb, change to suit your needs.


Configuring

With everything installed we next need to configure our software for use.

PHP

Only one option here needs changing else you will be seeing the following error quite alot:

 Error at /var/www/localhost/htdocs/modules/weather/handler.php, line 96:
 file() [function.file]: URL file-access is disabled in the server configuration

You need to open your php.ini which in Gentoo's case is /etc/php/cgi-php5/php.ini and change the following:

allow_url_fopen = On

The above command allows URLs to be treated as files.


Lighttpd

There are many options in here that need changing to allow MythWeb to work.

fastcgi.server

We need to configure fastcgi for PHP use so open the config file for it and leaving the parts which are already there as it may break you install we need to add the following line:

fastcgi.server             = ( ".php" =>
                              ( "localhost" =>
                                (
                                  "socket" => "/tmp/php-fastcgi.socket",
                                  "bin-path" => "/usr/local/bin/php",
                                  "broken-scriptfilename" => "enable"
                                )
                              )
                           )

Which should just be the broken-scriptfilename line

Please note that any line in the array that isn't the last line needs a comma ',' on the end of it else lighttpd won't start!

Lighttpd doesn't use .htaccess like Apache does so we need a workaround for access to the MythTV database.

Once again editing the fastcgi.server section place the following:

fastcgi.server             = ( ".php" =>
                              ( "localhost" =>
                                (
                                  "socket" => "/tmp/php-fastcgi.socket",
                                  "bin-path" => "/usr/local/bin/php",
                                  "broken-scriptfilename" => "enable"
                                  "bin-environment" => ( "db_server" => "localhost",
                                                         "db_name" => "mythconverg",
                                                         "db_login" => "mythtv",
                                                         "db_password" => "mythtv"
                                                        )
                                 )
                               )
                              )

Changing the values to match you install, e.g. if my login was Pompey the line would look like this

"db_login" => "Pompey",

MythWeb can now connect to the database.

Mod_Rewrite

MythWeb needs a rewrite rule to function properly so we need to enable the module mod_rewrite in the lighttpd.conf file as so:

server.modules = (
mod_rewrite
)

We now need to add the rule in the same config file that does the rewriting:

url.rewrite = (
   "^/mythweb(/tv.*|/music.*|/video.*|/weather.*|/settings.*|/status.*|/backend_log.*)$" =>   "/mythweb/mythweb.php/$1"
 )

The above rule is following my layout of being in the mythweb directory, If MythWeb was in the root of the web server '/' then we would use the following rule:

url.rewrite = (
   "^(/tv.*|/music.*|/video.*|/weather.*|/settings.*|/status.*|/backend_log.*)$" =>   "/mythweb.php/$1"
 )


Default Page

As most of you know when you type in an address such as link http://www.immolo.net it really loads up the page http://www.immolo.net/index.php but MythWeb's main page is called mythweb.php so lets edit lighttpd.conf to also open mythweb.php as a default page so we can just type http://localhost/mythweb/ to access MythWeb

Find the following line:

server.indexfiles    = ("index.php", "index.html", "index.htm", "default.htm")

And change to:

server.indexfiles    = ("mythweb.php", "index.php", "index.html", "index.htm", "default.htm")

Lighttpd is now configure for MythWeb usage but we need to restart Lighttpd for all the changes to take place.


MythWeb

When using MythWeb on Lighttpd you always get the following error:

Fatal error: Call to a member function query() on a non-object in /var/www/localhost/htdocs/mythweb/includes/session.php on line 60

To fix this we need to apply a few lines of code which I found on the Gentoo fourms


/**
+ * Destructor to save the session  before the database connection dies
/**/
    function __destruct() {
        // Restore global db object reference for session write
        global $db;
        $db = $this;
        // Ask session to write and close now, before we lose the db object forever
        session_write_close();
    } 

The above code needs to go into mythtv/include/objects/Database.php around line 90 which is just under the following section:

/**
 * Legacy constructor to catch things that the abstract classification won't
/**/
    function Database() {
        trigger_error('The Database class should never be created as an object.  Use Database::connect() instead.', E_USER_ERROR);
    }

After saving you should notice the error has gone from all the pages and now MythWeb fully works as it would with Apache.


Secure MythWeb on Lighttpd

You sometimes hear stories of people gaining access to other peoples MythTV setup via the Internet so lets look into ways of securing MythWen but still leaving access to MythWeb from the outside in case we ever need to access it from work or from a friends (or show off :D).

Auth (Password)

Nice and simple, Lets put an username and password on the directory so then only we can access it.

In the lighttpd.conf uncomment the mod_auth so it looks like this:

server.modules = (
mod_auth
)

We can then add the following rule to create the protected directory:

auth.backend               = "htpasswd"
auth.backend.htpasswd.userfile = "/var/www/localhost/lighttpd.user.htpasswd"
auth.require               = ( "/mythweb/" =>
                               (
                                 "method"  => "basic",
                                 "realm"   => "mythweb",
                                 "require" => "valid-user"
                               )
                        )

As you can see we are using htpasswd which is an Apache based tool which on Gentoo can be installed with the app-admin/apache-tools package but other distributions will need to check the package they need.

with htpasswd installed you now need to run the following command:

htpassword -c /var/www/localhost/lighttpd.user.htpassword <user>

Chaning <user> to the username you desire. You will next be asked to type a password which I'm sure you don't need me to say needs to be secure.

After you restart Lighttpd when you point your browser to MythWeb you should be asked for your username and password.


ToDo

I still need to add a section on using SSL with MythWeb on Lighttpd and any ideas are welcome place them in the Talk page or just add it yourself.

I also wrote this guide late at night and 3 days after the birth of my son (hence the lack of sleep) so if you find spelling or grammer mistakes please correct them.

The layout of this guide maybe change if you have any ideas on a better feel please let me know.

Immmolo