PHP can't connect to my chrooted MySQL socket?
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.
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.
精彩评论