I'm setting up a VPS for a WordPress blog. I'm using Ubuntu 14.04 LTS 64 bits and then I've installed Nginx 1.7.8, HHVM 3.6.0, MariaDB (don't remember the version). Finally I've downloaded WordPress 4.1.1 and after creating the database and editing the wp-config.php file with the correct parameters (database name, user and password) I try to connect to the blog to set it up.

I've done this kind of installation before but it was some months ago and I don't remember having any problem. But after trying everything I know of I can't solve the problem: everytime I try to load the blog on my browser to start the final WordPress installation process (the form with the name, admin and password) I get the legendary, horrible message:

Error establishing a database connection

The fact is, mysql is running, but something that I don't understand is wrong. I've created a testconnection.php file on the root of my blog with the following content

$link = mysql_connect('localhost', 'root', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
echo 'Connected successfully';

editing with the right password, of course. When I load that php file on the browser I get a

"Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)"

That file isn't anywhere, and my /etc/mysql/my.cnf points to /var/run/mysql/mysqld.sock (which is shown also if I do a ps xa | grep mysql. Trying to do a symbolic link doesn't work either:

ln -s /tmp/mysql.sock /var/run/mysql/mysqld.sock

and I'm getting out of ideas. The /var/run/mysql directory has www-data:www-data as owners, and the WordPress blog directory is owned by www-data:www-data as well.

I really don't know what's going on, I've read several messages over here and some other sites, but the things that they point to (check wp-config.php, restart mysql...) don't work because I've been careful with that. Ideas, please?

  • when you run the mysql client command (mysql -u root -p), it gives you the same error? – hdanniel Mar 18 '15 at 17:14
  • No, I can access MySQL withouth problem (from the root account or from the user account I've created) and do whatever I want there :/ – javipas Mar 19 '15 at 9:24

I've just found the solution: there seems to be some problem with HHVM and MySQL connection when you try to use "localhost" or "localhost:port", as shown on the HHVM documentation.

I've found the answer on GitHub. I needed to edit /etc/hhvm/php.ini file and add the line

hhvm.mysql.socket = /var/run/mysqld/mysqld.sock

Then I just have to do a sudo service hhvm restart and finally, finally, finally, everything works. Uauh.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.