1. 启动Apache(mac中已经默认集成,直接开启服务即可)
打开终端,输入:
<table border="0" cellpadding="0" cellspacing="0"Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size:12px!important; min-height:inherit!important">
<codeBitstream Vera Sans Mono','Courier New',Courier,monospace!important; min-height:inherit!important">sudo apachectl start
打开浏览器,输入:
<table border="0" cellpadding="0" cellspacing="0"Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size:12px!important; min-height:inherit!important">
<codeBitstream Vera Sans Mono','Courier New',Courier,monospace!important; min-height:inherit!important">http:<codeBitstream Vera Sans Mono','Courier New',Courier,monospace!important; min-height:inherit!important; color:rgb(0,130,0)!important">//localhost
应该可以看到”It works!“的页面,该页面位于/Library/WebServer/Documents/目录下,这是Apache的默认根目录(可以更改为自己目录,或者建虚拟目录)。
2.开启php
在终端中输入:
<table border="0" cellpadding="0" cellspacing="0"Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size:12px!important; min-height:inherit!important">
<codeBitstream Vera Sans Mono','Courier New',Courier,monospace!important; min-height:inherit!important">cd /etc/apache2/
<codeBitstream Vera Sans Mono','Courier New',Courier,monospace!important; min-height:inherit!important">sudo vi httpd.conf
在vi中,输入/php搜索包含php的文本,找到:
<table border="0" cellpadding="0" cellspacing="0"Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size:12px!important; min-height:inherit!important">
<codeBitstream Vera Sans Mono','Courier New',Courier,monospace!important; min-height:inherit!important; color:gray!important">#LoadModule php5_module libexec/apache2/libphp5.so
删除前面的#,然后保存退出。(按shift+i行首输入,按ESC退出编辑,按x删除当前字符,及#,输入:wq,保存并退出。)
在终端输入:
<table border="0" cellpadding="0" cellspacing="0"Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size:12px!important; min-height:inherit!important">
<codeBitstream Vera Sans Mono','Courier New',Courier,monospace!important; min-height:inherit!important">cd /etc
<codeBitstream Vera Sans Mono','Courier New',Courier,monospace!important; min-height:inherit!important">sudo cp php.ini.<codeBitstream Vera Sans Mono','Courier New',Courier,monospace!important; min-height:inherit!important; color:rgb(0,0,255)!important">default <codeBitstream Vera Sans Mono','Courier New',Courier,monospace!important; min-height:inherit!important">php.ini
<codeBitstream Vera Sans Mono','Courier New',Courier,monospace!important; min-height:inherit!important">sudo apachectl restart
<table border="0" cellpadding="0" cellspacing="0"Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size:12px!important; min-height:inherit!important">
<codeBitstream Vera Sans Mono','Courier New',Courier,monospace!important; min-height:inherit!important; color:gray!important">vi index.php
然后在info.php中输入以下内容:
<html><body><h1>HelloWorld!</h1><?php phpinfo(); ?></body></html>在浏览器输入:
127.0.0.1即可出现HelloWord和php信息
4.常见错误
a.由于修改错误的httpd.conf无法打开127.0.0.1首先检测hosts文件;
b.确认无问题后 ,在当前目录找到httpd.conf~previous 替换即可,或者找个同事 把httpd 传一份过来覆盖即可。
c.测试php文件不执行php脚本:测试文件后缀名.html 改为.php
版权声明:本文为博主原创文章,未经博主允许不得转载。
以上就介绍了Mac OS X 1010中配置Apache + PHP,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!