win7下手动搭建wamp环境,碰到的几个坑总结下,
1.能正常访问php和html类型文件,但是访问项目文件时老是连接被重置,后来总结是数据库的问题,就写测试用例测试php能否成功调用数据库,
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <?php 2 echo "mysql"; 3 4 $mysql_conf = array( 5 'host' => '127.0.0.1', 6 'db' => 'drupal628', 7 'db_user' => 'root', 8 'db_pwd' => 'admin', 9 ); 10 $mysql_conn = @mysql_connect($mysql_conf['host'], $mysql_conf['db_user'], $mysql_conf['db_pwd']); 11 if (!$mysql_conn) { 12 echo "失败"; 13 die("could not connect to the database: " . mysql_error());//诊断连接错误 14 }else{ 15 echo "连接成功"; 16 } 17 18 ?>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <?php 2 echo "mysqli"; 3 4 $mysql_conf = array( 5 'host' => '127.0.0.1', 6 'db' => 'drupal628', 7 'db_user' => 'root', 8 'db_pwd' => 'admin', 9 ); 10 11 $mysqli = @new mysqli($mysql_conf['host'], $mysql_conf['db_user'], $mysql_conf['db_pwd']); 12 if ($mysqli->connect_errno) { 13 echo "失败"; 14 die("could not connect to the database: " . $mysqli->connect_error);//诊断连接错误 15 }else{ 16 echo "成功"; 17 } 18 19 ?>
实际是mysqli能连接成功,mysql连接不成功,phpinfo.php也显示模块都已正常加载,百思不得其解,直到找到这位大神的解答。
解决方法1:
- 在apache的配置文件 httpd.conf 中添加: LoadFile D:/PHP/php5.2.13/libmysql.dll(一试便好,我不存在2的错误)
- 修改windowssystem32driversetchosts文件,把localhost指向127.0.0.1(因Windows7可解析IPv6,默认localhost指向是::1而非127.0.0.1)
2.不能自动定位首页
在httpd.conf中<Directory "F:/php_projects"></Directory>中 添加 DirectoryIndex index.html index.php default.html default.php指定默认首页
3.开始安装phpmyadmin时老是提示错误,我们都知道phpmyadmin只需要下载安装包后解压放到根目录下即可,不明白为什么一直提示错误,换了几个版本错误依旧,上面的问题解决后这个问题也不存在了
4.Call to undefined function imagecreatefrompng()发现是因为安装时php忘了开启gd2扩展