1.下載如下程序,都是免費(fèi)的,在官方網(wǎng)站都有下
apache_2.0.50-win32-x86-no_ssl.msi
mysql-4.0.20d-win
php-4.3.8-installer.exe
注:php有zip壓縮的和install的兩種版本,強(qiáng)烈建議使用install的版本,否則有時(shí)配置完全正確的情況下,apache還是找不到php。
2.安裝
1)先安裝mysql,然后安裝apache,最后安裝php,因?yàn)閜hp安裝時(shí)有個(gè)選擇服務(wù)器的設(shè)置。
mysql安裝之后,執(zhí)行安裝目錄下bin目錄中的winmysqladmin.exe,會(huì)提示輸入超級(jí)用戶(hù)名和密碼,填寫(xiě)即可,然后在右下角托盤(pán)右鍵菜單中選擇Install srevice,然后start service即可。
2)apache的安裝配置過(guò)程中要填寫(xiě)域名之類(lèi)的地方都可以隨便添,因?yàn)橐院笤趆ttpd.conf中都可以改,我都填的是localhost。安裝快結(jié)束的時(shí)候,它會(huì)自動(dòng)配置腳本,但是如果你的機(jī)子上裝了IIS,都用的80端口,會(huì)提示失敗,不過(guò)沒(méi)關(guān)系,后面配置的時(shí)候改端口就行了。
3)php安裝的時(shí)候選擇apache作服務(wù)器,另外安裝的路徑寫(xiě)簡(jiǎn)單些,如D:\php,要是放在program files這樣的目錄中,有可能在使用的時(shí)候會(huì)崩潰。
3.配置
1)mysql沒(méi)有什么好說(shuō)得,啟動(dòng)服務(wù)就能用了。
2)打開(kāi)apache安裝路徑下的CONF目錄,找httpd.conf文件,用文本編輯器打開(kāi),修改如下:
把
#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 (如果要支持更多的擴(kuò)展名,可以添加多行,如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
注:中文版的已經(jīng)有AddCharset ISO-2022-CN .iso2022-cn .cis這行了,所以不用加。
apache安裝完后默認(rèn)的虛擬路徑是安裝目錄下的htdocs目錄,如果要將其它目錄設(shè)為虛擬路徑,參考最后的附錄。
3)將php安裝目錄中的php4ts.dll拷貝到system32目錄下,如XP中拷貝到c:\windows\system32;
然后將BACKUP目錄下的PHP.INI拷貝到windows目錄中,用文本編輯器打開(kāi)它,
查找 [MySQL] 字段內(nèi)的內(nèi)容.修改如下.
mysql.default_port = 3306
// 這里是MYSQL的端口.
mysql.default_host = localhost
// 這里是本地主機(jī).
mysql.default_user = root
// 這里是超級(jí)用戶(hù)
mysql.default_password = 123456
// 這里是超級(jí)用戶(hù)密碼
修改到這里就可以讓 Php 與 MYSQL 關(guān)聯(lián)了.
最后啟動(dòng) PHP 對(duì) MYSQL 模塊支持.
查找 ;extension=php_mysql.dll 字串.刪除掉前面的 ; 號(hào),變成
extension=php_mysql.dll
然后找到doc_root字段,填入apache的虛擬路徑
doc_root =D:\Program Files\Apache Group\Apache2\htdocs
4.運(yùn)行
重啟apache,在htdocs目錄中放一個(gè)PHP文件,如a.php
然后在IE中輸入http://localhost:8080/a.php就可以看見(jiàn)內(nèi)容了。
5.附錄:如何改變默認(rèn)的虛擬路徑。
首先我們要在 c:\web\ 下新增目錄,例如www
然后在httpd.conf 中作如下改動(dòng)即可:
---------改動(dòng)前-------------
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>
----------改動(dòng)后-------------
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.附錄:如何設(shè)置默認(rèn)啟動(dòng)頁(yè)
同樣在HTTPD.CONF中
找到下面字段并加上你要的文件名,注意:每個(gè)文件名之間要加一個(gè)空格
< IfModule mod_dir.c>
DirectoryIndex index.html index.htm index.php index.php3
< /IfModule>
PS:在安裝Apache時(shí)最好將IIS停止,否則服務(wù)可能安裝不上