Mac OS X 10.10 Yosemite下配置 apache+php

來源:互聯網
上載者:User

標籤:style   blog   http   io   color   ar   os   使用   sp   

  
   自從系統從OS X Mavericks 10.9升級到OS X Yosemite 10.10 後之前配置apache和php均不能正常使用了,

   重新設定配置如下:

 首先,查看當前系統的apache版本,終端下輸入:httpd -v

  

  Apache/2.4.0 

   1. 啟動Apache 服務
      sudo apachectl start
      開啟safari,訪問:http://localhost,顯示“It works!”表示Apache啟動正常

      當前訪問的是Apache的預設目錄,/Library/WebServer/Documents/

   2. 配置使用者訪問目錄
      因為之前已經配置過使用者目錄,這裡提一下,首先建立使用者目錄:mkdir  ~/Sites 此時會在目前使用者的根目錄下建立一個Sites目錄
      可以在Sites目錄下建立一個測試的html,或者cp /Library/WebServer/Documents/index.html.en ~/Sites/
      
      修改目前使用者目錄的存取權限,這個與上一個版本一致沒有變化,這裡提一下修改方式:
      cd /etc/apache2/users
      sudo vim username.conf
      注意:這裡的username是目前使用者名,請根據實際情況修改
   
      輸入以下內容:

<Directory "/Users/username/Sites/">     Options Indexes MultiViews     AllowOverride All     Order allow,deny     Allow from all</Directory>

 

  儲存檔案,重啟apache ,sudo  apachectl restart

      修改當前檔案的存取權限:sudo chmod 775 username.conf

  此時開啟safari,訪問http://localhost/~username/    , 此時頁面提示~username伺服器不存在,我們還需要進入下一步的設定

 

3. 修改apache的httpd.conf檔案

  cd  /etc/apache2/

  sudo vim httpd.conf

  找到以下資訊,將其前面的#去掉:

LoadModule php5_module libexec/apache2/libphp5.soLoadModule authz_core_module libexec/apache2/mod_authz_core.soLoadModule authz_host_module libexec/apache2/mod_authz_host.soLoadModule userdir_module libexec/apache2/mod_userdir.soInclude /private/etc/apache2/extra/httpd-userdir.conf

 

  修改/etc/apache2/extra/httpd-userdir.conf

  sudo vim /etc/apache2/extra/httpd-userdir.conf

  找到一下資訊修,將其前面的#去掉:

Include /private/etc/apache2/users/*.conf

 

  此時訪問http://localhost/~username/, 依然無法訪問,提示:You don‘t have permission to access /~username/ on this server.

  

  這裡是就是新版本與老版本的區別了,需要重新開啟httpd.conf檔案,

  sudo vim /etc/apache2/httpd.conf

  找到

<Directory />    AllowOverride none    Require all denied</Directory>

  修改為:

<Directory />    AllowOverride none    Require all granted</Directory>

 

  重啟apache,sudo apachectl restart

  此時訪問:http://localhost/~username/,顯示:“It works!”,恭喜你,Apache配置成功!

  

4. 配置PHP

  cd /etc

  sudo cp /etc/php.ini.default /etc/php.ini

  sudo apachectl restart

  建立info.php檔案測試php是否安裝成功

  cd ~/Sites

  vim info.php

  輸入以下資訊:

<html>    <body>        <h1>It works!</h1>        <?php phpinfo(); ?>    </body></html>    

  開啟瀏覽器,訪問http://localhost/~username/info.php,顯示一下資訊表示php安裝配置成功~

 

  

  

 

Mac OS X 10.10 Yosemite下配置 apache+php

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.