Php+apache+mysql的环境搭建
软件下载与安装
1)php-5.2.17-Win32-VC6-x86.zip
http://windows.php.net/download/
2)httpd-2.2.22-win32-x86-openssl-0.9.8t.msi
http://httpd.apache.org/download.cgi
3)mysql-5.5.20-win32.msi
http://dev.mysql.com/downloads/
申明下我的安装路径 供以下配置信息参考
D:\develop\php5
D:\Program Files\Apache Software Foundation\Apache2.2
D:\Program Files\MySQL\MySQL Server 5.5
E:\php\web
配置apache
打开安装目录下的~\Apache2.2\conf\httpd.conf文件
#A、找到以 LoadModule 开始的部分,添加如下信息,从而在apache中载入php模块
LoadModule php5_module D:/apache/php5/php5apache2_2.dll
PHPIniDir "D:/develop/php5"(php配置信息的路径)
AddType application/x-httpd-php .php .html .htm
#B、找到以 DocumentRoot 开始的一行,更改服务器主目录
DocumentRoot "路径-如 E:/php/web"
#C、找到以 <Directory 开始的一行,更改此行路径
<Directory "同B-如 E:/php/web">
#D、找到 DirectoryIndex 开始的一行,更改为
DirectoryIndex index.php index.html
配置PHP
拷贝~/php5/php.ini-dist、php5ts.dll、libmysql.dll到windows操作系统目录,C:/Winnt/ 或 C:/Windows/,并将php.ini-dist改名为php.ini用editplus打开拷贝后的php.ini
#A、找到extension_dir 更改
extension_dir = "D:\develop\php5\ext"
#B、找到Windows Extensions 去掉模块配置每行前面的分号 实现模块支持
extension=php_curl.dll
extension=php_gd2.dll
extension=php_mbstring.dll
extension=php_mcrypt.dll
extension=php_mhash.dll
extension=php_ming.dll
extension=php_msql.dll
extension=php_mysql.dll
extension=php_openssl.dll
extension=php_pdo.dll
extension=php_pdo_mysql.dll
extension=php_sockets.dll
extension=php_xmlrpc.dll
extension=php_zip.dll
#C、(可选)找到;session.save_path 更改
session.save_path = "E:\php\session"
测试
重启Apache服务器
在刚才指定的工作目录中(D:/web)新建文件(test.php),输入以下内容
<?
phpinfo();
?>
保存,在浏览器中输入http://localhost/test.php,如果出现php信息的话,就说明成功了。
新建文件sql.php,输入以下内容
<?php
$connect=mysql_connect("127.0.0.1","root","root");
if(!$connect) echo "Mysql Connect Error!";
else echo "恭喜,配置成功!";
mysql_close();
?>
然后在浏览器中输入http://localhost/sql.php,数据正常显示,那么数据库连接成功。如果连接失败,重启一下mysql看看!