现在的位置: 首页 > 综合 > 正文

PHP 5.3.3 升级手记(APACHE 2.2 + MYSQL)

2013年03月12日 ⁄ 综合 ⁄ 共 4598字 ⁄ 字号 评论关闭

看了我上一篇日志就知道,最近在搞cURL这东西。。。。

最开始没想弄命令行的,因为相关教程和文章都比较少。于是很多人都在用php上的curl库,于是我也尝试装了下。

 

最开始我的PHP是5.2.几,当时是用msi安装包安装的(win7系统)当然apache也是安装包安装的- -(么办法,本人小菜。。)

当时在装添加mysql.dll时就蛋疼了一把。据说msi它会选择性安装东西,很多东西就不装了。。。于是后来我又把tar包解压覆盖了下= =

 

但是后来装cURL时又悲剧了,尝试网上n多教程都会让apache显示“The requested operation has faild..”

看来网上有人说建议用解压包的,于是就下载了php5.3,也当作升级了。。。

 

解压到另外一个地方,然后就开始各种蛋疼地设置,还有修改环境变量

总结下来大概有几个地方:

1.修改php.ini:

extension_dir = "F:/php/ext"

 

extension=php_gd2.dll
extension=php_curl.dll

extension=php_mbstring.dll

extension=php_mysql.dll
extension=php_mysqli.dll

extension=php_xmlrpc.dll

 

上面除了curl和mysql以外,都是按网上推荐的设置的。。。

 

2.环境变量

windows的path:加一条F:/php

PHPRC=F:/php

 

3.复制

libeay32.dll

php5ts.dll

ssleay32.dll

到system32文件夹

 

4.复制

php5ts.dll

到apache2.2/bin下

 

 

5.修改apache的设置文件,添加如下

PHPIniDir "F:/PHP/"
LoadModule php5_module "F:/PHP/php5apache2_2.dll"
AddType application/x-httpd-php .php

 

似乎就可以了。

注意一下,关于php下载的版本

应该下载

VC6 x86 Thread Safe

版本,VC6版本给apache,非线程安全的版本会缺少一些dll文件- -(不知道为什么…)

 

嗯,有机会我估计要重装apache成解压版本了。。。

 

 

当一切都配置好了以后,悲剧就出现了。

MYSQL连接不上了。。。

上网查了下原因,是在连接mysql服务器的时候,使用了“localhost”

而在5.3里应该用"127.0.0.1".....

比如:

 

具体的原因是因为php 5.3使用了mysqlnd这种东西。

它的好处是加速了数据读取,以及增加对IPV6的支持

悲剧就悲剧在这里。因为它支持了ipv6,当你设置了localhost以后,它会首先在IPV6中寻找ip并且连接。。

所以有2种解决办法:

1.修改localhost 成127.0.0.1,让php明确连接ipv4的服务器

2.在host文件中添加如下语句:

这似乎也是VISTA 和win7的一个小问题吧。。。。

 


附一个老外写的原文:

PHP 5.3 and MySQL connectivity problem

I have seen so many post in our IIS forum
mentioning that after moving to PHP5.3 they are not able to connect to
MySQL database. So this means a simple program like the one below
doesn’t work:

 

And trust me most of the users cannot even dig this
further and just mention that they are getting a 500 or some sort of
script timeout.

There are two workaround to overcome this situation:

  • Most elegant one is to replace the database
    server name ‘localhost’ with IP address of the machine or ‘127.0.0.1’
    which is reserved for localhost.
  • Disable IPV6. This can be done by opening the
    file ‘%systemroot%/System32/drivers/etc/hosts’ and commenting out the
    line ‘::1             localhost’. I would not advise this as there might
    be some other components which is dependent on IPV6 and may break or
    stop working.

Now some people also deduce from the above workaround
that it is a Windows OS bug or a PHP bug. Neither is correct. I have
explained this on PHP Windows internal alias couple of times as well as
on our forums. Let me explain it again.

Most of the Operating System today is building
support for IPV6. IPV4 has its own set of limitation and hence the world
is moving to IPV6. I am not going to explain differences between two,
but for the sake of this discussion assume that they are different. A
close look at PHP MySQL driver code indicates that mysql_connect()
function uses mysql_real_connect() to connect to MySQL. The API
mysql_real_connect() is an API which comes from MySQL dll (MySQL
development team and is part of MySQL database installation). So this
means the support for IPV6 in PHP MySQL driver is not possible unless
there is a support for IPV6 in MySQL database. So the limitation (or no
support for IPV6 or whatever word may be used to describe this
situation) is coming from MySQL database limitation. So now it is clear
that this is not a PHP bug in the sense that nothing can be changed in
PHP code base to fix it.

Let's move on to operating system concern now. A
typical host file (irrespective of OS) has two columns which contains
the IP address and host name binding to it. In order to support both
IPV4 and IPV6 (at least on Windows) localhost is getting mapped to two
IP addresses. There can be other reasons for mapping same localhost to
multiple IP address. What is important is that, there is a case where we
have multiple IP address pointing to same host name. A close inspection
of MySQL code reveals that the function mysql_real_connect() actually
tries to connect to only the first IP address returned for the hostname
and if this fails, no further attempt to connect using other IP address
associated with same host name is made. This can be fixed and I believe a
patch is already lying in some development branch of MySQL and please
follow MySQL release to know which version has this fix integrated. I do
not have any idea about that. But an important thing is that this bug
can surface on any OS where you have above condition satisfied for the
host file. Yes WINDOWS, Ubuntu, Solaris all will and may get impacted.
So this means that this is not a problem with Windows OS or for that
reason any other OS.

Hope this explain things. Thanks for the patient reading and till we meet again ‘Good Bye’.

Thanks,

Don.

PS: In this post you learnt one reason for using IP
address as your database host name. There is another compelling reason.
Read the blog by Kanwal here
to know more about it.

 

抱歉!评论已关闭.