PaaS is fun!
The fastest path to an OpenShift app that includes PHP and a MySQL database:
- Follow all of their on-screen instructions to create a PHP 5.3 app (it really is just next-next-next).
- Set up your SSH keys in your dev environment if that’s not done yet – OpenShift helpfully prompts you for it before giving you your git URLs.
- Add a MySQL cartridge to your app – literally just next-next-next-done
- Don’t worry about recording the username and password – OpenShift passes environment variables for those
- Clone the repo, cd php/ and stick the following in index.php
$mysqli = new mysqli( $_ENV['OPENSHIFT_MYSQL_DB_HOST'], $_ENV['OPENSHIFT_MYSQL_DB_USERNAME'], $_ENV['OPENSHIFT_MYSQL_DB_PASSWORD'], $_ENV['OPENSHIFT_APP_NAME'], // By default, app name == db name $_ENV['OPENSHIFT_MYSQL_DB_PORT'], $_ENV['OPENSHIFT_MYSQL_DB_SOCKET'] );
That gives you MySQL over TCP/IP. To use the UNIX socket, just set the first parameter to NULL (in the absence of a host, PHP will try the socket).