Hosting an apache server in Openshift with a godaddy hosted domain

Posted by Jose Estudillo on August 4, 2015

Hosting an apache server in Openshift with a godaddy hosted domain

In this article I’ll show how to point an existing domain hosted in godaddy to an apache server running in Openshift, to do so I’ll use the following generic URLs:

  • Subdomain under you already registered domain: http://SUBDOMAIN.DOMAIN.com

  • URL to the apache server hosted in OpenShift: http://APP_NAME-OPENSHIFT_DOMAIN_NAME.rhcloud.com

And I will also assume you have a free account in OpenShift.

Creating an application

Once logged into OpenShift go to: Applications -> Add Application…

In this case I will focus in creating a simple apache server. Configuring any other type of server should work in the same way. The apache server isn’t offered as an option, but any server that can host PHP will work (for example: PHP 5.3, PHP 5.4).

During the instantiation process, we will be asked to create an URL for the new application, in our case this will be: http://APP_NAME-OPENSHIFT_DOMAIN_NAME.rhcloud.com. Unless you have specific needs, the rest of the parameters can be left as they are. A git repository can be given to obtaion the content, otherwise, one will be created for every application.

Uploading files to the application using git

In the right side hand of the application configuration menu, there is a box that displays the git repository associated to the app, for this example it would look like ssh://ID@APP_NAME-OPENSHIFT_DOMAIN_NAME.rhcloud.com/~/git/APPNAME.git/ using this URL we can clone the git repository from the CLI:

git clone ssh://[ID]@APP_NAME-OPENSHIFT_DOMAIN_NAME.rhcloud.com/~/git/APPNAME.git/

Once it has been cloned, we can place the required files into the directory APPNAME. The last step will be uploading the files, this can be done using the commands below:

git add --all
git commit -m "`date`"
git push origin

Notice that for this to work you will need credentials, the easiest way to do it is having your public shh key configured in OpenShift. This is outside the scope of this article, so as a quick tip, ssh-keygen -t rsa -b 4096 -C "your@email.com" will generate the public key and cat ~/.ssh/id_rsa.pub will display it.

Setting the alias domain

From the application configuration page, right next to the application’s URL, there is a link called change, clicking on it will take you to a menu where you can see two values:

  • Application URL: is the actual URL app, it should look like http://APP_NAME-DOMAIN_NAME.rhcloud.com (as defined before) and

  • Domain Name: which is the domain that will be pointing to this app, being in the case SUBDOMAIN.DOMAIN.com.

With this is setup, no further configuration is required on the OpenShift side.

Configuring the domain in Godaddy

To point our domain to a OpenShift’s application we need two things:

  • redirect DOMAIN.com to SUBDOMAIN.DOMAIN.com

  • add a CNAME entry to point SUBDOMAIN.DOMAIN.com to the OpenShift URL.

The redirection is done using forwarding at domain level (no subdomain!) so clicking in manage under the forwarding category should allow you to add an entry:

  • Forward To: http://SUBDOMAIN.DOMAIN.com

  • Redirect Type: 301 (Permanent)

  • Forward Settings: Forward only

Adding the CName entry is done from a different tab, DNS ZONE FILE, where you must check that under:

  • A (Host) : there is no entries for the subdomain you want to redirect, and, in

  • CName (Alias): you add the entry:

    • Record Type: CNAME (alias)

    • Host: SUBDOMAIN

    • Points To: http://APP_NAME-OPENSHIFT_DOMAIN_NAME.rhcloud.com

    • TTL: 1 hour

If you got to this point you are all setup, after waiting a few minutes (this may vary) the page will be ready to use.