Apache、PHP和mySQL的配置过程


这两天要用到PHP,当然也难免地要用到Apache,两个以前都没用过的东东,下载地址好找,找到其根据地就行了。

Apache的网址:http://httpd.apache.org/download.cgi,最新版本是apache2.2.4,windows系统的话,要下Win32 Binary (MSI Installer)的那个(就是apache_2.2.4-win32-x86-no_ssl.msi)。

PHP的下载地址:http://cn.php.net/get/php-5.2.1-Win32.zip/from/a/mirror,当前的最新版本是PHP5.2.1。当然也可以用它的安装版的,安装版就是有安装过程,不需要另外设置配置文件了, 它的下载地址:http://cn.php.net/get/php-5.2.1-win32-installer.msi/from/a/mirror。

安装之后,就是配置了。在网上搜了N个配置方法,但大多是无聊的相互抄袭。耐着性子看了几个配置后有这样的感觉:不同的人不同的版本,有不同的配置。于是自己着手配置,N次之后得出了这样的结论——配置是简单的,不像网上老兄们说的那么麻烦,总结如下:

在Apache2\conf 目录下的 httpd.conf文件是Apache的主配置文件,是个文本文件。

[注:] Apache2.2和以前版本有差别,部分的配置文件放置到conf/extra目录中,如语言文件httpd-languages.conf,用户目录文件httpd-userdir.conf。

1、找到DocumentRoot,在其后的“”里写入自己的工作文件的根目录。如下:

# 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 "F:/vhost/wordpress"

2、找到DirectoryIndex index.html 在后面加入 index.htm index.php index.html.var

#

# DirectoryIndex: sets the file that Apache will serve if a directory

# is requested.

#

<IfModule dir_module>

    DirectoryIndex index.html index.htm index.php index.html.var

</IfModule>

    以上的简单设置,Apache就可以使用了。比如启动Apache后,在浏览器的地址栏里输入:“http://localhost/index.html”,就可以看到你所设置的工作目录里的东东了。但由于Apache要用做PHP的服务器,所以还要有如3的设置

3、模块化安装配置:

3.1在httpd.conf中找到

#LoadModule ssl_module modules/mod_ssl.so

 一行,在其后加入如下行

LoadModule php5_module %php5_home%/php5apache2_2.dll

(其中,%php5_home%为PHP的安装目录)

3.2在httpd.conf中找到

AddType application/x-gzip .gz .tgz

一行,在其后加入如下行:

ScriptAlias /php/ “ D:/PHPServer/php5/”
AddType application/x-httpd-php .php
Action application/x-httpd-php “/php/php-cgi.exe”

如果安装后出现You don’t have permission to access / on this server,可查找httpd.conf中的Deny from all,改为:Allow from all

*其实支持PHP5.2.1的关键代码就三行,可以直接添加在httpd.conf文件末尾:

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

3.3 上述的3.1和3.2都是在httpd.conf中进行的。而在PHP5.2.1中,要对php.ini实例化。(php.ini这个文件可从php.ini-dist 或者 php.ini-recommended改名得到)

打开该文件,修改extension_dir = "./"一行。把“”中的改成本机PHP5的ext目录,比如我的ext路径为“f:/vhost/php5/ext”。

然后找到“;extension=php_gd2.dll”一行,去掉其前的分号;

4、要使PHP支持mySQL,则还要继续下面的步骤:

4.1在apache中的文件httpd.conf的末尾加入下面的一行:

LoadFile D:/server/php5/libmysql.dll

4.2在PHP5.2.1中的文件php.ini中,找到“;extension=php_mysql.dll”一行,并去掉其前的分号。当然如果不用mySQL。则可以不删除php_mysql.dll 前的分号。


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3