/private/etc/apache2/httpd.conf
一、啟動Apache
sudo apachectl start
sudo apachectl -v 可以查看到Apache的版本信息
此時在瀏覽器中輸入http://localhost,會出現It works!的頁面
sudo apachectl restart 重啟Apache
二、運行PHP
1、找到Apache的配置文件,在目錄/etc/apache2/下,打開Finder,選擇"前往"-"前往文件夾",輸入"/etc/apache2/",找到其中的"httpd.conf"文件,選擇用文稿打開進行編輯,點按Command+F,搜索#LoadModule php5_module libexec/apache2/libphp5.so,如圖
把藍色那一行的#號去掉,然后保存,如果出現文本鎖定,無法解鎖的情況,解決辦法有兩種
a)選中該文件,右擊后選擇"顯示簡介",點擊右下角的小鎖的圖標,輸入電腦密碼解鎖,然后選擇左邊的+號鍵,選擇自己當前電腦登陸的用戶,將權限設置為讀與寫,如果還是不行,將其上一級文件夾權限同樣再修改一次。
b)將該文件復制到桌面,進行修改,修改后再復制到原來的文件夾替換之前的文件即可。
2、重啟Apache,在終端輸入 sudo apachectl restart
3、在終端輸入 sudo cp /Library/WebServer/Documents/index.html.en /Library/WebServer/Documents/info.php
即在Apache的根目錄下復制index.html.en文件並重命名為info.php。
4、打開info.php,在It works后面加上<?php phpinfo(); ?>,然后再次重啟Apache,在瀏覽器中輸入http://localhost/info.php,會出現一個顯示php信息的頁面,如圖所示。
Mac下配置Apache時遇到的Forbidden
You don't have permission to access /HelloMac.htm on this server.
OS X升級到Yosemite之后,自帶的Apache也從2.2升級到了2.4,訪問權限的配置上有所不同。
以配置alise別名目錄為例,把/Users/redraiment/workspace/映射到http://localhost/workspace/,在2.2版本中配置信息如下:
<IfModule alias_module> Alias /workspace "/Users/redraiment/workspace/" <Directory "/Users/redraiment/workspace/"> AllowOverride All Options Indexes MultiViews FollowSymLinks ExecCGI Order allow,deny Allow from all DirectoryIndex index.html index.php </Directory> </IfModule>
升級到2.4版本之后:Order allow,deny和Allow from all要改成Require all granted,如下所示:
<IfModule alias_module> Alias /workspace "/Users/redraiment/workspace/" <Directory "/Users/redraiment/workspace/"> AllowOverride All Options Indexes MultiViews FollowSymLinks ExecCGI Require all granted DirectoryIndex index.html index.php </Directory> </IfModule>


