What is OpenShift? It is a cloud, it is from Red Hat. More precisely: A PaaS (Platform As A Service).
It is available since quite some time now and I finally found some time to test it. Conclusion: It is very simple to use. This will guide you how to create a PHP application which just prints “this is a test”. More to come in future postings.
The following steps are needed:
- Create an account
- Installing the CLI and setting up your environment
- Create an application
- Initialize a git repository
- Put some content into your git repository
- Push/publish your application
It is a good idea to start reading https://www.openshift.com/get-started”.
Create an account
Simply head to https://openshift.redhat.com/app/account/new and fill in the form. The captcha can be a hassle, you may need to try reading it correctly several times.
Setting up your environment
before being able to use your account, you need to install and set up some software on your developer workstation. Of course you also can go for the “Wimp Way” and using the web-UI, but real men use the CLI for higher productivity.
The following steps I used on my Fedora 18 box:
f18:~# yum install rubygems git
Next, install the CLI tool. The simplest way to do so is using gem.
f18:~# gem install rhc Fetching: net-ssh-2.6.7.gem (100%) Fetching: archive-tar-minitar-0.5.2.gem (100%) Fetching: highline-1.6.19.gem (100%) Fetching: commander-4.1.3.gem (100%) Fetching: httpclient-2.3.3.gem (100%) Fetching: open4-1.3.0.gem (100%) Fetching: rhc-1.9.6.gem (100%) =========================================================================== If this is your first time installing the RHC tools, please run 'rhc setup' =========================================================================== Successfully installed net-ssh-2.6.7 Successfully installed archive-tar-minitar-0.5.2 Successfully installed highline-1.6.19 Successfully installed commander-4.1.3 Successfully installed httpclient-2.3.3 Successfully installed open4-1.3.0 Successfully installed rhc-1.9.6 7 gems installed Installing ri documentation for net-ssh-2.6.7... Installing ri documentation for archive-tar-minitar-0.5.2... Installing ri documentation for highline-1.6.19... Installing ri documentation for commander-4.1.3... Installing ri documentation for httpclient-2.3.3... Installing ri documentation for open4-1.3.0... Installing ri documentation for rhc-1.9.6... Installing RDoc documentation for net-ssh-2.6.7... Installing RDoc documentation for archive-tar-minitar-0.5.2... Installing RDoc documentation for highline-1.6.19... Installing RDoc documentation for commander-4.1.3... Installing RDoc documentation for httpclient-2.3.3... Installing RDoc documentation for open4-1.3.0... Installing RDoc documentation for rhc-1.9.6...
Just to be sure there are not updates available:
f18:~# gem update rhc Updating installed gems Nothing to update
Next on the list is to set up your credentials and evironment. It is wizard style and will guide you trough the process.
[luc@f18 ~]$ 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. Login to openshift.redhat.com: your-account@example.com 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 logout'. Generate a token now? (yes|no) yes Generating an authorization token for this client ... lasts about 1 day Saving configuration to /home/luc/.openshift/express.conf ... done Your public SSH key must be uploaded to the OpenShift server to access code. Upload now? (yes|no) yes 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.8.1.4 Checking common problems .. done Checking your namespace ... none Your namespace is unique to your account and is the suffix of the public URLs we assign to your applications. You may configure your namespace here or leave it blank and use 'rhc create-domain' to create a namespace later. You will not be able to create applications without first creating a namespace. Please enter a namespace (letters and numbers only) ||: ldelouw Your domain name 'ldelouw' has been successfully created Checking for applications ... none Run 'rhc create-app' to create your first application. [..] Your client tools are now configured.
Create an application
Now as your environment is nearly finished setting up you can create your application instance on OpenShift.
[luc@f18 ~]$ rhc create-app test zend-5.6 Application Options ------------------- Namespace: ldelouw Cartridges: zend-5.6 Gear Size: default Scaling: no Creating application 'test' ... done Waiting for your DNS name to be available ... done Downloading the application Git repository ... Cloning into 'test'... The authenticity of host 'test-ldelouw.rhcloud.com ()' can't be established. RSA key fingerprint is a-finger-print. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'test-ldelouw.rhcloud.com' (RSA) to the list of known hosts. Your application code is now in 'test' test @ http://test-ldelouw.rhcloud.com/ (uuid: a-uuid) ------------------------------------------------------------------------ Created: 5:22 PM Gears: 1 (defaults to small) Git URL: ssh://a-uuid@test-ldelouw.rhcloud.com/~/git/test.git/ SSH: a-uuid@test-ldelouw.rhcloud.com zend-5.6 (Zend Server 5.6) -------------------------- Gears: 1 small RESULT: Application test was created. Note: You should set password for the Zend Server Console at: https://test-ldelouw.rhcloud.com/ZendServer Zend Server 5.6 started successfully
As mentioned in the output, you shoud proceed to https://yourapp-yourdomain.rhcloud.com/ZendServer
Initialize a git repository
This is not very clear in Red Hats documentation. When creating an application on OpenShift, a git repository is created to you. In order to push your app, you need to clone that repository locally or adding an upstream git master. Lets do it locally for now:
[luc@f18 ~]$ cd ~/your-project-directory [luc@f18 your-project-directory]$ git clone ssh://a-uuid@test-ldelouw.rhcloud.com/~/git/test.git/ Cloning into 'test'... remote: Counting objects: 26, done. remote: Compressing objects: 100% (20/20), done. remote: Total 26 (delta 2), reused 20 (delta 0) Receiving objects: 100% (26/26), 6.99 KiB, done. Resolving deltas: 100% (2/2), done.
Put some content into your git repository
What a git repository and an application instance without some content? Nothing, so lets change that.
[luc@f18 your-project-directory]$ cat <<EOF>test/php/test.php <?php print "this is a test"; ?> EOF
Adding your project file to the git repository:
git add test.php
Commit it:
git commit
And push it:
[luc@f18 your-project-directory]$ git push Counting objects: 6, done. Delta compression using up to 8 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (4/4), 398 bytes, done. Total 4 (delta 1), reused 0 (delta 0) remote: CLIENT_MESSAGE: Stopping Zend Server Console remote: Stopping Zend Server GUI [Lighttpd] [OK] remote: CLIENT_MESSAGE: Stopping Zend Server JobQueue daemon remote: Stopping JobQueue [OK] remote: CLIENT_MESSAGE: Stopping Apache remote: CLIENT_MESSAGE: Stopping Zend Server Monitor node remote: Stopping Zend Server Monitor node [OK] remote: CLIENT_MESSAGE: Stopping Zend Server Deployment daemon remote: Stopping Deployment [OK] remote: CLIENT_RESULT: Zend Server 5.6 stopped successfully remote: TODO remote: CLIENT_MESSAGE: Starting Zend Server Deployment daemon remote: Starting Deployment [OK] remote: [08.06.2013 11:36:30 SYSTEM] watchdog for zdd is running. remote: [08.06.2013 11:36:30 SYSTEM] zdd is running. remote: CLIENT_MESSAGE: Starting Zend Server Monitor node remote: Starting Zend Server Monitor node [OK] remote: [08.06.2013 11:36:31 SYSTEM] watchdog for monitor is running. remote: [08.06.2013 11:36:31 SYSTEM] monitor is running. remote: CLIENT_MESSAGE: Starting Apache remote: CLIENT_MESSAGE: Starting Zend Server JobQueue daemon remote: Starting JobQueue [OK] remote: [08.06.2013 11:36:34 SYSTEM] watchdog for jqd is running. remote: [08.06.2013 11:36:34 SYSTEM] jqd is running. remote: CLIENT_MESSAGE: Starting Zend Server Console remote: spawn-fcgi: child spawned successfully: PID: 1433 remote: Starting Zend Server GUI [Lighttpd] [OK] remote: [08.06.2013 11:36:36 SYSTEM] watchdog for lighttpd is running. remote: [08.06.2013 11:36:36 SYSTEM] lighttpd is running. remote: CLIENT_RESULT: Zend Server 5.6 started successfully To ssh://a-uuid@test-ldelouw.rhcloud.com/~/git/test.git/ xxxxx..yyyy master -> master [luc@f18 your-project-directory]$
Did it all worked?
Lets try…
[luc@bond test]$ wget --quiet http://test-ldelouw.rhcloud.com/test.php -O -|grep test this is a test [luc@bond test]$
Yes!