http://www.developer.com/lang/php/setting-up-openshift-for-php-cloud-development.html

Back to article




Using your OpenShift login and password, execute the $rhc setup command. This command sets up our SSH key, so that you can securely communicate with Git, and creates a namespace for all your applications to be grouped under.

After running the rhc setup command, you should get something like in the next figure:

Run rhc setup command for uploading SSH keys and setting the namespace for the application
Figure 6 - Run rhc setup command for uploading SSH keys and setting the namespace for the application

You may notice, from the above figure, that my namespace for the incoming application is OctaviaExamples and, as I said in the section "Create an OpenShift account", was set after I created my OpenShift account, from OPENSHIFT MANAGEMENT CONSOLE, My account tab.

My OpenShift Account containing namespace and SSH keys, after running the rhc setup command
Figure 7 - My OpenShift Account containing namespace and SSH keys, after running the rhc setup command

Create a PHP 5.3 Cloud Application from Command Line

To create a PHP cloud application from the command line, you only need to use the $ rhc app create $appName php-5.3 command. My application name is firstExample, as you can see from the next figure:

Creating first cloud application from command line
Figure 8 - Creating first cloud application from command line

Going into the cloud account, application firstExample should appear now, in the My Applications tab:

My Applications tab from the OpenShift Account containing the first application created above
Figure 9 - My Applications tab from the OpenShift Account containing the first application created above

Testing the application on cloud, you should get something like the next figure:

Testing the firstExample application in the cloud
Figure 10 - Testing the firstExample application in the cloud

Next, is a list containing the most important commands you can use to control your application:

1. Create - Create an application and add it to a domain

2. git-clone - Clone and configure an application's repository locally

3. delete - Delete an application from the server

4. start - Start the application

5. stop - Stop the application

For example, if we want to delete the firstExample application we will use the following command:

$ rhc app delete firstExample

Of course, you can delete an application from your management console, in your OpenShift account.

This is the fastest and easiest method to create a PHP 5.3 cloud application. So, to accomplish this task all you need to do is:

1. open your OpenShift account

2. go on Create Application tab

3. select PHP from the list (figure 11):

Choosing PHP from the application types
Figure 11 - Choosing PHP from the application types

4. After you select PHP from the above list you should choose a web programming cartridge you want to use next. You may notice from the below figure that Zend Server 5.6, CakePHP, Drupal 7, WordPress 3.x and PHP 5.3 are the application types available for creating a PHP cloud application. You also have the opportunity to enable additional capabilities like databases, cron, metrics, and continuous build support after you create the application. (In the next section of this article we will add a database to this second application)

The available PHP cartridges for the cloud applications
Figure 12 - The available PHP cartridges for the cloud applications

We will choose to create a simple PHP 5.3 application; therefore we will choose PHP 5.3 application type. All we have to do next is to set a name for our application; we will name it secondExample, and press the Create Application button. That's it! In My Applications tab you should see now the new created application.

Clone the PHP Cloud Application into a Local Repository

To clone the cloud application, secondApplication, we will use the below command, which creates a local copy of the source code repository for you.

$ rhc git-clone secondExample

Cloning the secondExample cloud application and seeing its structure on our local repository
Figure 13 - Cloning the secondExample cloud application and seeing its structure on our local repository

Adding Cartridges

First, we need to check the available cartridges and for that, we need to use the below command, from command line:

$ rhc cartridge list

Listing all the available cartridges
Figure 14 - Listing all the available cartridges

You may notice this is a complete list of available cartridges, not only for PHP.

As I said in the previous section, we can add specific features to our application; in our case we will add a database. For this, we need first to add the mysql-5.1 cartridge. There are two methods to add mysql-5.1 cartridge:

1. from command line, using the below command:

$ rhc cartridge add mysql-5.1

Adding the mysql-5.1 cartridge to application secondExample in command line
Figure 15 - Adding the mysql-5.1 cartridge to application secondExample in command line

2. directly on cloud, by pressing the Add Cartridge button:

Adding the mysql-5.1 cartridge to application secondExample on cloud
Figure 16 - Adding the mysql-5.1 cartridge to application secondExample on cloud

We will get a list with the available cartridges for our PHP application, secondExample:

 Available PHP cartridges
Figure 17 - Available PHP cartridges

Select MySQL database 5.1 and then press the Add cartridge button. You will receive a user and a password and you should make a note of them or make a print screen figure containing them, because you will need them later when you populate your database:

Confirmation message that MySQL cartridge was successfully added to your application
Figure 18 - Confirmation message that MySQL cartridge was successfully added to your application

Now, that we have added the mysql-5.1 cartridge, we can add the phpMyAdmin 3.4 cartridge, which is a web based MySQL admin tool and for that requires that MySQL cartridge should be installed first. So, select the phpMyAdmin 3.4 cartridge and press the Add Cartridge button. This is the message you will get after adding phpMyAdmin cartridge:

Confirmation message that phpMyAdmin cartridge was successfully added to your application
Figure 19 - Confirmation message that phpMyAdmin cartridge was successfully added to your application

Notice that you will also receive a URL and we will use that URL to connect to our database, through the phpMyAdmin MySQL admin tool. Opening this URL into a new browser page, you will get an Authentication Required window, where you should introduce the user and password received previously (when I said that you should note them, in order to remember):

 Connecting to phpMyAdmin
Figure 20 - Connecting to phpMyAdmin

Entering into phpMyAdmin account
Figure 21 - Entering into phpMyAdmin account

Notice that a database with the name of the cloud application was created simultaneously, secondExample.

These are the main steps in creating a cloud application, which is based on databases; from now on you can expand the cloud application as you like, by adding any cartridges you need, populating the database and so on.

In the last part of this article, we will create a Wordpress quick start example. The Wordpress quick start repository for OpenShift Express is on github. And, to create the cloud application you should run the command from figure 22, using your OpenShift account:

Creating an Wordpress example using our OpenShift account
Figure 22 - Creating an Wordpress example using our OpenShift account

That is it! Checking now your OpenShift account, on the My Application tab you should see, beside our two previous examples, also this new Wordpress example:

My Application tab from the OpenShift account
Figure 23 - My Application tab from the OpenShift account

Now, testing it the first time in a new browser page, you will be asked to provide some information, in order to install Wordpress, as you can see from figure 24:

Install Wordpress, in order to host and run your own blog on your own server
Figure 24 - Install Wordpress, in order to host and run your own blog on your own server

After the installation process you will be redirected to your Wordpress Dashboard, where you can manage your site however you like:

The Management Console of our Wordpress quiqstart example
Figure 25 - The Management Console of our Wordpress quiqstart example

Conclusion

You have learned how to create an OpenShift account in order to create a PHP cloud application, how to create a simple PHP application from the command line and from the web cloud account, how to add cartridges to your application and how to create a Wordpress quickstart example. Further, you can continue exploring and practicing the amazing capabilities of PHP cloud development on your own.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date