本篇介绍如何在Mac OS上使用Apache服务器搭建PHP多站点虚拟主机环境。在Mac里,已经默认内置了Apache和PHP,下面就来介绍如何配置Apache虚拟主机。php
sudo apachectl start
sudo apachectl restart
sudo apachectl stop
sudo apachectl -v
#LoadModule php5_module libexec/apache2/libphp5.so
/Library/WebServer/Documents
文件夹下,新建index.php文件, 写入以下内容, 保存退出。<?php phpinfo(); ?>
sudo apachectl start
命令, 在浏览器中输入localhost/index.php
, 出现php信息,说明php环境配置成功。#Include /private/etc/apache2/extra/httpd-vhosts.conf
,去掉前面的“#”,保存并退出。<VirtualHost *:80> ServerName www.phptest.com DocumentRoot "/Users/guobangzgb/working/websites/phptest" <Directory "/Users/guobangzgb/working/websites/phptest"> DirectoryIndex index.html index.php index index.html default.html default.htm AllowOverride All Options Indexes MultiViews FollowSymLinks Require all granted </Directory> </VirtualHost>
/ect/hosts
文件就能够访问相关站点了。若是你的站点不是放置在/Library/WebServer/Documents
目录下,好比放到了本身的工做目录下~/myname
, 可能产生访问权限问题,页面出现403 Forbidden错误,请按照下面配置就能够解决问题。html
httpd.conf
文件中, 找到#LoadModule userdir_module libexec/apache2/mod_userdir.so #Include /private/etc/apache2/extra/httpd-userdir.conf #Include /private/etc/apache2/users/*.conf
删掉前面的注释,保存退出。web
<Directory "/Users/guobangzgb/working"> DirectoryIndex index.html index.php index index.html default.html default.htm AllowOverride All Options Indexes MultiViews FollowSymLinks Require all granted </Directory>