[OpenShift] Deploy PHP/MySQL in OpenShift got 503 Service Temporarily Unavailable / 504 Gateway Time-out

Context :

The objective is to deploy the connection of MySQL with PHP in an OpenShift Server.
OpenShift is PaaS provided by Red Hat. For more info, read wikipedia OpenShift.

Problem :

The server returns :

503 Service Temporarily Unavailable


504 Gateway Time-out

Code source :

<?php $con = mysqli_connect("localhost","my_user","my_password","my_db"); // Check connection 
  if (mysqli_connect_errno()) { 
     echo "Failed to connect to MySQL: " . mysqli_connect_error(); 

Reason :

For a scalable gear in OpenShift, we have to specify the mysql port to make it work.

Solution :

<?php $con = mysqli_connect("localhost","my_user","my_password","my_db", "54321"); // Check connection 
   if (mysqli_connect_errno()) { 
      echo "Failed to connect to MySQL: " . mysqli_connect_error(); 

To get the values of the database variable (to mysql, just replace by mysql):

Variable Name



The host name or IP address used to connect to the database.


The port the database server is listening on.


The database administrative user name.


The database administrative user’s password.


An AF socket for connecting to the database (for non-scaled apps only).


Database connection URL.

And the syntax for mysqli in PHP :


Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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