说明:iMac自带PHP和Apache服务器,仅需配置即可。
1.进入/etc/apache2,编辑httpd.conf
# LoadModule php5_module libexec/apache2/libphp5.so
<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>
<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即可访问。