您的位置:首页 > 运维架构 > Apache

windows平台下快速配置Apache+PHP服务器环境

2008-12-24 11:52 721 查看
一直以来,Apache是PHP应用理想的Web服务器,已经成为PHP应用的首选Web服务器软件。Apache与PHP均提供了详细的配置参数,但是在一般情况下,我们只需对其中的少数参数进行设置,其它的取默认即可。windows平台下快速配置Apache+PHP服务器环境如下:

1.安装Apache

http://httpd.apache.org网站上可以下载到最新的Apache的安装包,记住选用Win32 binary(MSI Installer)版本的。我使用的是apache_2.2.10-win32-x86-openssl-0.9.8i.msi,估计也不是新的了。运行安装程序,由于我已经在机器上安装了Apache,而且进行了一些配置,所以不方便重装并截图,请谅解,只能文字说明。安装中注意的就是设置Network Domain(服务器所在域)和 Server Name(服务器名,一般填127.0.0.1).我建议大家安装的时候可以安装在C:\Apache2.2下.以便于操作和配置。

2.安装PHP

http://www.php.net网站上下载PHP,我的不是安装版本的,但是可以导入注册表,我使用的是php-5.2.6-Win32.zip。



3.配置Apache

进入Apache的安装目录,我的是C:\Apache2.2\conf,编辑该目录下的httpd.conf文件,用一般的记事本打开即可,如果打开的时候文件不规整,可以使用专门的IDE工具打开,如UltraEdit打开编辑。在该文件中以“#”开始的行为为注释行,而且注释行中都给出了具体的说明,我现给出我的配置详细参数:

# LoadModule foo_module modules/mod_foo.so
#

LoadModule php5_module "c:/php5/php5apache2_2.dll"
AddType application/x-httpd-php .php
PHPIniDir "c:/php5"


LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
LoadModule asis_module modules/mod_asis.so
LoadModule auth_basic_module modules/mod_auth_basic.so
#LoadModule auth_digest_module modules/mod_auth_digest.so
#LoadModule authn_alias_module modules/mod_authn_alias.so
#LoadModule authn_anon_module modules/mod_authn_anon.so
#LoadModule authn_dbd_module modules/mod_authn_dbd.so
#LoadModule authn_dbm_module modules/mod_authn_dbm.so

(采用动态链接库的方式配置,使得PHP和Apache能一起工作)

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "e:/bookmage"

<Directory "e:/bookmage">
#
# 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

#
# 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>

(设置Web文件的根目录,Apahe将客户端的请求指向该目录,并在该目录下搜索被请求的页面)

<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>


(设置目录文件中的默认检索文件)

4.配置PHP

将php5目录下的php.ini-recommended复制一份,更名为php.ini,然后放入php5目录下,这个文件便成为PHP的配置文件,在PHP运行时将使用它。具体配置如下:

; Allow the <? tag. Otherwise, only <?php and <script> tags are recognized.
; NOTE: Using short tags should be avoided when developing applications or
; libraries that are meant for redistribution, or deployment on PHP
; servers which are not under your control, because short tags may not
; be supported on the target server. For portable, redistributable code,
; be sure not to use short tags.
short_open_tag = On

(决定在PHP脚本中是否允许使用起始标记法“<?PHP”的简写形式<?)

; To output errors to STDERR with CGI/CLI:
;display_errors = "stderr"
;
; Default
;
display_errors = On

(我建议设置为ON,这样可以显示出错误,对网站的编译有好处)

; As of 4.0b4, PHP always outputs a character encoding by default in
; the Content-type: header. To disable sending of the charset, simply
; set it to be empty.
;
; PHP's built-in default is text/html
default_mimetype = "text/html"
default_charset = "gb2312"

(设置字体,一般为汉文编码)

; Windows: "\path1;\path2"
include_path = ".;c:\php\includes;e:\bookmage"

(设置要指向的PHP文件放置的位置)

; Directory in which the loadable extensions (modules) reside.
extension_dir = "c:/php5/ext"

(设置扩展模块的所在目录)

extension=php_mysql.dll
extension=php_mysqli.dll


(支持连接mysql数据库)

; session.save_path = "N;MODE;/path"
;
; where MODE is the octal representation of the mode. Note that this
; does not overwrite the process's umask.
session.save_path = "c:/php5/tmp"

(设置存放session的目录,建议在PHP5下建立tmp目录)

之后的工作就是重启Apache服务器,然后点击STRAT按钮可以了,一般配置成功的话,会出现It Works!的网页
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: