The OpenShift forums have been retired, but you can still read and search them.
For the most up-to-date information about how to use OpenShift please visit

PHP + MySql + Zend Framework

I have a web running on a shared hosting account which I have, running without any problem. Since last week I'm trying to run the same app on a openshift php cartridge.

If I try to access mysql database from my app, I get this error: Message: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

You can see this error here

I'm accessing database with the enviroment variable.

I'm able to connect to mysql from ssh also from mysql workbench.

I have to say that this app is working well in other enviroments so I don't think it's problem of my code.

Thank you.


Sorry to hear about you trouble, maybe you can give a bit more information? Like what cartrigdes are you using and which version of Zend Framework?

Also this looks like a php config error did you try to set 'mysqli.default_socket' in '.htaccess' to something like '${OPENSHIFT_REPO_DIR}/mysql.sock'? or maybe try and see if using 'mysql' works?

Good luck, Warnar


As you said, I added this two lines in my .htaccess and now is working!!

php_value mysql.default_socket "${OPENSHIFT_MYSQL_DB_SOCKET}"

php_value mysqli.default_socket "${OPENSHIFT_MYSQL_DB_SOCKET}"

Thank you very much!

Hi, I've submitted a bug report for this issue:


Sorry for hijacking this thread but I also have a similar problem.

PHP 5.3 + Zend Server 5.6
MySQL 5.5 cartridge

All the $OPENSHIFT_MYSQL_* environment variables are available on the environment via:

$ env | grep MYSQL

Also I can see them if I run a small PHP test using:

php -r  'echo getenv('OPENSHIFT_MYSQL_DB_HOST');'
php -r  'echo $_ENV['OPENSHIFT_MYSQL_DB_HOST'];'

However, as soon as my PHP application is served through the Apache server the OPENSHIFT_MYSQL_* environment variables are no longer available. Does someone know why this happens?

Currently, what I'm doing based on Warnar Boekkooi's suggestion is to add additional environment vars directives in my .htaccess file when the deploy runs, .e.g,

SetEnv OPENSHIFT_MYSQL_DB_HOST "replace-token"
SetEnv OPENSHIFT_MYSQL_DB_PORT "replace-token"

Since you are using zend, is there another way you need to reference the environment variables?

Actually, I only use Zend because of the mcrypt extension support. I'm not really sure whether I need to configure the database connection properties somewhere in the Zend server itself? My PHP application uses the pdo_mysql driver to connect to the MySQL database by passing the host,user,password as standard configuration parameters.

I can use getenv and $_ENV to read all the OPENSHIFT_MYSQL_DB* vars from within a PHP script executed on the command line when logged on via ssh. The same script prints empty strings for all OPENSHIFT_MYSQL_DB* vars when run by the Zend server.

Hmmm, i found this (, can you see any of the NON DB variables? Also try restarting your gear, if you added mysql AFTER you created your gear with zend, that could be the issue. Issue a stop, then a start, not just a restart. use the rhc command line.

Well, now after I did the stop/start procedure it worked! Thank you. It's been 2 days now that I struggle with this issue. :)

The comment below that gist represents exactly what has been happening on my side. When I ran that script (before the stop/start) I got exactly the same results as in the comment posted there.

In any case now it all seems to work. I must note that previously I used "restart" to restart my app and also the cartridges. How does restart differ from start/stop?

I believe it does an "apache reload" instead of a stop/start, which does not reload the environment