PHP 无法连接到我的 chrooted MySQL 套接字?
所以我在 CentOS 上设置了 MySQL chroot。 MySQL 实际上被限制在 /opt/chroot/mysql/ 中,并且我修改了 /etc/init.d/mysqld 文件,以便一切正常运行。我可以(作为 root)通过发出以下命令连接到套接字:
mysql -S /opt/chroot/mysql/var/lib/mysql/mysql.sock
目前,为了简单起见,MySQL root 用户没有密码。
但是,由于某种原因,PHP(在 Apache 中运行)无法连接到同一套接字。我尝试更新 php.ini 中的 MySQL 默认套接字变量,并在建立连接时引用完整的套接字路径,但我总是遇到相同的错误:
无法通过套接字'/opt/chroot/mysql/var/lib/mysql/mysql.sock'连接到本地MySQL服务器(13)
有什么想法吗?
更新:我自己找到了解决方案。 SELinux 已启用并阻止 Apache 的所有连接。
So I've set up a MySQL chroot on CentOS. MySQL is effectively confined to /opt/chroot/mysql/, and I've modified the /etc/init.d/mysqld file so that everything runs fine. I can (as root) connect to the socket by issuing the command:
mysql -S /opt/chroot/mysql/var/lib/mysql/mysql.sock
At the moment, to keeps things simple, there is no password for the MySQL root user.
However, for some reason PHP (running in Apache) cannot connect to the same socket. I've tried updating the MySQL default socket variable in php.ini, as well as referencing the full socket path whilst making the connection, but I always get the same error:
Can't connect to local MySQL server through socket '/opt/chroot/mysql/var/lib/mysql/mysql.sock' (13)
Any ideas?
Update: Found the solution myself. SELinux was enabled and was blocking all connections by Apache.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Apache是否有权遍历/读取该路径中的所有目录?仅仅因为您以 root 身份从命令行执行某些操作,并不意味着您就可以直接使用 Apache。这是一个不同的用户 ID 和一个完全不同的环境。
Does Apache have the rights to traverse/read all the directories in that path? Just because you do something as root from the command line, doesn't mean diddly squat to Apache. That's a different user ID and a different environment entirely.