Php – OpenBSD Nginx/PHP/MariaDB/PHP-FPM Stack

mariadbopenbsdPHP

I have a minimal OpenBSD 5.7 amd64 install in VMware where I have installed matching versions of PHP and PHP-FPM, plus nginx, and mariadb using pkg_add. I configure all the services, and get nginx to parse HTML through PHP-FPM, and everything is fine, until I try to connect to MariaDB. It does not connect to MySQL/MariaDB. I have tried three different PHP CMSes using correct credentials, and each gives the following error:

Warning: mysql_connect(): Can't connect to local MySQL server through socket Warning: mysql_connect(): Can't connect to local MySQL server through socket /var/run/mysql/mysql.sock (62 "Too many levels of symbolic links") in /htdocs/index.php on line 5

This is after doing ths

mkdir -p /var/www/var/run/
ln -s /var/run/mysql /var/www/var/run/mysql

What in the world is the problem here? I have tried four different tutorials, and I just simply cannot get PHP and MySQL to work with each other. Even though I am certain MySQL is running, and I can use mysql -p -u ... to connect just fine to the server.

Please help.

EDIT:

# ls -al /var/run/mysql /var/www/var/run/mysql
lrwxr-xr-x  1 root  daemon  14 May  5 11:07 /var/www/var/run/mysql -> /var/run/mysql

/var/run/mysql:
total 8
drwx--x--x  2 _mysql  _mysql  512 May  5 11:01 .
drwxr-xr-x  4 root    wheel   512 May  5 11:06 ..
srwxrwxrwx  1 _mysql  _mysql    0 May  5 11:01 mysql.sock
#

Best Answer

Your /var/www/var/run/mysql points to /var/run/mysql. By the directory structure I presume, you are chrooting your apache/php into /var/www. It probably is a default of OpenBSD.

When chrooted into /var/www your link actually becomes /var/run/mysql -> /var/run/mysql, which is pretty much infinite loop.

You either need to provide socket inside that chroot, using socket configuration option, or use TCP connections.

Edit: Just by the way, if you are not used to working with OpenBSD, you probably should not use that for production. You probably won't get any more secure than with a system/distro you know well.