OpenShift – git push your webpage to the cloud

OpenShift provides you with up to three free gadgets. Sufficient cloud space to maintain your PoCs at no cost. The blog shall guide you through the first steps to get your PHP server and pages up and running.

Setup toolchain (git, ruby gems, rhc)

bla@blu:~$ sudo apt-get install git-core
bla@blu:~$ sudo gem install rhc
bla@blu:~$ rhc setup
OpenShift Client Tools (RHC) Setup Wizard

This wizard will help you upload your SSH keys, set your application namespace,
and check that other programs like Git are properly installed.

If you have your own OpenShift server, you can specify it now. Just hit enter to
use the server for OpenShift Online:
Enter the server hostname: ||

You can add more servers later using 'rhc server'.

Login to
Password: ******************************

OpenShift can create and store a token on disk which allows to you to access the
server without using your password. The key is stored in your home directory and
should be kept secret.  You can delete the key at any time by running 'rhc
Generate a token now? (yes|no) yes
Generating an authorization token for this client ... done
Saving configuration to /home/user/.openshift/express.conf ... done

Your public SSH key must be uploaded to the OpenShift server to access code.
Upload now? (yes|no)

Since you do not have any keys associated with your OpenShift account, your new
key will be uploaded as the 'default' key.

Uploading key 'default' ... done

Checking for git ... found git version 1.9.1

Checking common problems .. done

Checking for a domain ... none

Applications are grouped into domains - each domain has a unique name (called a
namespace) that becomes part of your public application URL. You may create your
first domain here or leave it blank and use 'rhc create-domain' later. You will
not be able to create an application without completing this step.

Please enter a namespace (letters and numbers only) |<none>|: xmpldomain
Your domain 'xmpldomain' has been successfully created

Checking for applications ... none

Run 'rhc create-app' to create your first application.

Do-It-Yourself 0.1                         rhc create-app <app name> diy-0.1
JBoss Application Server 7                 rhc create-app <app name> jbossas-7
JBoss Data Virtualization 6                rhc create-app <app name> jboss-dv-6.1.0
JBoss Enterprise Application Platform 6    rhc create-app <app name> jbosseap-6
JBoss Unified Push Server 1.0.0.Beta1      rhc create-app <app name> jboss-unified-push-1
JBoss Unified Push Server 1.0.0.Beta2      rhc create-app <app name> jboss-unified-push-2
Jenkins Server                             rhc create-app <app name> jenkins-1
Node.js 0.10                               rhc create-app <app name> nodejs-0.10
PHP 5.3                                    rhc create-app <app name> php-5.3
PHP 5.4                                    rhc create-app <app name> php-5.4
PHP 5.4 with Zend Server 6.1               rhc create-app <app name> zend-6.1
Perl 5.10                                  rhc create-app <app name> perl-5.10
Python 2.6                                 rhc create-app <app name> python-2.6
Python 2.7                                 rhc create-app <app name> python-2.7
Python 3.3                                 rhc create-app <app name> python-3.3
Ruby 1.8                                   rhc create-app <app name> ruby-1.8
Ruby 1.9                                   rhc create-app <app name> ruby-1.9
Ruby 2.0                                   rhc create-app <app name> ruby-2.0
Tomcat 6 (JBoss EWS 1.0)                   rhc create-app <app name> jbossews-1.0
Tomcat 7 (JBoss EWS 2.0)                   rhc create-app <app name> jbossews-2.0
Vert.x 2.1                                 rhc create-app <app name> jboss-vertx-2.1
WildFly Application Server 10              rhc create-app <app name> jboss-wildfly-10
WildFly Application Server 8.2.1.Final     rhc create-app <app name> jboss-wildfly-8
WildFly Application Server 9               rhc create-app <app name> jboss-wildfly-9

You are using 0 of 3 total gears
The following gear sizes are available to you: small

Your client tools are now configured.

By now, you have a working environment and setup all necessary credentials and your own cloud space.

Create your first PHP application (gear, cartridge)

bla@blu:~$ rhc create-app xmplapp php-5.4
Domain:     xmpldomain
Cartridges: php-5.4
Gear Size:  default
Scaling:    no

Creating application 'xmplapp' ... done

Waiting for your DNS name to be available ... done

Cloning into 'xmplapp'... done

Your application 'xmplapp' is now available.

SSH to:
Git remote: ssh://
Cloned to:  /home/user/xmplapp

Run 'rhc show-app xmplapp' for more details about your app.

You just successfully deployed your web server under your custom domain. You are ready to push your files to your webserver.

Publish your files using git (git push)

OpenShift relies on git repositories to synchronize files between the cloud server and your machine. Files in your repo will be pushed to the web servers document root.

bla@blu:~/Dev/rhc-git/xmplapp$ cp ~/Documents/mirror/* . -r

bla@blu:~/Dev/rhc-git/xmplapp$ ls
myfolder  robots.txt

bla@blu:~/Dev/rhc-git/xmplapp$ git add -A

bla@blu:~/Dev/rhc-git/xmplapp$ git commit -a -m 'initial content load'
[master ef9624f] initial content load
1037 files changed, 159387 insertions(+)
create mode 100644 robots.txt

bla@blu:~/Dev/rhc-git/xmplapp$ git push
Counting objects: 1058, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (1046/1046), done.
Writing objects: 100% (1057/1057), 9.25 MiB | 1.22 MiB/s, done.
Total 1057 (delta 531), reused 0 (delta 0)
remote: Stopping PHP 5.4 cartridge (Apache+modphp)
remote: Waiting for stop to finish
remote: Waiting for stop to finish
remote: Building git ref 'master', commit a23b241
remote: Checking .openshift/pear.txt for PEAR dependency...
remote: Preparing build for deployment
remote: Deployment id is ab46361a
remote: Activating deployment
remote: Starting PHP 5.4 cartridge (Apache+modphp)
remote: Application directory "/" selected as DocumentRoot
remote: -------------------------
remote: Git Post-Receive Result: success
remote: Activation status: success
remote: Deployment completed with status: success
To ssh://
1aa6203..a23b241  master -> master

Finally, it’s all there. Go, have a look at

Custom Domain Name (add an alias and CNAME record)

Add an alias to your PHP application (gear) if your prefer to run it under your custom domain. Run the following command assumed your domain name is Note, you need to add a CNAME record to your DNS configuration to let point to

bla@blu:~/Dev/rhc-git/xmplapp$ rhc alias add xmplapp
Alias '' has been added.

Your web page will be reachable by Note, that TLS (formerly SSL) for custom domains is not available within the free plan.

Create your first backup (save snapshots)

Well, it’s nice to have stuff online but a local backup might come in handy some time. So, let’s keep a snapshot of the site.

bla@blu:~/Dev/rhc-git$ rhc snapshot save xmplapp
Pulling down a snapshot of application 'xmplapp' to xmplapp.tar.gz ... done

rhc will store the snapshot as gzipped tarball (.tar.gz) in the working directory. It’s named after the application xmplapp.tar.gz.

bla@blu:~/Dev/rhc-git$ ls
xmplapp  xmplapp.tar.gz