声明:本编文章主要是本人通过查阅网络资料与自己亲自实践总结,文章主要参考(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,测试是否成功,希望本篇文章对您有所帮助。