MythWeb via MacPorts

From MythTV Official Wiki
Jump to: navigation, search
Warning.png
Running a web server may open your computer up to hacking attempts, particularly if you allow access through your firewall. Instructions for securing MythWeb are available elsewhere in this wiki and you should take appropriate steps before enabling access via the Internet.


This section assumes that you have used the pre-built MythTV 0.28.1 installer to install a complete Myth system on an OS X machine and now want to serve MythWeb from the same machine. Other configurations are possible but are left as an exercise for the reader! See Building MythWeb yourself if you are not using the pre-built MythTV 0.28.1 installer.


Installation

Everything required to run MythWeb is installed by the pre-built installer and the necessary configuration and set-up steps are detailed in the following sections.

Ensure copies exist of required files

Enter each one of the following lines in turn in Terminal.app. Any errors will report a message; successful completion just returns the command prompt.

sudo cp -np /opt/dvr/apache2/bin/envvars-std /opt/dvr/apache2/bin/envvars
sudo cp -np /opt/dvr/apache2/conf/original/httpd.conf /opt/dvr/apache2/conf/httpd.conf
sudo cp -np /opt/dvr/apache2/conf/original/extra/* /opt/dvr/apache2/conf/extra/

Configure Apache and PHP

Based on: https://trac.macports.org/wiki/howto/MAMP

You must enter a series of commands in Terminal and modify a couple of configuration files with a text editor (such as TextEdit or TextWrangler).

Register PHP with Apache

In Terminal, enter:

cd /opt/dvr/apache2/modules
sudo /opt/dvr/apache2/bin/apxs -a -e -n "php5" mod_php54.so

Edit Apache's httpd.conf

You will probably need to change the permissions on the http.conf file in order to edit the file:

sudo chmod 666 /opt/dvr/apache2/conf/httpd.conf

Using a text editor, update /opt/dvr/apache2/conf/httpd.conf file to extend the "DirectoryIndex" directive to include additional "index" files. Search for:

DirectoryIndex index.html

and change it this way:

DirectoryIndex index.php index.html

Also, at the end of the httpd.conf file, add the following lines so that Apache includes the mod_php "AddType" configurations and MythWeb's configuration file:

# 
# Include PHP configurations
#
Include etc/apache2/extra/mod_php54.conf
# 
# MythWeb config
Include www/apache2/html/MythWeb/mythweb.conf

If you have a lower-end machine running Apache/PHP/MythWeb, you may find that the default settings use memory pretty aggressively. Since we're only likely to be accessing MythWeb from a small number of computers--and seldom simultaneously--I found adding the following configuration values to httpd.conf helpful:

#
# MythWeb optional - Ease Apache memory demands 
#
StartServers 1
MinSpareServers 1
MaxSpareServers 4
MaxClients 7
MaxRequestsPerChild 300


based on http://emergent.urbanpug.com/?p=60

Save your changes and close the httpd.conf file.

Modify PHP configuration

In Terminal, enter:

cd /opt/dvr/etc/php54
sudo cp php.ini-development php.ini

Setup the MariaDB 5.5 default socket to use the MacPorts configuration ('/opt/dvr/var/run/mariadb/mysqld.sock')

$ sudo -i
# cd /opt/dvr/etc/php54
# cp php.ini php.ini.bak
# defSock=`/opt/dvr/lib/mariadb/bin/mysql_config --socket`
# cat php.ini | sed \
  -e "s#pdo_mysql\.default_socket.*#pdo_mysql\.default_socket=${defSock}#" \
  -e "s#mysql\.default_socket.*#mysql\.default_socket=${defSock}#" \
  -e "s#mysqli\.default_socket.*#mysqli\.default_socket=${defSock}#" > tmp.ini
# grep default_socket tmp.ini  # Check it!
# mv tmp.ini php.ini
# exit # OR rm php.ini.bak && exit

Edit MythWeb.conf

You may need to tell MythWeb the database settings, so that it can establish a connection.

Using a text editor, update /opt/dvr/apache2/htdocs/MythWeb/mythweb.conf to find and uncomment these lines:

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

You should also update these with the correct server name, database name, login name and password as required.

Save your changes.

Start Web Server

Start the Apache2 web server (httpd) with our configuration:

sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist

Should you ever wish to stop using MythWeb on this machine, enter the following:

sudo launchctl unload /Library/LaunchDaemons/org.macports.apache2.plist

Configure MythWeb

MythWeb works 'out of the box'. To do: determine if any more configuration is necessary or desirable.

Accessing MythWeb

http://localhost/MythWeb or http://web.server.ip/MythWeb


Building MythWeb and supporting software yourself

If you have built your own MythTV software using MacPorts, you can also build and install MythWeb.

Self-build: Installing MythWeb

Choose the version of MythWeb that matches your installed version of Myth. Use Terminal to run the following commands:

At the Terminal prompt, you enter What happens
sudo port install mythweb.28
Download, build and install the MythWeb and supporting software. The first time, it may require several minutes to download, build and install the MacPorts versions of Apache2 and PHP5.

Self-build: Configure Apache and PHP

Based on: https://trac.macports.org/wiki/howto/MAMP

You must enter a series of commands in Terminal and modify a couple of configuration files with a text editor (such as TextEdit or TextWrangler).

Self-build: Register PHP with Apache

In Terminal, enter:

cd /opt/local/lib/apache2/modules
sudo /opt/local/bin/apxs -a -e -n "php5" mod_php54.so

Self-build: Edit Apache's httpd.conf

You will probably need to change the permissions on the http.conf file in order to edit the file:

sudo chmod 666 /opt/local/etc/apache2/httpd.conf

Using a text editor, update /opt/local/etc/apache2/httpd.conf file to extend the "DirectoryIndex" directive to include additional "index" files. Search for:

DirectoryIndex index.html

and change it this way:

DirectoryIndex index.php index.html

Also, at the end of the httpd.conf file, add the following lines so that Apache includes the mod_php "AddType" configurations and MythWeb's configuration file:

# 
# Include PHP configurations
#
Include etc/apache2/extra/mod_php54.conf
# 
# MythWeb config
Include www/apache2/html/MythWeb/mythweb.conf

If you have a lower-end machine running Apache/PHP/MythWeb, you may find that the default settings use memory pretty aggressively. Since we're only likely to be accessing MythWeb from a small number of computers--and seldom simultaneously--I found adding the following configuration values to httpd.conf helpful:

#
# MythWeb optional - Ease Apache memory demands 
#
StartServers 1
MinSpareServers 1
MaxSpareServers 4
MaxClients 7
MaxRequestsPerChild 300

You should also find and uncomment the following two lines:

LoadModule rewrite_module lib/apache2/modules/mod_rewrite.so

...and...

LoadModule deflate_module lib/apache2/modules/mod_deflate.so

based on http://emergent.urbanpug.com/?p=60

Save your changes and close the httpd.conf file.

Self-build: Modify PHP configuration

In Terminal, enter:

cd /opt/local/etc/php54
sudo cp php.ini-development php.ini

Setup the MariaDB 5.5 default socket to use the MacPorts configuration ('/opt/local/var/run/mariadb/mysqld.sock')

$ sudo -i
# cd /opt/local/etc/php54
# cp php.ini php.ini.bak
# defSock=`/opt/local/lib/mariadb/bin/mysql_config --socket`
# cat php.ini | sed \
  -e "s#pdo_mysql\.default_socket.*#pdo_mysql\.default_socket=${defSock}#" \
  -e "s#mysql\.default_socket.*#mysql\.default_socket=${defSock}#" \
  -e "s#mysqli\.default_socket.*#mysqli\.default_socket=${defSock}#" > tmp.ini
# grep default_socket tmp.ini  # Check it!
# mv tmp.ini php.ini
# exit # OR rm php.ini.bak && exit

Self-build: Edit MythWeb.conf

You may need to tell MythWeb the database settings, so that it can establish a connection.

Using a text editor, update /opt/local/www/apache2/html/MythWeb/mythweb.conf to find and uncomment these lines:

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

You should also update these with the correct server name, database name, login name and password as required.

Save your changes.

Self-build: Start Web Server

Start the Apache2 web server (httpd) with our configuration:

sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist

Should you ever wish to stop using MythWeb on this machine, enter the following:

sudo launchctl unload /Library/LaunchDaemons/org.macports.apache2.plist

Self-build: Configure MythWeb

MythWeb works 'out of the box'. To do: determine if any more configuration is necessary or desirable.

Self-build: Accessing MythWeb

http://localhost/MythWeb or http://web.server.ip/MythWeb

Troubleshooting

404 Not Found

Check Console.app, under the /var/log section for an apache2 error log. If you see lines like "File does not exist: /Library/WebServer/Documents/MythWeb", the Apache software built into OS X is intercepting the web request and isn't configured to handle it. Be sure that MacPorts Apache2 is the only one running; not the version built into OS X. Prior to Mountain Lion, go into the System Preferences>Sharing and ensure Web Sharing is not clicked. For Mountain Lion (OS X 10.8.x), search the web for instructions on enabling/disabling web sharing.