Re: Mysql connection from within php
On 1 June 2010 16:30, What you get is Not what you see wygin...@gmail.com wrote: Freshly installed on openbsd 4.6 mysql,php and php5-mysql packages. Done the configs. Now php and mysql works. But I couldnt make it connect to mysql from within php with such a command mysql_connect(localhost,user,pass) It used to give Cant connect to mysql through socket error till I change the command to mysql_connect(127.0.0.1,user,pass) I want to learn why? As you've been already told, this is because default apache is chrooted and thus cannot access mysql socket. To correct it, just do # mkdir -p /var/www/var/run/mysql # ln -f /var/run/mysql/mysql.sock /var/www/var/run/mysql/mysql.sock -- The best the little guy can do is what the little guy does right
Re: Mysql connection from within php
On 2 June 2010, Eugene Yunak e.yu...@gmail.com wrote: On 1 June 2010 16:30, What you get is Not what you see wygin...@gmail.com wrote: Freshly installed on openbsd 4.6 mysql,php and php5-mysql packages. Done the configs. Now php and mysql works. But I couldnt make it connect to mysql from within php with such a command mysql_connect(localhost,user,pass) It used to give Cant connect to mysql through socket error till I change the command to mysql_connect(127.0.0.1,user,pass) I want to learn why? As you've been already told, this is because default apache is chrooted and thus cannot access mysql socket. To correct it, just do # mkdir -p /var/www/var/run/mysql # ln -f /var/run/mysql/mysql.sock /var/www/var/run/mysql/mysql.sock Please, stop perpetrating this nonsense. This only works until you restart mysqld. The reason is mysqld removes the socket when it starts before creating it anew. If you really must use a socket instead of TCP then move the socket to jail and give programs different views to it from inside and outside the jail, using my.cnf. Not tested: - in /etc/my.cnf: socket = /var/www/var/run/mysql/mysql.sock - in /var/www/etc/my.cnf: socket = /var/run/mysql/mysql.sock Regards, Liviu Daia -- Dr. Liviu Daia http://www.imar.ro/~daia
Re: Mysql connection from within php
On 2 June 2010 20:48, Liviu Daia liviu.d...@imar.ro wrote: On 2 June 2010, Eugene Yunak e.yu...@gmail.com wrote: On 1 June 2010 16:30, What you get is Not what you see wygin...@gmail.com wrote: Freshly installed on openbsd 4.6 mysql,php and php5-mysql packages. Done the configs. Now php and mysql works. But I couldnt make it connect to mysql from within php with such a command mysql_connect(localhost,user,pass) It used to give Cant connect to mysql through socket error till I change the command to mysql_connect(127.0.0.1,user,pass) I want to learn why? As you've been already told, this is because default apache is chrooted and thus cannot access mysql socket. To correct it, just do # mkdir -p /var/www/var/run/mysql # ln -f /var/run/mysql/mysql.sock /var/www/var/run/mysql/mysql.sock B B Please, stop perpetrating this nonsense. B This only works until you restart mysqld. B The reason is mysqld removes the socket when it starts before creating it anew. B B If you really must use a socket instead of TCP then move the socket to jail and give programs different views to it from inside and outside the jail, using my.cnf. B Not tested: - in /etc/my.cnf: socket = /var/www/var/run/mysql/mysql.sock - in /var/www/etc/my.cnf: socket = /var/run/mysql/mysql.sock I fail to see how this is nonsense or what stops one from creating this hardlink in rc.local (which would be normally used to start mysql anyway). Your solution however works as well, of course. -- The best the little guy can do is what the little guy does right
Re: Mysql connection from within php
On 2 June 2010, Eugene Yunak e.yu...@gmail.com wrote: On 2 June 2010 20:48, Liviu Daia liviu.d...@imar.ro wrote: On 2 June 2010, Eugene Yunak e.yu...@gmail.com wrote: On 1 June 2010 16:30, What you get is Not what you see wygin...@gmail.com wrote: Freshly installed on openbsd 4.6 mysql,php and php5-mysql packages. Done the configs. Now php and mysql works. But I couldnt make it connect to mysql from within php with such a command mysql_connect(localhost,user,pass) It used to give Cant connect to mysql through socket error till I change the command to mysql_connect(127.0.0.1,user,pass) I want to learn why? As you've been already told, this is because default apache is chrooted and thus cannot access mysql socket. To correct it, just do # mkdir -p /var/www/var/run/mysql # ln -f /var/run/mysql/mysql.sock /var/www/var/run/mysql/mysql.sock B B Please, stop perpetrating this nonsense. B This only works until you restart mysqld. B The reason is mysqld removes the socket when it starts before creating it anew. B B If you really must use a socket instead of TCP then move the socket to jail and give programs different views to it from inside and outside the jail, using my.cnf. B Not tested: - in /etc/my.cnf: socket = /var/www/var/run/mysql/mysql.sock - in /var/www/etc/my.cnf: socket = /var/run/mysql/mysql.sock I fail to see how this is nonsense or what stops one from creating this hardlink in rc.local (which would be normally used to start mysql anyway). Like I said, it stops working when you restart mysqld. This doesn't necessarily happen at boot. If, for whatever reason, you restart mysqld manually, will you remember to re-create the link? Your solution however works as well, of course. Regards, Liviu Daia -- Dr. Liviu Daia http://www.imar.ro/~daia
Mysql connection from within php
Freshly installed on openbsd 4.6 mysql,php and php5-mysql packages. Done the configs. Now php and mysql works. But I couldnt make it connect to mysql from within php with such a command mysql_connect(localhost,user,pass) It used to give Cant connect to mysql through socket error till I change the command to mysql_connect(127.0.0.1,user,pass) I want to learn why?
Re: Mysql connection from within php
On Tue, 1 Jun 2010, What you get is Not what you see wrote: Freshly installed on openbsd 4.6 mysql,php and php5-mysql packages. Done the configs. Now php and mysql works. But I couldnt make it connect to mysql from within php with such a command mysql_connect(localhost,user,pass) It used to give Cant connect to mysql through socket error till I change the command to mysql_connect(127.0.0.1,user,pass) I want to learn why? Because the socket is in /var, .. and default apache chroot's to /var/www. I believe there are tricks to make it work, but it's simpler to just connect @127.0.0.1. Lee
Re: Mysql connection from within php
On Tue, Jun 1, 2010 at 9:30 AM, What you get is Not what you see wygin...@gmail.com wrote: Freshly installed on openbsd 4.6 mysql,php and php5-mysql packages. Done the configs. Now php and mysql works. But I couldnt make it connect to mysql from within php with such a command mysql_connect(localhost,user,pass) It used to give Cant connect to mysql through socket error till I change the command to mysql_connect(127.0.0.1,user,pass) I want to learn why? From: http://dev.mysql.com/doc/refman/5.0/en/connecting.html On Unix, MySQL programs treat the host name localhost specially, in a way that is likely different from what you expect compared to other network-based programs. For connections to localhost, MySQL programs attempt to connect to the local server by using a Unix socket file. On OpenBSD, the MySQL socket file is outside the httpd chroot, so your PHP script can't access it. Accessing 127.0.0.1 over TCP is no problem. Paul. -- -- Paul D. Ouderkirk Senior UNIX System Administrator p...@ouderkirk.ca -- laughing, in the mechanism -- William Gibson
Re: Mysql connection from within php
On Tue, Jun 01, 2010 at 04:30:34PM +0300, What you get is Not what you see wrote: Freshly installed on openbsd 4.6 mysql,php and php5-mysql packages. Done the configs. Now php and mysql works. But I couldnt make it connect to mysql from within php with such a command mysql_connect(localhost,user,pass) It used to give Cant connect to mysql through socket error till I change the command to mysql_connect(127.0.0.1,user,pass) I want to learn why? cat /etc/resolv.conf cat /etc/hosts
Re: Mysql connection from within php
01.06.2010 16:45, L. V. Lammert P?P8QP5Q: On Tue, 1 Jun 2010, What you get is Not what you see wrote: Freshly installed on openbsd 4.6 mysql,php and php5-mysql packages. Done the configs. Now php and mysql works. But I couldnt make it connect to mysql from within php with such a command mysql_connect(localhost,user,pass) It used to give Cant connect to mysql through socket error till I change the command to mysql_connect(127.0.0.1,user,pass) I want to learn why? Because the socket is in /var, .. and default apache chroot's to /var/www. I believe there are tricks to make it work, but it's simpler to just connect @127.0.0.1. Lee try to create hosts file for chrooted apache. $ cat /var/www/etc/hosts 127.0.0.1 localhost $ -- thanks. VA