zoukankan      html  css  js  c++  java
  • Windows下实战Apache+PHP [转]

     

     
     

    一、Apache


    1、下载
    登陆Apache Lougne(http://www.apachelounge.com/download/),找到最新版本的Apache。笔者下载的是带IPv6和Crypto的2.4.3版本,大小为10.8MB,下载地址:http://www.apachelounge.com/download/win32/binaries/httpd-2.4.3-win32.zip

    另外如果你的系统没有安装VC10,还需要另外下载安装,下载页面:http://www.microsoft.com/en-us/download/details.aspx?id=8328


    2、配置
    将下载的压缩包解压,删除以下无用文件:
    /*.txt
    /manuals


    打开/conf/httpd.conf,清空文件,写入以下内容:
    LoadModule access_compat_module modules/mod_access_compat.so
    LoadModule actions_module modules/mod_actions.so
    LoadModule alias_module modules/mod_alias.so
    LoadModule allowmethods_module modules/mod_allowmethods.so
    LoadModule asis_module modules/mod_asis.so
    LoadModule auth_basic_module modules/mod_auth_basic.so
    LoadModule authn_core_module modules/mod_authn_core.so
    LoadModule authn_file_module modules/mod_authn_file.so
    LoadModule authz_core_module modules/mod_authz_core.so
    LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
    LoadModule authz_host_module modules/mod_authz_host.so
    LoadModule authz_user_module modules/mod_authz_user.so
    LoadModule autoindex_module modules/mod_autoindex.so
    LoadModule cgi_module modules/mod_cgi.so
    LoadModule dir_module modules/mod_dir.so
    LoadModule env_module modules/mod_env.so
    LoadModule include_module modules/mod_include.so
    LoadModule isapi_module modules/mod_isapi.so
    LoadModule log_config_module modules/mod_log_config.so
    LoadModule mime_module modules/mod_mime.so
    LoadModule negotiation_module modules/mod_negotiation.so
    LoadModule setenvif_module modules/mod_setenvif.so

    <IfModule unixd_module>
    User daemon
    Group daemon
    </IfModule>
    LoadModule php5_module "C:/Apache24/cgi-bin/php/php5apache2_4.dll"
    PHPIniDir "cgi-bin/php"
    AddHandler application/x-httpd-php .php
    Listen 80
    <VirtualHost *:80>
    LogLevel warn
    ErrorLog "logs/error.log"
    CustomLog "logs/access.log" common
    DocumentRoot htdocs
    <Directory />
        Options FollowSymLinks
        DirectoryIndex index.html default.htm index.php
        AllowOverride All
        Order deny,allow
        Allow from all
    </Directory>
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
    </VirtualHost>

    <Files ".ht*">
        Require all denied
    </Files>

    <IfModule log_config_module>
        LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined
        LogFormat "%h %l %u %t "%r" %>s %b" common
        <IfModule logio_module>
          LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i" %I %O" combinedio
        </IfModule>
        CustomLog "logs/access.log" common
    </IfModule>

    <IfModule mime_module>
        TypesConfig conf/mime.types
        AddType application/x-compress .Z
        AddType application/x-gzip .gz .tgz
    </IfModule>

    <IfModule proxy_html_module>
    Include conf/extra/proxy-html.conf
    </IfModule>

    <IfModule ssl_module>
    SSLRandomSeed startup builtin
    SSLRandomSeed connect builtin
    </IfModule>

    <IfModule setenvif_module>
    BrowserMatch "MSIE 10.0;" bad_DNT
    </IfModule>
    <IfModule headers_module>
    RequestHeader unset DNT env=bad_DNT
    </IfModule>

    其中红色部分要根据实际情况设置,下面再详细说明。

    二、PHP
    1、下载
    根据笔者测试,在Windows系统下,如果下载Non Thread Safe的PHP5.4,则无法与Apache2.4.3配合使用。启动服务器时,总会提示无法加载php5apache2_4.dll。因此建议下载TS版本的PHP。

    下载页面:http://windows.php.net/download/#php-5.4

    下载地址:http://windows.php.net/downloads/releases/php-5.4.6-Win32-VC9-x86.zip,14.74MB

    下载之后,解压至你存放程序的目录,建议存放在Apache的modules目录下。

    2、连接器

    对于2.4版本的Apache,PHP官方没有提供连接器,需到Apache Lounges下载。下载页面:http://www.apachelounge.com/download/,在Apache 2.4 win32 modules一栏。

    下载地址:http://www.apachelounge.com/download/win32/modules-2.4/php5apache2_4.dll-php-5.4-win32.zip,75KB。解压出文件php5apache2_4.dll,将其拷贝至PHP文件夹下。

    3、修改Apache配置

    LoadModule php5_module "C:/Apache24/cgi-bin/php/php5apache2_4.dll"
    PHPIniDir "cgi-bin/php"

    将红色部分替换为你存储php和连接器的位置,注意斜杠的写法。

    三、测试

    启动Apahce有两种方式:DOS启动和安装Windows服务。需要说明的是,DOS启动能够提示详细的错误信息,因此非常适合在调试阶段使用。

    1、DOS启动

    在DOS下找到Apache/bin目录,输入httpd即可。如果启动失败,窗口会返回错误信息。检查一下Apache的配置文件。在整个测试过程中,DOS窗口不可关闭。

    2、安装Windows服务

    为方便起见,使用如下批处理:

    @echo off
    @echo 1: Install  and start Apache
    @echo 2: Restart Apache
    @echo 3: Stop and delete Apache

    set S=".Server"
    set WEB="Apache243"
    set input=
    set /p input=Pleasse select:
    if %input%==1 call :start
    if %input%==2 call :restart
    if %input%==3 call :del

    :start
    @echo off
    %~dp0%WEB%inhttpd -d %~dp0%WEB% -f %~dp0Apacheconfhttpd.conf -k install -n %S%
    net start %S%
    pause
    exit

    :restart
    @echo off
    net stop %S%
    net start %S%
    pause
    exit

    :del
    @echo off
    net stop %S%
    sc delete %S%
    pause
    exit
    其中WEB变量是Apache文件夹相对该批处理文件的位置,应该根据情况修改。将上述代码复制到文本文件里,保存以bat扩展名保存。

    成功启动服务器后,在浏览器中访问本站,看看是否成功。

  • 相关阅读:
    敏捷之一:以终为始
    Rails non browser app高级篇-capistrano/daemon部署
    ios 5下设置屏幕方向为landscape
    Android敏捷开发实践(连载)
    Rails+Mongodb的一个重要技巧:如何得到last N Records?
    在macos x上 编译jzmq 3.x
    计划缓冲区
    转载程序员的十层楼
    特权账户是什么?
    如何管理公司的共享iPad?
  • 原文地址:https://www.cnblogs.com/kingangWang/p/3166056.html
Copyright © 2011-2022 走看看