Mac下PHP環境搭建,MacPHP環境搭建

來源:互聯網
上載者:User

Mac下PHP環境搭建,MacPHP環境搭建

1.啟動伺服器

MacBook-Air:~ wgyp$ sudo apachectl start

Password:

MacBook-Air:~ wgyp$ sudo apachectl -v

Server version: Apache/2.2.26 (Unix)

Server built:   Dec 10 2013 22:09:38

2.在瀏覽器中輸入http://localhost,會出現It works!的頁面

注意:如果沒有出現It works! 在瀏覽器中輸入127.0.0.1,如果出現,就是host綁定出現錯誤了。

3.用vi開啟 /etc/apache2/httpd.conf中開啟

LoadModule php5_module libexec/apache2/libphp5.so

的注釋代碼,用:w儲存,:q退出編輯.

注意:會出現readonly許可權,可以右擊檔案,選擇簡介(Get info)》共用許可權(Shareing&permissions)開啟》選擇右下角的小鎖。就可以編輯檔案讀寫權限了。

4.重啟Apache,在終端輸入 sudo apachectl restart  PHP就可以用了。

5.編輯php檔案。將檔案/Library/WebServer/Documents/index.html.en複製一份,改名info.php,修改內容為<?php phpinfo(); ?> 

6.重啟apache伺服器,在瀏覽器中輸入http://localhost/info.php。可以看到效果了。

注意:如果你按到出現:<?php phpinfo(); ?> 就是第三步沒有做好。

7.DocumentRoot,Apache預設讀入根目錄更改。

MacBook-Air:~ wgyp$ open /etc/apache2/

剛剛已經改變了httpd.conf的讀寫權限。找到DocumentRoot;把/Library/WebServer/Documents全部修改成你想要指向的檔案夾,在終端輸入 sudo apachectl restart 就行了。然後就在你指向的檔案夾裡編寫代碼,瀏覽器中輸入localhost+檔案名稱,就可以預覽了。

聯繫我們

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