Difference between revisions of "MythWeb via MacPorts"

From MythTV Official Wiki
Jump to: navigation, search
(27.4: update for MariaDB 5.5)
(PHP 5.4)
Line 71: Line 71:
In Terminal, enter:
In Terminal, enter:
  cd /opt/dvr/etc/php5
  cd /opt/dvr/etc/php54
  sudo cp php.ini-development php.ini
  sudo cp php.ini-development php.ini

Revision as of 18:15, 19 October 2014

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 page assumes that you have used the pre-built 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 installer.


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. (These commands are not required if you built MythWeb with MacPorts.) Any errors will report a message; successful completion just returns the command prompt.

sudo cp -np /opt/dvr/apache2/htdocs/index.html.sample /opt/dvr/apache2/htdocs/index.html
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" libphp5.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 conf/extra/mod_php.conf
# MythWeb config
Include htdocs/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 https.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/php5
# 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

Start Web Server

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

sudo launchctl load -w /opt/dvr/etc/LaunchDaemons/org.macports.apache2/org.macports.apache2.plist

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

sudo launchctl unload /opt/dvr/etc/LaunchDaemons/org.macports.apache2/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. You will also have to complete the configuration and set-up steps above. Note that the pre-built software is installed under '/opt/dvr' while your version will be under '/opt/local'. Adapt all the instructions above by replace '/opt/dvr' with '/opt/local'.

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.27
sudo port install mythweb.26
sudo port install mythweb.25
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.


If you

  1. Built and installed Myth and MythWeb yourself using MacPorts before September 24, 2014
  2. Upgraded ('sudo port selfupdate && sudo port upgrade outdated') after September 23, 2014

then the version of PHP used by MythWeb has been upgraded and you need to modify or re-do the following steps:

0) Stop the Apache2 server, if running

sudo port unload apache2

1) Register PHP 5.4 with Apache

In Terminal, enter:

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

2) Edit Apache's httpd.conf

In '/opt/local/apache2/conf/httpd.conf' , change the line:

Include conf/extra/mod_php.conf


Include conf/extra/mod_php54.conf

Verify that mod_php54.so module will be loaded. You should find the following line already added by the command in step 1) above.

LoadModule php5_module modules/mod_php54.so

If you find a line like the following, delete it or comment it out:

LoadModule php5_module modules/libphp5.so

3) Set up your PHP 5.4 configuration files We'll cheat and reuse the config file created for php5

sudo cp -np /opt/local/etc/php5/php.ini /opt/local/etc/php54/php.ini

4) Restart Apache2

sudo port load apache2

MythWeb should be back up running like before!


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.