在Mac下配置php開發環境:Apache+php+MySql

來源:互聯網
上載者:User

標籤:

/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,denyAllow 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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.