一个鲜为人知的秘密---Using Apache and PHP on Mac OS X

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/

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值