Apache, PHP on external HD?

I'm creating a local network via airport for displaying photo galleries in relative real-time. I'll be exporting each gallery from lightroom to a folder within a firewire drive (we'll call this the 'event folder') connected the main machine. I will be using other machines connected via airport so that people can view any gallery listed within the event folder. I need to, now, figure out a way to easily allow those other machines to view a list of the galleries and view them. Additional galleries will be added throughout the day. I determined, with some advice, that this could be done using a web page that lists the gallery folders within the event folder. Gallery folders will each have their own index.html file as created by lightroom.

I've been working with someone who tried to write me up some php code to make it work, however, he said I need to have apache and php installed. I've enabled web sharing, but that still didn't allow the code he provided to work.

Do I need to somehow install apache and php on that hard drive directly or is there something else I need to do?

Also, if anyone has any comments or suggestions for a solution to my main objective, please opine. I'm very open to suggestions. Please remember, coding/scripting languages are gibberish to me, but I am very good at following directions. Here also are two different version of php that my friend provided to accomplish this project. Feel free to inspect it and comment.

<?php
$current_dir = "$DOCUMENT_ROOT"."dirname/"; //Put in second part, the directory - without a leading slash but with a trailing slash!
$dir = opendir($current_dir); // Open the sucker

echo ("<p><h1>List of available files:</h1></p><hr><br />");
while ($file = readdir($dir)) // while loop
{
$parts = explode(".", $file); // pull apart the name and dissect by period
if (is_array($parts) && count($parts) > 1) { // does the dissected array have more than one part
$extension = end($parts); // set to we can see last file extension
if ($extension == "ext" OR $extension == "EXT") // is extension ext or EXT ?
echo "<a href=\"$file\" target=\"_blank\"> $file </a><br />"; // If so, echo it out else do nothing cos it's not what we want
}
}
echo "<hr><br />";
closedir($dir); // Close the directory after we are done
?>

This can be used to list certain file extensions. If you want it to list all files, use this code:

<?php
$current_dir = "$DOCUMENT_ROOT"."dirname/"; //Put in second part, the directory - without a leading slash but with a trailing slash!
$dir = opendir($current_dir); // Open the sucker

echo ("<p><h1>List of available files:</h1></p><hr><br />");
while ($file = readdir($dir)) // while loop
{
echo "<a href=\"$file\" target=\"_blank\"> $file </a><br />"; // creates link to file
}
echo "<hr><br />";
closedir($dir); // Close the directory after we are done
?>

Remember to change "dirname/" to the directory you want to list. If you want to place the php file in the directory you want listed, eliminate "dirname/" and leave it "/"

iMac 2.4GHz Aluminum, Mac OS X (10.4.11)

Posted on Aug 5, 2009 9:31 PM

Reply
11 replies

Aug 5, 2009 10:35 PM in response to dubnluvn?

Apache and PHP are already installed on your system. Web sharing starts Apache, but you may need to enable PHP (I forget whether it's enabled by default or not).

You'll need to edit your apache configuration files to enable PHP. The specific file to edit depends on the version of Apache you're running.

For Apache 1.3 (default on Tiger and optional on Leopard) you need to edit /etc/httpd/httpd.conf and uncomment (remove the leading # from) the lines:

#LoadModule php4_module libexec/httpd/libphp4.so
#AddModule mod_php4.c


For Apache 2.x (the default under Leopard) you need to edit /etc/apache2/httpd.conf and uncomment the line:

#LoadModule php5_module libexec/apache2/libphp5.so


That should enable PHP. The second element involves telling Apache to look at the external drive for the web content to serve. For that, you need to edit the DocumentRoot directive in your site's configuration (either /etc/httpd/sites/ or /etc/apache2/sites depending on the version you're running).

Look for the line that begins with DocumentRoot and change the path to the folder on your external drive where your galleries are located, e.g.:

DocumentRoot "/Volumes/ExternalDisk/SomeOtherFolder"


rather than the default:

DocumentRoot "/Library/WebServer/Documents"

Aug 10, 2009 11:24 PM in response to dubnluvn?

You copy this(your conf) file first? You just want to comment out(#) the line as such:
#DocumentRoot "/Library/WebServer/Documents" and below that line add:
DocumentRoot "/Volumes/oldlacie/eventfolder" and save and close. Then type sudo apachectl stop and then sudo apachectl start. Also type httpd -t and see if it says syntax is good. Then cd /Volumes/oldlacie and type sudo chmod 755 eventfolder. And sudo chown root:admin eventfolder
Aside from all that code you presented earlier, do you have an index.html in your eventfolder to see if it will load? I've got a site on my Panther machine that is a stocker(unlike what you want) so all I'm doing here is seeing if we can get you working out of a new DocRoot. And you will probably have this problem and solution:
http://discussions.apple.com/message.jspa?messageID=9963118#9963118
And if my permissions are wrong, someone feel free to correct.

Message was edited by: doug pennington

Aug 11, 2009 12:17 AM in response to doug pennington

Ok I've done as you said. But still not working. A couple things to note:

1) If I attempt to open phpinfo.php in terminal or from the desktop it will open dreamweaver by default. If I type file:///Volumes/oldlacie/eventfolder/phpinfo.php in the address bar of safari it just prints the code in the browser.

2) I am not running Apache 2 so the link to that other problem/solution doesn't help.

3) here is the transcript of me following your directions:

matty:/volumes/oldlacie Matty$ sudo apachectl stop
/usr/sbin/apachectl stop: httpd stopped
matty:/volumes/oldlacie Matty$ sudo apachectl start
[Mon Aug 10 23:50:41 2009] [alert] httpd: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
/usr/sbin/apachectl start: httpd started
matty:/volumes/oldlacie Matty$ sudo apachectl start
/usr/sbin/apachectl start: httpd (pid 5020) already running
matty:/volumes/oldlacie Matty$ httpd -t
[Mon Aug 10 23:51:04 2009] [alert] httpd: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
Syntax OK
matty:/etc/httpd Matty$ cd /volumes/oldlacie
matty:/volumes/oldlacie Matty$ sudo chmod 755 eventfolder
Password:
matty:/volumes/oldlacie Matty$ sudo chown root:admin eventfolder
matty:/volumes/oldlacie Matty$

4) what do you mean an index.html doc? I have a couple .html docs in there and they work fine. I also have a little an simple feedback html file that when you click send is supposed to direct to a php doc. When you click the button the php code is just printed in the browser as well.

Aug 11, 2009 8:52 AM in response to dubnluvn?

#1 Put that phpinfo.php in your eventfolder and go to SysPrefs/Sharing and make sure web sharing is on and view your computer's website address that is highlighted there. Now if I wanted to see my phpinfo page I would type: http://192.168.0.4/info.php. And this refers to #4 http://en.wikipedia.org/wiki/Index.html, so copy this:

<HTML>
<HEAD>
</HEAD>
<BODY>
Hello world.
</BODY>
</HTML>

and save as index.html and put in eventfolder. Then do the sharing call from above without the extra phpinfo added. You should then see this index.html(aka home page).
That server name item. Are you trying to run this over the internet, like now?

That wiki link went south, but was meant to be an explanation of what an index.html is.

Message was edited by: doug pennington

Aug 11, 2009 9:54 AM in response to doug pennington

Sweet...I woke up this morning a tried just typing 192.168.2.10/phpinfo.php and I got the info page. Awesome. Then I tried the feedback.html file that points to a php doc and that work too.

Doug,
Thanks for all your help, and everyone else's, thus far. All I'm trying to do, is make a webpage on my local network (not for internet) so that local Machines can display any the folders within that 'eventfolder'. Which one of the codes my friend gave me does, sort of.

I just tried making a sample gallery using my workflow and it works perfectly. Now I just need to make the page that displays the 'eventfolder' contents in a clean and dare I say 'stylish' way. So for now this is solved! If anything pops up I'll let you know. Thanks thanks thanks thanks!!!

Aug 11, 2009 10:25 AM in response to dubnluvn?

Dub, that's great. You're welcome. Ignore that message of: httpd: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName. It resolves back anyway as seen in this next sentence. From config: "127.0.0.1 is the TCP/IP local loop-back address, often named localhost. Your
machine always knows itself by this address." Doug

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Apache, PHP on external HD?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.