MythWeb on Mac OS X Backend

From MythTV Official Wiki
Revision as of 02:44, 23 November 2009 by Brianboonstra (talk | contribs) (Work on a Copy)

Jump to: navigation, search

Because Macs all come with a built-in webserver, it is fairly easy to have MythWeb served from your Mac. However, there are a few changes needed to the default configuration.

Warning.png
Running a webserver opens your computer up to hacking attempts, particularly if you allow port-forwarding access through your firewall.


Getting a Copy of MythWeb

You will need a copy of the website files in the proper directory. To get it, open Terminal and use the command-line program svn (which should already be present on your Mac, in /usr/bin/svn) like this:

shell> cd /Library/WebServer
shell> svn co http://svn.mythtv.org/svn/branches/release-0-22-fixes/mythplugins/mythweb MythWeb

Here, the shell> characters indicate the shell prompt, not something you need to type.

This will put a copy of the latest website code in /Library/WebServer/MythWeb.

Modify Webserver Configuration

Work on a Copy

Now you need to change the configuration of the webserver so that the website works. Begin by copying the Linux configuration file and opening it (along with the general configuration file) in TextEdit

shell> cd /Library/WebServer/MythWeb
shell> cp mythweb.conf.apache mythweb.conf
shell> cp /etc/apache2/httpd.conf ./
shell> open -a TextEdit mythweb.conf httpd.conf

Edit mythweb.conf

First, make some changes to mythweb.conf

URL Alias

Insert a line at the top that says

Alias /MythWeb /Library/WebServer/MythWeb

You may find it convenient to have a couple more aliases, such as

Alias /MythTV /Library/WebServer/MythWeb
Alias /Myth /Library/WebServer/MythWeb


Streaming Authentication

Find the lines that look like

#   <LocationMatch .*/pl/stream/[0-9]+/[0-9]+>
#       Allow from all
#   </LocationMatch>
#
#   <LocationMatch .*/music/stream.php>
#       Allow from all
#   </LocationMatch>

and change them to read

   <LocationMatch .*/pl/stream/[0-9]+/[0-9]+>
       Allow from all
   </LocationMatch>
#
   <LocationMatch .*/music/stream.php>
       Allow from all
   </LocationMatch>

Directory Locations

Find the line that says

    <Directory "/var/www/html/data">

and change it to

    <Directory /Library/WebServer/MythWeb/data>

where it is important to remove the quotes.


A couple lines below that, find the line that says

   <Directory "/var/www/html" >

and change it to

    <Directory /Library/WebServer/MythWeb>

Again, it is important to remove the quotes.

Authentication and Security

In the Authentication section below that, uncomment (remove the leading octothorpes from) the setup lines. So the section that formerly read like this

   #    AuthType           Digest
   #    AuthName           "MythTV"
   #    AuthUserFile       /var/www/htdigest
   #    Require            valid-user
   #    BrowserMatch       "MSIE"      AuthDigestEnableQueryStringHack=On
   #    Order              allow,deny
   #    Satisfy            any

should now read like this

       AuthType           Digest
       AuthName           "MythTV"
       AuthUserFile       /etc/apache2/other/mythweb-htdigest
       Require            valid-user
       BrowserMatch       "MSIE"      AuthDigestEnableQueryStringHack=On
       Order              allow,deny
       Satisfy            any

Note the change in location of the AuthUserFile.

Backend Details

Make sure the backend details, which currently look like this

           setenv db_server        "localhost"
           setenv db_name          "mythconverg"
           setenv db_login         "mythtv"
           setenv db_password      "mythtv"

have your correct database information, in particular the username and password.

You may have to change the location of the database server from localhost to mydvrmac.local or some equivalent if you have not fixed your MySQL socket (see below). The error message for bad database information is not working as of mythtv 22-fixes-20091115.

URL Rewrite

Find the line that says

   #    RewriteBase    /mythweb

uncomment and change the capitalization so that it now reads

       RewriteBase    /MythWeb

Compression and Deflation

Find the section that looks like this

   #    BrowserMatch ^Mozilla/4 gzip-only-text/html
   #    BrowserMatch ^Mozilla/4\.0[678] no-gzip
   #    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
   #
   #    AddOutputFilterByType DEFLATE text/html
   #    AddOutputFilterByType DEFLATE text/css
   #    AddOutputFilterByType DEFLATE application/x-javascript

and uncomment it to read like this

       BrowserMatch ^Mozilla/4 gzip-only-text/html
       BrowserMatch ^Mozilla/4\.0[678] no-gzip
       BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
       AddOutputFilterByType DEFLATE text/html
       AddOutputFilterByType DEFLATE text/css
       AddOutputFilterByType DEFLATE application/x-javascript

Then uncomment the line that reads

   #    Header append Vary User-Agent env=!dont-vary

so that it now reads

       Header append Vary User-Agent env=!dont-vary

Edit httpd.conf

Now we just have to make a couple of changes to the main webserver configuration file httpd.conf.

Enable PHP

Find the line that says

#LoadModule php5_module        libexec/apache2/libphp5.so

and uncomment it to read

LoadModule php5_module        libexec/apache2/libphp5.so

Additional Security

If you don't plan to use this Mac webserver for other purposes, you may wish to disable some security risks such as the user directory module. To do so, find the line

Include /private/etc/apache2/extra/httpd-userdir.conf

and comment it out to read

#Include /private/etc/apache2/extra/httpd-userdir.conf

Save

Save these files and quit TextEdit.

Finish Webserver Configuration

Create Password File

Create the password file for accessing your webserver by using the line

shell> sudo htdigest  -c  /etc/apache2/other/mythweb-htdigest MythTV username

where you should replace username with your own choice. You will be prompted for a password. This username and password are the ones you will need to use the MythWeb site.

Set Up Config Files

Now you need to put these configuration files where the webserver can read them.

shell> sudo cp /etc/apache2/httpd.conf /etc/apache2/httpd.conf.pre-mythweb
shell> cd /Library/WebServer/MythWeb
shell> sudo cp mythweb.conf /etc/apache2/other/mythweb.conf
shell> sudo cp httpd.conf /etc/apache2/httpd.conf

Change Data Directory Owner

As a security practice, the webserver runs as the user www rather than as an administrator. Change the ownership of the MythWeb files like this

shell> sudo chown -R root:admin /Library/WebServer/MythWeb
shell> sudo chown -R www:www /Library/WebServer/MythWeb/data

where the first line is optional, but the second allows the webserver some scratch space on the hard drive.

Fix MySQL Socket

If your database server is localhost you will need to tell PHP how it can find a socket to communicate with MySQL. To do this, you must edit the file /etc/php.ini. Find the lines that look like this

; Default socket name for local MySQL connects.  If empty, uses the built-in 
mysql.default_socket = 

and add the location where the MySQL installer really puts the socket

; Default socket name for local MySQL connects.  If empty, uses the built-in 
mysql.default_socket = /tmp/mysql.sock

You will need to be an admin to edit this file. if you are comfortable with the text-based editor nano, it is convenient to edit the file with the line

shell> sudo nano /etc/php.ini

(Optional) Perl Upgrades

To get streaming video working, you must install the Perl module

shell> sudo perl -MCPAN -e 'install DBD::mysql'

you should do fine if you allow it to automatically configure

Are you ready for manual configuration? [yes] no


Start The Webserver

To start the webserver, go to System Preferences and open the Sharing pane. Click the checkbox next to Web Sharing. If it was already on, then click it off and on again, so as to restart the webserver with your new configuration.

Troubleshooting

You can examine the error messages from the webserver using Console. The most interesting is /var/log/apache2/error_log. Since the MythWeb website uses PHP, you need the startup message here to say that PHP is working. It should look something like this

Apache/2.2.13 (Unix) mod_ssl/2.2.13 OpenSSL/0.9.7l DAV/2 PHP/5.2.11 configured -- resuming normal operations


Command-line jockeys may enjoy causing the webserver to reload new configurations with the following set of pipes

ps auxww | grep httpd | grep root | awk -F' '  '{print $2}'|xargs sudo kill -HUP


For more information

Mailing Lists

If you have problems with this guide, the mythtv-users mailing list is the best place to start. Check the searchable archive to see if your problem has already been discussed. Also, you can check the mythtv-dev list to see if it's a problem with SVN; if you can't compile MythTV, you may just have to wait a few days and try again.

External Links

Wiki

  • The MythWeb page has a little userguide along with some Linux-oriented setup information

Install guide

  • The INSTALL file distributed with the source code has a considerable amount of Linux-oriented setup information.