MythWeb on Mac OS X Backend

From MythTV Official Wiki
Revision as of 15:44, 1 December 2011 by OCG (talk | contribs) (Work on a Copy)

Jump to: navigation, search

Introduction

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. If you are interested in watching and recording TV using OSX, please see MythTV_on_Mac_OS_X.

If you are interested in browsing an existing MythWeb server using OSX, please see MythWeb_client_on_Mac_OS_X.

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


Get 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 git (which you will need to have installed on your Mac) like this:

shell> cd /Library/WebServer
shell> git clone -b fixes/0.24 https://github.com/MythTV/mythweb.git 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 from the latest fixes to 0.24 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 version of the MythWeb configuration file and opening it (along with the general apache configuration file) in TextEdit

For OS X Server Lion all of the "/Library/WebServer/MythWeb" should be replaced with "/Library/Server/Web/Data/Sites/Default/MythWeb".

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

Editing 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 near the top that look like

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

and uncomment (remove the leading octothorpes from) them. So they should now 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 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
Warning.png
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 do not want to fix 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

Editing 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

OS X Server Lion

Find the line that says

   <IfDefine WEBSERVICE_ON>
       Include /etc/apache2/sites/*.conf
   </IfDefine>

And change it to

   <IfDefine WEBSERVICE_ON>
       Include /etc/apache2/sites/*.conf
       Include /etc/apache2/other/*.conf
   </IfDefine>


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 from remote computers, so they should not be considered particularly secure.

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 is required (it 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. The way to do this depends on which version of OSX you are using:

Leopard

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


Snow Leopard

Begin by copying /etc/php.ini.default to /etc/php.ini.

shell> sudo cp -p  /etc/php.ini.default /etc/php.ini

Now 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

Also, locate the timezone specification so that we can fix it. Edit the part that says

; date.timezone =

to read

date.timezone = America/Chicago

or the equivalent timezone for your location.

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 for communicating with MySQL. This requires having the XCode development environment installed so that a C compiler is available to the Perl module installer. After installing XCode, your next steps depend on which version of OSX you are using:


Leopard

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

It's fine if you allow it to automatically configure

Are you ready for manual configuration? [yes] no


Snow Leopard

The default 64-bit Perl installation cannot automatically install DBD::mysql (as of OSX version 10.6.4, 2010-09-05). Instead, it is easiest to switch the default version to 32-bit. This involves the following commands

shell> sudo su
shell# export VERSIONER_PERL_PREFER_32_BIT=yes
shell# defaults write com.apple.versioner.perl Prefer-32-Bit -bool yes
shell# defaults write /Library/Preferences/com.apple.versioner.perl Version 5.8.9

Automatic installation may now work with

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

Otherwise, you can download the package from CPAN, unpack it, and then build and install using

shell> perl Makefile.PL --mysql_config=/usr/local/mysql/bin/mysql_config
shell> make
shell> sudo make install

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.app. The most interesting is /var/log/apache2/error_log. Since the MythWeb website uses PHP, you are looking for the startup message here to say that PHP is working. It should look something like this

Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8l DAV/2 PHP/5.3.1 configured -- resuming normal operations


Command-line jockeys may enjoy causing the webserver to reload new configurations with the following command

shell> sudo apachectl graceful

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.

External Links

Wiki


Install guide

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