学生用PHP开发的网页Game示例,我在虚拟机上安装了APACHE2及MYSQL,外加PHP5,通过主机host os(XP)上调用:
http://192.168.*.*/game/installer.php安装数据库,出现一些问题:
1. 首先是用IP无法连接数据库
mysql默认PORT为3306.
提示错误:"Lost connection to MySQL server at 'reading initial communication packet…”
在网上找到解决方法:#vim /etc/mysql/my.cnf
Find the bind-address 127.0.0.1 and comment it out.
注意要重新启动mysql.
实际上这是因为安全原因,系统只允许从本机访问mysql.
最后还看到一种解决方法,也是修改/etc/mysql/my.cnf文件,在[mysqld] 段增加一个启动参数
skip-name-resolve
没试过,原理应该一样。
2. 上述问题解决后,仍然显示错误:
- Notice!: System Error
- ErrInfo: Host '192.168.203.131' is not allowed to connect to this MySQL server
- ErrCode: 1130
- ErrURIs: /game/installer.php
在网上找到一个解决方法:http://freespace.javaeye.com/blog/80876
另外一种方法,可以用机器名代替IP,就不会出现上述问题了。
3. 提示./include/config.inc.php出错,显示需要手工配置:
Warning: fopen(./include/config.inc.php) [function.fopen]: failed to open stream: Permission denied in /var/www/game/installer.php on line 37
数据库连接配置文件写入错误 你必须手动更改这个文件:./include/config.inc.php!
查看源代码,发现这个地方是将系统配置参数,如主机名,用户及PASSWORD写入到一个配置文件。应该是权限设置的问题。而实际上数据库已经配置成功了。可以通过mysql客户端或phpmyadmin查看数据。
解决方法,可以修改文件./include/config.inc.php文件权限:
#chmod 777 config.inc.php