說明:iMac自帶PHP和Apache伺服器,僅需配置即可。
1.進入 /etc/apache2
,編輯 httpd.conf
/etc/apache2
httpd.conf
- 啟動php環境。将下面這句前的
去掉。#
- 修改權限。
<Directory /> <Directory />
AllowOverrid none => Allow from all
Require all denied </Directory>
</Directory>
- 修改伺服器根目錄。
DocumentRoot "xxxxxx" DocumentRoot "/Users/layne/WebServer"
<Directory "XXXXXX"> => <Directory "/Users/layne/WebServer">
...... ......
</Directory> </Directory>
- 增加預設檔案(index.php)。
<IfModule dir_module> <IfModule dir_module>
DirectoryIndex index.html => DirectoryIndex index.html index.php
</IfModule> </IfModule>
2.重新開機Apache
~layne$sudo apachectl restart //重新開機
//~ layne$sudo apachectl start //啟動
3.這時隻要把你的php檔案(如test.php)放到 /Users/layne/WebServer
目錄下,然後在浏覽器輸入 http://localhost/test.php
即可通路。
/Users/layne/WebServer
http://localhost/test.php