Setting Up A Mac as Webserver - Gallery Codex
Personal tools

Setting Up A Mac as Webserver

From Gallery Codex

BACKGROUND NOTES

  • The procedure for setting up the Mac is largely from http://NerdVittles.com but this represents an adaptation for setting up on OS X Tiger directly since he recommended setting up on OS X Panther, upgrading to OS X Tiger and then applying some tweaks. He also provides information on setting up Webmin and the Webalizer (for visitor stats) which are not included here but you can check the site for details on those.
  • The abbreviation CTRL is used to represent the COMMAND Key.
  • The Document Revision Date is OCTOBER 2006.
  • Minor edit June 2007. Links and software versions still as at October 2006.

PREREQUISITES

  • Apple Machintosh computer running OS X Tiger (A dedicated MacMini works well but any Apple Mac will do the job)
  • Full administrative rights on the computer
  • Internet connection (The faster the better)
  • Dynamic DNS Configurable Router (Linksys WAG54GS recommended). This is serves as a hardware firewall and will help update your IP address

PREPARATION

  • Install additional Software from OS X Installation disk. Not strictly neccesary but not a bad idea either as it enables you to compile from source.
    • Install Xcode Tools (Easy Install)
    • Install Developer Tools (Easy Install)
  • Setup a free account on a service such as http://www.dyndns.com (This particular one will work with the Linksys WAG54GS to automatically update your IP Address). This sort of service will enable people to find your server by typing in an "regular" web address. Using the software based updater the site (and others) provide will not work when you are behind a router as it will update with your machine address to the router and not the router address to the internet.
  • Setup the router to update your IP Address with dyndns
  • Run Software Update and install up to date system software
  • Switch on OS X Firewall
    • System Preferences -> Sharing -> Firewall -> Start
  • Start Apache Webserver
    • System Preferences -> Sharing -> Services -> Personal Web Sharing

Congratulations! You have a server working. You can navigate to your dyndns address from a remote computer and will be served the default apache page. Add content and it will be served.

However, you are not yet ready to run the Gallery software as you don't have PHP or MySQL.

SETUP TO RUN GALLERY

Install MySQL

Notes

MySQL is installed in an unsecure state. It is critical to secure the installation after.

All commands for Terminal should be entered without the $ sign.

Do not copy / paste. All text must be typed in

Installation Steps

  • Download MySQL (I have used Version 4.1.15 from http://dev.mysql.com/downloads/mysql/4.1.html)
  • Install mysql-standard Package
  • Install MySQLStartupItem package as prompted
  • Install PrefPane for yourself only
    • This is used to set prefernces for MySQL. MySQL should always be on.
  • Reboot

Secure MySQL

  • Launch Terminal
    • Applications -> Utilities -> Terminal
  • Log into Terminal
$ sudo su
Enter password on prompt
  • Connect to MySQL and Set MySQL Password
 $ /usr/local/mysql/bin/mysql
$ update mysql.user set password = password('enter a really secure password here. You probably will never use it again') where host<>‘localhost’ ; 
  • Write Changes to Disk and Exit
$ flush privileges ;
$ \q
$ Exit
$ Exit
Press CTRL Q

Install PHP

Notes

All commands for Terminal should be entered without the $ sign.

Do not copy / paste. All text must be typed in

Installation Steps

  • Download PHP
    • Mac Legend, Marc Liyanage, has binary packages on his site at http://www.entropy.ch/software/macosx/php
    • If for any reason this doesn't work, then it's off to http://www.php.net/ for the source code which you will have to compile and configure yourself. Search the web for instructions...it is not too difficult.

Configure Apache for PHP on OS X (Based on PHP 4.x.x)

  • Launch Terminal and Log in
$ sudo su
Enter password on prompt
  • Backup Apache Config File so you can revert if anything goes wrong.
$ cd  /etc/httpd
$ cp httpd.conf httpd.sav
  • Edit Apache Config File
Step 1. $ pico httpd.conf
Step 2. Press CTRL W
Step 3. $ PHP
Step 4. Press ENTER
Step 5. Repeat Steps 2 - 4 until this line: #LoadModule php4_module
Step 6. Place cursor on # and delete pressing CTRL D.
Step 7. Repeat Steps 2 - 4 until this line: #AddModule mod_php4.c
Step 8. Place cursor on # and delete by pressing CTRL D
  • Close file and exit
Press CTRL X
$ y
Press ENTER 
$ exit
$ exit
Press CTRL Q

Reboot Apache

  • Shut Down Apache
    • System Preferences -> Sharing -> Uncheck "Personal Web Sharing" and wait for confirmation
  • Start Apache
    • Select "Personal Web Sharing"

Check PHP Installation

  • Create a new text file with TextEdit
  • Change to Plain Text Format
    • Format -> Make Plain Text
  • Type in
<?php 
phpinfo(); 
?> 
  • Save as "info.php" in Unicode (UTF-8) format to /Library/WebServer/Documents. Don't append ".txt" to the filename when prompted
  • Navigate to localhost/info.php with your web browser and you should see a PHP generated page. If not, recheck to make sure your web server is running and there are no mistakes in the info.php file
  • Delete the file as it presents a possible security risk if left on your server

Install PHPmyAdmin

Notes

PHPmyAdmin is installed in an unsecure state. It is critical to secure the installation after.

Do not copy / paste. All text must be typed in

Installation Steps

Secure PHPMyAdmin

  • Open config.inc.php with textedit
  • Change the line that reads
$cfg[’PmaAbsoluteUri_DisableWarning’] = FALSE; 

 to

 $cfg[’PmaAbsoluteUri_DisableWarning’] = TRUE;
  • Change this block of text
$cfg[’Servers’][$i][’AllowRoot’] = TRUE; // whether to allow root login
$cfg[’Servers’][$i][’AllowDeny’][’order’] // Host authentication order, leave blank to not use
= ‘’;
$cfg[’Servers’][$i][’AllowDeny’][’rules’] // Host authentication rules, leave blank for defaults
= array();

to 

$cfg[’Servers’][$i][’AllowRoot’] = TRUE; // whether to allow root login
$cfg[’Servers’][$i][’AllowDeny’][’order’] // Host authentication order, leave blank to not use
= ‘deny,allow’;
$cfg[’Servers’][$i][’AllowDeny’][’rules’] // Host authentication rules, leave blank for defaults
= array(’deny root from all’,'allow root from localhost’,'allow root from PutYourIPNoHere′,);

NOTE: Put in your IP Address in place of "PutYourIPNoHere" above
  • Save file and close

Prepare For G2 Installation

Launch PHPMyAdmin and create database for G2

  • Navigate to "localhost/php/" or to "YourIPAddress/php/" to launch PHPmyAdmin
  • Type "gallery2" (or whatevername you want) in the space for database name
  • Change collation to UTF-8 bin
  • Create

Create folder to hold G2 info

Launch Terminal
$ sudo su
$ cd  /library/webserver
$ mkdir g2data
$ chmod 777 g2data
$ exit
$ exit
Press CTRL Q

Download and Install G2

You can find information here.