> php教程 > php手册 > MAC OSX10.9.2上搭建Apache,php,osx10.9.2apache

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

WBOY
풀어 주다: 2016-06-13 08:44:18
원래의
1040명이 탐색했습니다.

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行可以看到如下代码片段:

<Directory "/Library/WebServer/Documents">
    #
    # 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
</Directory>
로그인 후 복사

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

<Directory "<span>/Users/shelley/Sites</span>">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
로그인 후 복사

为何一定是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
<IfModule bonjour_module>
       RegisterUserSite customized-users
</IfModule>
로그인 후 복사

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

<VirtualHost *:80>
    DocumentRoot "/Users/shelley/Sites"
    ServerName www.shelleymyl.com
    ErrorLog "/Users/shelley/Sites/log/error.log"
    CustomLog "/Users/shelley/Sites/log/access.log" common
    <Directory />
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order deny,allow
                Allow from all
      </Directory>
</VirtualHost> 
로그인 후 복사

  

5- URL转发

先打开httpd.conf,确保下面这二行没有被注释掉:

LoadModule proxy_module libexec/apache2/mod_proxy.so
LoadModule proxy_http_module libexec/apache2/mod_proxy_http.so
로그인 후 복사

然后在httpd.conf最后加上

ProxyPass /HelloWorldApp http://localhost:8080/HelloWorldApp/<br />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.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
로그인 후 복사

在"5、URL转发"的基础上,再打开这二项

然后修改

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

NameVirtualHost *:80

<VirtualHost *:80>
        ProxyPreserveHost On
        ServerName www.yjmyzz.com

        ProxyPass / http://www.yjmyzz.com:8000/
        ProxyPassReverse / http://www.yjmyzz.com:8000/        
    
        ServerAdmin webmaster@localhost
</VirtualHost>
로그인 후 복사

这样就相当于把 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

 

  

 

  

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 추천
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿