1.下载如下程序,都是免费的,在官方网站都有下
apache_2.0.50-win32-x86-no_ssl.msi
mysql-4.0.20d-win
php-4.3.8-installer.exe
注:php有zip压缩的和install的两种版本,强烈建议使用install的版本,否则有时配置完全正确的情况下,apache还是找不到php。
2.安装
1)先安装mysql,然后安装apache,最后安装php,因为php安装时有个选择服务器的设置。
mysql安装之后,执行安装目录下bin目录中的winmysqladmin.exe,会提示输入超级用户名和密码,填写即可,然后在右下角托盘右键菜单中选择Install srevice,然后start service即可。
2)apache的安装配置过程中要填写域名之类的地方都可以随便添,因为以后在httpd.conf中都可以改,我都填的是localhost。安装快结束的时候,它会自动配置脚本,但是如果你的机子上装了IIS,都用的80端口,会提示失败,不过没关系,后面配置的时候改端口就行了。
3)php安装的时候选择apache作服务器,另外安装的路径写简单些,如D:\php,要是放在program files这样的目录中,有可能在使用的时候会崩溃。
3.配置
1)mysql没有什么好说得,启动服务就能用了。
2)打开apache安装路径下的CONF目录,找httpd.conf文件,用文本编辑器打开,修改如下:
把
#Listen 12.34.56.78:80
Listen 80
改成
#Listen 12.34.56.78:8080
Listen 8080
把
#ScriptAlias /cgi-bin/ "D:/Program Files/Apache Group/Apache2/cgi-bin/" 注释掉
改成
ScriptAlias /php/ "D:/php/"
AddType application/x-httpd-php .php (如果要支持更多的扩展名,可以添加多行,如AddType application/x-httpd-php .php3)
Action application/x-httpd-php "/php/php.exe
注意:反斜杠
把
ServerName localhost:80
改成
ServerName localhost:8080
如果你是用的英文版,想要支持中文
在配置文件中找包含“AddLanguage”或“AddCharset”的行,在这些行最前面增加一行(最好“AddCharset”行前):
AddDefaultCharset GB2312
注:中文版的已经有AddCharset ISO-2022-CN .iso2022-cn .cis这行了,所以不用加。
apache安装完后默认的虚拟路径是安装目录下的htdocs目录,如果要将其它目录设为虚拟路径,参考最后的附录。
3)将php安装目录中的php4ts.dll拷贝到system32目录下,如XP中拷贝到c:\windows\system32;
然后将BACKUP目录下的PHP.INI拷贝到windows目录中,用文本编辑器打开它,
查找 [MySQL] 字段内的内容.修改如下.
mysql.default_port = 3306
// 这里是MYSQL的端口.
mysql.default_host = localhost
// 这里是本地主机.
mysql.default_user = root
// 这里是超级用户
mysql.default_password = 123456
// 这里是超级用户密码
修改到这里就可以让 Php 与 MYSQL 关联了.
最后启动 PHP 对 MYSQL 模块支持.
查找 ;extension=php_mysql.dll 字串.删除掉前面的 ; 号,变成
extension=php_mysql.dll
然后找到doc_root字段,填入apache的虚拟路径
doc_root =D:\Program Files\Apache Group\Apache2\htdocs
4.运行
重启apache,在htdocs目录中放一个PHP文件,如a.php
然后在IE中输入http://localhost:8080/a.php就可以看见内容了。
5.附录:如何改变默认的虚拟路径。
首先我們要在 c:\web\ 下新增目录,例如www
然后在httpd.conf 中作如下改动即可:
---------改动前-------------
DocumentRoot "C:/web/Apache/htdocs" 原始路徑
#
# Each directory to which Apache has access, can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive set of
# permissions.
#
< Directory />
Options FollowSymLinks
AllowOverride None
< /Directory >
#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#
#
# This should be changed to whatever you set DocumentRoot to.
#
< Directory "C:/web/Apache/htdocs">
#
# This may also be "None", "All", or any combination of "Indexes",
# "Includes", "FollowSymLinks", "ExecCGI", or "MultiViews".
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
Options Indexes FollowSymLinks MultiViews
#
# This controls which options the .htaccess files in directories can
# override. Can also be "All", or any combination of "Options", "FileInfo",
# "AuthConfig", and "Limit"
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
< / Directory>
----------改动后-------------
DocumentRoot "C:/web/www"
#
# Each directory to which Apache has access, can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive set of
# permissions.
#
< Directory />
Options All
AllowOverride None
< /Directory>
#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#
#
# This should be changed to whatever you set DocumentRoot to.
#
< Directory "C:/web/www">
#
# This may also be "None", "All", or any combination of "Indexes",
# "Includes", "FollowSymLinks", "ExecCGI", or "MultiViews".
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
Options All
#
# This controls which options the .htaccess files in directories can
# override. Can also be "All", or any combination of "Options", "FileInfo",
# "AuthConfig", and "Limit"
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
< / Directory>
#
# UserDir: The name of the directory which is appended onto a user's home
# directory if a ~user request is received.
#
# Under Win32, we do not currently try to determine the home directory of
# a Windows login, so a format such as that below needs to be used. See
# the UserDir documentation for details.
#
< IfModule mod_userdir.c>
UserDir "C:/web/www/"
< /IfModule>
6.附录:如何设置默认启动页
同样在HTTPD.CONF中
找到下面字段并加上你要的文件名,注意:每个文件名之间要加一个空格
< IfModule mod_dir.c>
DirectoryIndex index.html index.htm index.php index.php3
< /IfModule>
PS:在安装Apache时最好将IIS停止,否则服务可能安装不上