MAC OSX 10.10 下起用自带的Apache和PHP

MAC OSX 10.10 下启用自带的Apache和PHP

Mac 系统自带Apache和PHP,只要你开启即可使用 



1.修改Apache配置文件

sudo vim /etc/apache2/httpd.conf。

取消注释掉下面两行

LoadModule rewrite_module libexec/apache2/mod_rewrite.so

LoadModule php5_module libexec/apache2/libphp5.so

注释掉221行的#Require all denied

212 #ServerName www.example.com:80
213
214 #
215 # Deny access to the entirety of your server's filesystem. You must
216 # explicitly permit access to web content directories in other
217 # <Directory> blocks below.
218 #
219 <Directory />
220     AllowOverride none
221 #    Require all denied
222 </Directory>


另外取消499行的注释,使apache的vhost设置生效

497
498 # Virtual hosts
499 Include /private/etc/apache2/extra/httpd-vhosts.conf
500
501 # Local access to the Apache HTTP Server Manual

502 #Include /private/etc/apache2/extra/httpd-manual.conf



2. vim/etc/apache2/extra/httpd-vhosts.conf

添加如下内容(sheng 是我的用户名,xxx是自己添加的虚拟域名)

  <VirtualHost *:80>
      DocumentRoot "/Users/sheng/site/xxx"
      ServerName xxx.com
      <Directory "/Users/sheng/site/xxx">
          Options FollowSymLinks
          AllowOverride All
          Require all granted
      </Directory>
</VirtualHost>

3. 修改本机的host设置

vim /etc/hosts

添加一行

 127.0.0.1   xxx.com

4.打开终端命令行

sudo apachectl start。


5. 在/Users/sheng/site/xxx放一个index.php 文件

可以写入如下内容。(MAC OSX 10.10的PHP 版本在5.4以上,不知道为什么短标签默认不能用)

<?php

echo "hello php";

?>

打开浏览器 

type 

xxx.com

and try out!


版权声明:本文为博主原创文章,未经博主允许不得转载。