MAC OSX10.9.2上搭建Apache,php,osx10.9.2apache_PHP教程

來源:互聯網
上載者:User

MAC OSX10.9.2上搭建Apache,php,osx10.9.2apache


mac osx10.9.* 內建了apache, php

Apache配置

1- 啟動

sudo apachectl start

啟動後,訪問 http://localhost/ 應該能看到"It works!"的初始頁面,

vi /etc/apache2/httpd.conf

197行可以看到如下程式碼片段:

    #    # Possible values for the Options directive are "None", "All",    # or any combination of:    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews    #    # Note that "MultiViews" must be named *explicitly* --- "Options All"    # doesn't give it to you.    #    # The Options directive is both complicated and important.  Please see    # http://httpd.apache.org/docs/2.2/mod/core.html#options    # for more information.    #    Options Indexes FollowSymLinks MultiViews    #    # AllowOverride controls what directives may be placed in .htaccess files.    # It can be "All", "None", or any combination of the keywords:    #   Options FileInfo AuthConfig Limit    #    AllowOverride None    #    # Controls who can get stuff from this server.    #    Order allow,deny    Allow from all

cd /Library/WebServer/Documents

It Works 內容在 index.html.en 這是apache的預設頁

2- 停止/重啟

sudo apachectl stop

sudo apachectl restart

3- 建立個人網站目錄

cd ~

mkdir Sites

echo "helloWorld" >> index.html

sudo apachectl restart

然後再訪問 http://localhost/~shelley/ 應該就能看到"helloWorld"的個人目錄初始頁面(註:~shelley需換成~你的使用者名稱

如果失敗

sudo vi /etc/apache2/users/Guest.conf

/Users/shelley/Sites">    Options Indexes MultiViews    AllowOverride None    Order allow,deny    Allow from all

為何一定是Sites目錄名,

vi /etc/apache2/extra/httpd-userdir.conf

第10行

# Settings for user home directories## Required module: mod_userdir## UserDir: The name of the directory that is appended onto a user's home# directory if a ~user request is received.  Note that you must also set# the default access control for these directories, as in the example below.#UserDir Sites## Users might not be in /Users/*/Sites, so use user-specific config files.#Include /private/etc/apache2/users/*.conf       RegisterUserSite customized-users

4- 啟動虛擬機器主機

預設情況下,apache的虛擬機器主機功能是關閉的

sudo vi /etc/apache2/httpd.conf

放開注釋

#Virtual hosts#Include /private/etc/apache2/extra/httpd-vhosts.conf

修改檔案

sudo vi /etc/apache2/extra/httpd-vhosts.conf

類似以下內容

NameVirtualHost *:80    DocumentRoot "/Users/shelley/Sites"    ServerName www.shelleymyl.com    ErrorLog "/Users/shelley/Sites/log/error.log"    CustomLog "/Users/shelley/Sites/log/access.log" common                    Options Indexes FollowSymLinks MultiViews                AllowOverride None                Order deny,allow                Allow from all       

  

5- URL轉寄

先開啟httpd.conf,確保下面這二行沒有被注釋掉:

LoadModule proxy_module libexec/apache2/mod_proxy.soLoadModule proxy_http_module libexec/apache2/mod_proxy_http.so

然後在httpd.conf最後加上

ProxyPass /HelloWorldApp http://localhost:8080/HelloWorldApp/
ProxyPassReverse /HelloWorldApp http://localhost:8080/HelloWorldApp/

這樣訪問 http://localhost/HelloWorldApp、http://ip/HelloWorldApp、http://www.shelleymyl.com/HellpWorldApp 都相當於訪問 http://localhost:8080/HelloWorldApp

6- 連接埠轉寄

假如伺服器上有一個應用 http://x.x.x.x:8080/ ,如果想通過類似 http://www.shelleymyl.com 的網域名稱來直接存取,就需要做連接埠轉寄,仍然開啟httpd.conf

LoadModule proxy_connect_module modules/mod_proxy_connect.soLoadModule proxy_ftp_module modules/mod_proxy_ftp.so

在"5、URL轉寄"的基礎上,再開啟這二項

然後修改

sudo vi /etc/apache2/extra/httpd-vhosts.conf

NameVirtualHost *:80        ProxyPreserveHost On        ServerName www.yjmyzz.com        ProxyPass / http://www.yjmyzz.com:8000/        ProxyPassReverse / http://www.yjmyzz.com:8000/                    ServerAdmin webmaster@localhost

這樣就相當於把 80連接埠轉寄到8080連接埠上了

PHP配置

PHP的配置非常簡單,就一個事

vi /etc/apache2/httpd.conf

LoadModule php5_module libexec/apache2/libphp5.so

放開注釋

然後sudo apachectl restart 重啟,在使用者目錄的Sites檔案夾下,建立一個index.php,裡面echo phpinfo() ,就可以看到效果了:

reference:

http://www.cnblogs.com/yjmyzz/p/3920361.html

  

  

http://www.bkjia.com/PHPjc/1110971.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1110971.htmlTechArticleMAC OSX10.9.2上搭建Apache,php,osx10.9.2apache mac osx10.9.* 內建了apache, php Apache配置 1- 啟動 sudo apachectl start 啟動後,訪問http://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.