為Mac內建的Apache配置PHP和虛擬機器

來源:互聯網
上載者:User
作業系統:os x 10.11.2

1、啟動apache

開啟終端(terminal),輸入命令:sudo apachectl -k start ;

在瀏覽器地址欄中輸入:http://localhost,顯示如下資訊則apache正常啟動

apache相關命令:啟動:sudo apachectl start停止:sudo apachectl stop重啟:sudo apachectl restart查看版本號碼:sudo apachectl -v

2、添加PHP模組

在終端中輸入命令:sudo vi /etc/apache2/httpd.conf ,開啟httpd.conf

去掉PHP模組前面的注釋 '#',重啟apache,php添加成功

3、配置‘mysites’虛擬機器

1.在終端輸入命令:mkdir /Users/你的使用者名稱/Sites ,添加此檔案夾做為'mysites'虛擬機器的實體儲存體位置。

2.開啟httpd.config,去掉"# Include /private/etc/apache2/extra/httpd-vhosts.conf"前面的'#'。

3.選擇 DocumentRoot "/Library/WebServer/Documents" "/Library/WebServer/Documents"> ... 之間的內容,複製這些內容到它的下方;修改黃色地區修改為 "/Users/你的使用者名稱/Sites",儲存退出。

在終端輸入命令:sudo vi /etc/apache2/extra/httpd-vhosts.conf ,開啟httpd-vhosts.conf。

注釋兩個預設的虛擬機器,在每一行前面加'#'

接下來,添加如下代碼,儲存退出,重啟apache

# 'localhost'虛擬機器    DocumentRoot "/Library/WebServer/Documents"    ServerName localhost    ErrorLog "/private/var/log/apache2/localhost-error_log"    CustomLog "/private/var/log/apache2/localhost-access_log" common # 'mysites'虛擬機器    DocumentRoot "/Users/你的使用者名稱/Sites"    ServerName mysites    ErrorLog "/private/var/log/apache2/mysites-error_log"    CustomLog "/private/var/log/apache2/mysites-access_log" common 

在終端輸入命令: sudo vi /etc/hosts ,添加 "127.0.0.1 mysites",儲存退出

在終端輸入命令:sudo vi /Users/你的使用者名稱/Sites/info.php ,添加 "" ,儲存退出

在瀏覽器中輸入 http://mysites/info.php

到此結束,謝謝閱讀!

濁水輕舟於2016.1.12寫

參考文檔:http://www.cnblogs.com/snandy/archive/2012/11/13/2765381.html

以上就介紹了為Mac內建的Apache配置PHP和虛擬機器,包括了方面的內容,希望對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.