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停止,否則服務可能安裝不上