1.部署和安装
mac是自动安装了apache和php程序的.
Apache的默认根目录: “/Library(资源库)/WebServer/Documents/”。 根目录就是存放给浏览器用户访问的文件和资源等.
Apache的安装目录在:/etc/apache2/
开发过程中,觉得在默认根目录下放文件不方便, 更换根目录的方法:
1.1 打开配置文件: sudo vi /etc/apache2/httpd.conf
1.2 修改DocumentRoot ,如下:
将系统默认的根目录修改为自己想要存放的根目录.即将 DocumentRoot "/Library/WebServer/Documents" 修改为:DocumentRoot "/mypath/..."
最后是放在自己的家目录下,即 DocumentRoot "/Users/zhailianxing" 或者 DocumentRoot "/Users/zhailianxing/mywork"
2 查看版本
sudo apachectl -v
3. apache 的启动/关闭/重启
sudo apachectl start/stop/restart
4. 测试apache服务器是否启动成功
浏览器中输入
http://localhost 或者 http://localhost/index.html.en
如果显示出"It works"则表明apache服务器启动成功.
注: 1.http://localhost 默认访问的是index.html.en文档.
2.index.html.en默认是放在原始的默认/Library/WebServer/Documents目录下
5. 启用php
打开文件 sudo vi /etc/apache2/httpd.conf
找到 #LoadModule php5_module libexec/apache2/libphp5.so 去掉 #
6.测试php环境是否正常显示:
在apache根目录下[即
/Library/WebServer/Documents下] 新增一个 test.php文件, 其内容如下:
<?php
phpinfo(); <!--php的库函数 --!>
?>
在浏览器中输入 http://localhost/test.php .如果页面能显示出相关的信息,则php环境正常