NOTE: My MAC OS version is 10.6.4
首先可以参考的文档是Apple官方文档(https://developer.apple.com/library/mac/#featuredarticles/EnablingPHP/),但是里面没有描述一些关键的文件夹和文档的路径, 下面的文字则详细的说明了关键文件夹和文件的路径。
If you’re running Mac OS X it has some surprises for you. Seems, PHP and the Apache Web Server have been installed on your machine without your knowledge. Well, its no secret but running them both is somewhat of a mystery and the trick is to flush them out of their hiding spots.
Generally on a Mac there are Icons that represent programs and documents that you double-click to execute their existence. With PHP and Apache, they run in the background with no sign of an Icon in sight.
To start Apache Web Server, you must go into the “System Preferences Control panel located on the “Apple Menu”.
Click on the Icon labeled "Sharing". Then locate the tab labeled "File & Web". You will want to click the button labeled “Start” in the "Web Sharing " section. This starts up Web sharing which starts the Apache Web Server.
Apache Web Server is now running. Easy, huh? "How can I tell?” you ask. Simple. Start up your web browser of choice. In the web address or URL part of your browser, type: "localhost" (without the double-quotes)
Ex. http://localhost
If everything is Okay, your browser will display the following:
"If you can see this, it means that the installation of the Apache Web server software on this system was successful. You may now add content to this directory and replace this page."
or
"It works!"
It worked! Hooray.
To access the pages of this directory, double-click on your hard drive and locate the "Library" directory. From there locate the "WebServer" directory and then the "Documents" directory where these web pages reside.
Note: If its not running, you either do not have web sharing enabled or something is wrong with Apache's files. It should work right out of the box.
Since Mac OS X is a multi-user system, every person has their own account and with that brings it’s own set of web pages. To access your personal web pages you must type the following in the browser address:
Ex. http://localhost/~yourname/
To access your personal web pages, locate your account name directory under "Users" And locate the directory labeled "Sites".
/Users/yourname/Sites/your web pages are here <---
Now that you have Apache running, it would be great to write your own PHP scripts and run them locally on your Mac. This is the most difficult part and if you get past this, everything is downhill with ease.
By default, PHP is disabled along with other features of the Apache Web Server, but we are going to concentrate on enabling PHP.
There is a file called "httpd.conf". The Official name for this file is: "Apache HTTP Server Configuration file". This is our mission. You are going to "uncomment" four lines of the "httpd.conf" file. This requires us to use a text editor to do the job.
Using the Terminal.app, Start the Terminal.app located in the "/Applications/Utilities/" directory, then change the directory to the "httpd" directory using the following command:
cd /etc/httpd
or
cd /etc/apache2/
Next step is to use "root" privileges, start up the text editor named vi and edit the "httpd.conf" file.
However, which options you should uncommented, I don't know. So, I suggest you using scripts metioned in apple offical document "Enabling PHP and SQLite on Mac OS X Leopard" to modify the options to enable PHP in apache.
以上内容参考:
http://www.devarticles.com/c/a/Apache/Using-Apache-and-PHP-on-Mac-OS-X/
http://www.anujgakhar.com/2009/01/19/how-to-edit-httpdconf-on-macos/
https://developer.apple.com/library/mac/#featuredarticles/EnablingPHP/