Zero to PHP + MySQL on RedHat OpenShift

PaaS is fun!

The fastest path to an OpenShift app that includes PHP and a MySQL database:

  1. Follow all of their on-screen instructions to create a PHP 5.3 app (it really is just next-next-next).
  2. 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.
  3. Add a MySQL cartridge to your app – literally just next-next-next-done
  4. Don’t worry about recording the username and password – OpenShift passes environment variables for those
  5. Clone the repo, cd php/ and stick the following in index.php
$mysqli = new mysqli(
$_ENV['OPENSHIFT_APP_NAME'], // By default, app name == db name

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).


About these ads

One thought on “Zero to PHP + MySQL on RedHat OpenShift”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s