聲明:本編文章主要是本人通過查閱網絡資料與自己親自實踐總結,文章主要參考(http://jingyan.baidu.com/article/154b46315242b328ca8f4101.html)希望對大家配置php環境有所幫助。
1.軟件環境
操作系統:winX86(64位系統同理,下載64位軟件即可)
Web服務器:Apache2.4.16
語言環境:php5.6.13
數據庫環境:MySQL5.6.26
Apache預安裝軟件:VC11
2.軟件環境下載
1)VC11
網址:http://www.microsoft.com/en-us/download/details.aspx?id=30679下載vcredist_x86.exe,下載時選擇英文版,如果系統爲win7(64位),則下載x64即可。(這裏解釋一下,32位win7系統下載軟件時選擇x86或x32,64位win7系統下載時選擇x64,這對所有win7系統軟件下載適用)
2)Apache2.4.16
網址:http://www.apachelounge.com/download/VC11/下載httpd-2.4.16-win32-VC11.zip
3)PHP5.6.13
網址:http://windows.php.net/download/下載VC11 x86 Thread Safe
4)MySQL5.6.26
網址:http://dev.mysql.com/downloads/mysql/下載mysql-5.6.26-win32.zip
3.軟件安裝
1)VC11
下一步下一步下一步。。。
2)Apache2.4.16
將文件解壓後,放入D盤,路徑爲D:\phptools\apache2.4
3)PHP5.6.13
文件解壓後,放入D盤,路徑爲D:\phptools\php5.5
4)MySQL5.6.26
文件解壓後,放入D盤,路徑爲D:\phptools\MySQL
4.配置PHP
1) 複製F:\phptools\php5.5\php.ini-production文件一分,複製後重命名爲php.ini;
2)計算機右鍵屬性-->高級系統設置-->環境變量-->系統變量,找到Path,編輯,在其後加上;D:\phptools\php5.5;D:\phptools\php5.5\ext;
5.配置Apache
用記事本打開D:\phptools\Apache2.4\Apache24\conf\httpd.conf
查找ServerRoot,修改ServerRoot
"C:/Apache24" => ServerRoot "D:/phptools/Apache2.4/Apache24"
查找#ServerName
www.example.com:80 ,修改爲 ServerName www.example.com:80
查找DocumentRoot
"c:/Apache24/htdocs" , 修改爲DocumentRoot "D:/phptools/Apache2.4/Apache24/htdocs"
查找<Directory
"c:/Apache24/htdocs"> ,修改爲 <Directory " D:/phptools/Apache2.4/Apache24/htdocs ">
查找DirectoryIndex
index.html ,修改爲 DirectoryIndex index.html index.php index.htm
查找ScriptAlias
/cgi-bin/ "c:/Apache24/cgi-bin/" ,修改爲 ScriptAlias /cgi- bin/ " D:/phptools/Apache2.4/Apache24/cgi-bin"
查找<Directory
"c:/Apache24/cgi-bin"> 修改爲 <Directory "D:/phptools/Apache2.4/Apache24/cgi-bin/">
在D:\phptools\apache2.4.10\conf\httpd.conf最後一行添加添加
LoadModule php5_module "D:/phptools/php5.5/php5apache2_4.dll"
讓apache支持php(請確認D:/phptools/php5.5/有php5apache2_4.dll,本文提供的下載鏈接無需確認)
添加
AddType application/x-httpd-php .php .html .htm
添加
PHPIniDir "D:/phptools/php5.5"
(告訴apache php.ini的位置)
至此,httpd.conf
配置完成,保存httpd.conf。
6.配置MySQL
1)配置環境變量
在Path中添加D:\phptools\MySQL\bin;(注意要有分號)
2)修改配置文件
記事本打開D:\phptools\MySQL\my-default.ini,修改basedir,datadir爲:
basedir
= D:\phptools\MySQL
datadir = D:\phptools\MySQL\data
3)安裝服務
管理員運行cmd輸入cd D:\phptools\MySQL\bin,然後輸入mysqld -install,安裝成功後
輸入net start mysql,啓動mysql,輸入mysql -u root -p,登陸成功。
7.安裝Apache到系統服務
鍵盤“windows+R”,輸入cmd進入命令行,輸入d:,回車後,輸入D:\phptools\Apache2.4\Apache24\bin\httpd -k install ,回車。
8.開啓PHP常用擴展
用記事本打開D:\phptools\php5.5\php.ini
將;
extension_dir = "ext"前面;去掉
將;extension=php_mbstring.dll前面;去掉
將;extension=php_mysql.dll修改爲前面;去掉
將;extension=php_mysqli.dll
修改爲前面;去掉
9.啓動Apache
雙擊D:\phptools\Apache2.4\Apache24\bin\ApacheMonitor.exe啓動。
10.測試php環境
瀏覽器鍵入127.0.0.1,若顯示it works則配置成功,若出現提示 Forbidden You don't have permission to access / on this server.則進行如下操作。
記事本打開D:\phptools\apache2.4\Apache24\conf\httpd.conf
1)找到並修改
#
Deny access to the entirety of your server's filesystem. You must
#
explicitly permit access to web content directories in other
#
<Directory> blocks below.
#
<Directory
/>
AllowOverride none
# Require all denied
Allow from all
Satisfy all
</Directory>
2)找到並修改
#
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
"D:\phptools\apache2.4\Apache24\htdocs"
<Directory
"D:/phptools/Apache2.4/Apache24/htdocs">
#
# 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.4/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:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride all
#
# Controls who can get stuff from this server.
#
# Require all granted
Order Deny,Allow
Allow from all
</Directory>
修改後保存,在瀏覽起輸入127.0.0.1,測試是否成功,希望本篇文章對您有所幫助。