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

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

WBOY
WBOY原創
2016-06-13 08:44:181037瀏覽

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

 

  

 

  

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn