標籤:
/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>
在Mac下配置php開發環境:Apache+php+MySql