Montag, 11. Juli 2011

Web 001: Setting up Apache and Running phpinfo() on Mac OS X

Ok, so you just want that phpinfo() running within two minutes on your local Mac because you want to develop your website from your $HOME/Sites directory. Easy. Here's the out-of-the-box solution to that (its done on Mac OS 10.6, PHP and Apache are from the default installation).
  1. cp /etc/apache/http.conf /etc/apache/back_http.conf # No backup, no mercy.
  2. sudo vi /etc/apache/http.conf
  3. You need to change two lines: Locate "DocumentRoot" and set the path behind it to '/Users/yourUserHomeDirectory/Sites'. Then locate the <Directory "/Library/WebServer/Documents"> line and change the path to the one you entered above.
  4. Remove the '#' sign infront of the line starting with "LoadModule php5_module"
  5. Save the file and exit.
That should be it. Now just restart Apache by issuing
sudo /sbin/apachectl restart

You can use the two following scripts as a default template. Copy the text and place them two files within the ~/Sites directory.
The index.html file:
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<title>Index Testing PHP</title>
<br /><br />
<form method="POST" action="phpinfo.php">
<input type="submit">
Then enter the following into a file called phpinfo.php and place it in the ~/Sites directory as well.
<?php phpinfo(); ?>
Set permissions for phpinfo.php to 755 in order to be executable by Apache. Now enter http://localhost/~yourUserHomeDirectory/ into a browser. This will display a minimal page showing the path you entered above and a button. Hit the button and the phpinfo.php script will execute. This should be it.
In case you have trouble getting it running, feel free to leave a comment.

Keine Kommentare:

Kommentar veröffentlichen