将 PHP mysql 库从 mysqlnd 更改为 libmysql(用于 SSL 连接)
我在 Windows 机器上使用最新的 PHP 5.3.6。我将远程 MySQL 服务器配置为仅接受 SSL 连接。使用 MySQL 命令行客户端连接工作正常:
mysql.exe -u user -h mysql.example.com -P 3307 --ssl-ca=C:\www\mysql.example.com.crt -p
但是,我不能通过 PHP 连接。根据 PHP 文档,这是由于 PHP 5.3 使用默认情况下较新的 MySQL 本机驱动程序 (mysqlnd)。该驱动程序不支持 SSL。
我不敢相信他们允许这样的回归溜走(SSL是为什么有人会使用 mysqli 而不是 mysql 扩展的少数原因之一),而不提供一种简单的方法来恢复到支持旧的 libmysql 驱动程序SSL。
在 php.net 上,没有说明如何执行此操作。此外,重新编译也不是一个选择。因此我的问题是:如何才能轻松做到这一点?
I am using the most recent PHP 5.3.6 on a Windows box. I configured a remote MySQL server to accept only SSL connections. Connecting works fine with the MySQL command line client:
mysql.exe -u user -h mysql.example.com -P 3307 --ssl-ca=C:\www\mysql.example.com.crt -p
However, I cannot connect through PHP. According to the PHP documentation, this is due to PHP 5.3 using the newer MySQL Native Driver (mysqlnd) by default. This driver does not support SSL.
I can't believe that they allowed such a regression to slip through (SSL being one of the few reasons why someone would use the mysqli rather than the mysql extension) without offering an easy way to revert back to the old libmysql driver which does support SSL.
On php.net, there is no indication about how to do this. Also, recompiling is not an option. My question thus is: how can this be done easily?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了创建 mysql、mysqli 和 PDO 扩展,必须针对 MySQL 接口库编译 PHP。您不能简单地更换该底层库。为了使用另一个库,比如 MySQL 提供的库,您必须针对它重新编译 PHP。
切换到原生库的原因是MySQL提供的库是在GPL下发布的。 PHP 许可证与 GPL 不兼容,因此分发根据 GPL 代码编译的 PHP 二进制文件在“禁止”列表中名列前茅。你可以感谢和/或诅咒 MySQL 人员的这种完全愚蠢的行为。只有白痴和邪恶的人才会在 GPL 下发布库代码。
如果你不能重新编译,那你可能就不走运了。请记住,Microsoft 免费提供 VC9 (Visual Studio 2008) ,因此您应该能够在需要时执行重新编译。
您可能想探索其他选项来安全连接到 MySQL 服务器。
如果远程计算机是 Linux 或其他基于 Unix 的计算机,那么使用 SSH 隧道(端口转发)可能适合您。 许多 Windows SSH 客户端可以做到这一点。
您还应该考虑 OpenVPN,一种 VPN 解决方案建立在 SSL/TLS 之上。您可以使用它在两台机器之间建立安全连接,而无需担心协议级安全性。
In order to create the mysql, mysqli and PDO extensions, PHP must be compiled against a MySQL interface library. You can't simply swap out that underlying library. In order to use another library, like the one provided by MySQL, you have to recompile PHP against it.
The reason for the switch to the native library is that the MySQL-provided library is released under the GPL. The PHP license is not compatible with the GPL, so distributing PHP binaries compiled against GPL code is pretty high up on the Thou Shalt Not list. You can thank and/or curse the MySQL folks for this bit of utter stupidity. Only idiots and evil people release library code under the GPL.
</rant>
If you can't recompile, you're probably out of luck. Keep in mind that Microsoft offers VC9 (Visual Studio 2008) at no cost, so you should be able to perform the recompile, if needed.
You might want to explore other options for a secure connection to your MySQL server.
If the remote machine is Linux or otherwise Unix-based, then using an SSH tunnel (port forwarding) may work for you. There are numerous SSH clients for Windows that can do this.
You should also consider OpenVPN, a VPN solution built on top of SSL/TLS. You can use this to establish a secure connection between the two machines without needing to worry about protocol-level security.