Tuesday, December 3, 2013

How to use Codenvy and GitHub together.

In "Easy, simple develop and deploy PHP, MySQL applications using the cloud. Manage the MySQL service."  I showed to you how to get started with PHP/MySQL development/deployment in the most convenient, easy and simple way using only cloud technologies. All you need is only a web browser. In this tutorial I will show you how to use Source Control Management (SCM)/ Version Control System (VCS) such as Git to track your revisions and share the project in GitHub or another Hosting service of choice.

There is also a YouTube Tutorial on the same topic.

You don't need to carry around flash drives DVDs or a computer. You can use any computer/device in the world. All you need is Internet and web browser. Your development stack(s) and projects just follow you and they are stored safely somewhere in the cloud. :)

All you need is again only a web browser!

I have made a lot of screenshots. Don't let this scare you. :)
I just explain everything step by step. And I think more screenshots will actually help you.

So if you have already created  an application in Codenvy you can push it to GitHub and I am going to explain how it is done. If you want to knwo how to create a PHP application in a very easy and convenient way please read my tutorial "Easy, simple develop and deploy PHP, MySQL applications using the cloud. Manage the MySQL service."

1) Just open the project you want to push to GitHub or another SCM hosting service. (e.g. bitbucket)

 2) We have to generate RSA key pair in order to allow Codenvy and GitHub to exchange data securely. In order to do so you have to go to Window->Preferences in Codenvy.
 3) Hit "Generate Key"
 4) Enter the domain name of the hosting service. In our case "github.com"
 5) The RSA key pair has been generated. You can see the public key by clicking on "view"
 6) Copy the public key.
 7) Go to your GitHub account settings -> SSH keys and add the public key.
 8) Paste the public key and give it a name.
 9) You will be asked to enter your credential again.
 10) The key has been stored in GitHub. So Codenvy holds the private key and Github has the public key now. These 2 services can communicate using a secure protocol.
 11) It is time to create a repository for our project, which exsists so far only in Codenvy.
 12) Give it  a name.
 13) You have to choose SSH. (Remember from step 10 we are using RSA key pair)
 14) Initialize a repository in Codenvy.
 15) Add all files and folders.
 16) Add the address to your GitHub repository which will hold your project files.

 17) Just make sure you use the right address of the repository. It should be SSH address.

 18) Lets add all the files and folders we want to be under the control of the SCM (Git).

19) Lets commit. This is adding the files to the local database of Git

 20) Lets push our local files to GitHub.

 21) refresh to make sure all files have been uploaded to the remote (origin) repository.

I hope you find this tutorial useful. Just like, share and comment.
Have fun! :)

Easy, simple develop and deploy PHP, MySQL applications using the cloud. Manage the MySQL service.

You want to start developing with PHP and MySQL, but you don't want to mess around with installation of Apache, MySQL server, dealing with hosting companies etc.?
There is a way. And this way leads to the clouds! :)
You can develop and deploy your application within 5-10 minutes.
This tutorial can be used by beginners and advanced users.

All you need is just a web browser! :)

I have created a YouTube Tutorial as well. It describes the same steps and it is only 15 minutes long. So in 15 minutes or less you can have an application up and running without the troubles of installing a development stack.

The key is a cloud IDE called "Codenvy". It allows you to create your app within seconds and Deploy it to a lot of existing "Platform as a Service", In this tutorial I will show how to do so with "AppFog". You can use not only MySQL but mongoDb, Redis etc. And you can develop not only PHP applications, but Java, Ruby etc.

All these steps can be executed from almost every computer or device in the planet that can run a web browser. You are free to use different computers, operating systems, browsers. Your development stacks and projects are always with you. And you can deploy your applications with a click of a button.  :)

We are going to use 2 applications. Don't worry they are created with a click of a button. One of them is our real application. Another is temporary used just to deploy phpMyAdmin to be able to manage our MySQL service on AppFog. You can delete it from the IDE (Codenvy) after the deployment is done if you wish. :)

I have made a lot of screenshots. But don't worry! They are here not to confuse you, by explaining difficult concepts, but to make it easier for you, showing every simple dummy step. Also you can run them as a slideshow and even don't have to read the text in the post.

1) Go to https://codenvy.com/ . Login or register. They support OpenID so you can login with github or google account.

 2)You can start from scratch or if you already have a project in Codenvy you can open it. In this tutorial I will assume you are starting from scratch and you want to use PHP and MySQL
 3) Give a name to the project. Choose the technology. It is PHP in our case. Choose the deployment platform. I am going to use AppFog as a PaaS. It is very good one. You application will become available online for a seconds. And you can choose from many DB services: MySQL, MongoDB, Redis etc.

 4) Login with your AppFog username.password or go to https://www.appfog.com/, register and get an account.
 5) Select the infrastructure. AppFog has 4 infrastructures at the moment (AWS Asia Southeast, AWS Europe West, AWS US East, HP Openstack AZ 2). Select the infrastructure according to your customers.
 6) And you are Done! :). Your "Hello World!" PHP application is up and running. It is also available to your customers to access it. But don't you worry. Only the people who know the URL can access it.

7) You are in charge. You have full control over the instance of your application directly from Codenvy

 8) It is time to run a DB service on the infrastructure if you need one. You can do it directly from the IDE (Codenvy) or go to appfog.com and do it from their interface.

 9) Lets do it from the AppFog interface (dashboard). Login to AppFog.
 10) Find your running application. As you can see you have a full control.
 11) Select "Services", because we want to use a MySQL service in our PHP application.

12) We have the service up and running, ready to be used in our PHP app.
 13) But we want to be ablle to mange the DB server (MySQL) add, delete tables etc. We can achieve this using tunneling. But this requires installing software etc. There is an easier way, by using phpMyAdmin. So lets deploy and run an instance of phpMyAdmin on the same Infrastructure and manage the MySQL service. In order to do so we are using again Codenvy. It is extremely easy to deploy apps from the cloud IDE.
Start by creating a new Project in Codenvy which we will use to Deploy phpMyAdmin to AppFog infrastructure.
 14) phpMyAdmin is a PHP application. This is the reason we start again with creating a PHP project and choose to deplaoy to the same PaaS (AppFog) on the same infrastructure as our running MySQL service

 15) Check if your second app is running on AppFog.
 16) We don't need any of the files from a Codenvy "Hello World" PHP app, so lets delete them.
17) We are going to use GitHub to pull the right version of phpMyAdmin from https://github.com/appfog. This is a modified version of phpMyAdmin. Notice we are not downloading the original version of phpMyAdmin.

 18) Go to https://github.com/appfog and find phpMyAdmin there
 19) Copy the address of the repo.
 20) Add the remote repository address. This is the address of  phpMyAdmin https://github.com/appfog/af-php-myadmin

 21) Pull the phpMyAdmin from the repo.

 22) Deploy the phpMyAdmin to AppFog

 23) Try to see if it has been deployed. It is there, but we have to do configuration before we start using it.
24) Go to AppFog and find the project from our phpMyAdmin.
 25) Bind the running MySQL service to our phpMyAdmin application. We are going to manage the service with this phpMyAdmin.

 26) Set up the password for our phpMyAdmin instance. In order to do so, we have to set an Environment Variable for our phpMyAdmin app in AppFog. Go to Env variables tab and enter PMA_PASSWORD to whatever password you want to use to access your phpMyAdmin.
 27) After having completed the previous steps you can refresh the page with your phpMyAdmin instance to enter your username/password
 28) As a username use your AppFog username (it is an email address) and as a password use the password you have set in the Environment Variable PMA_PASSWORD. You can change the username as well. All you have to do is set another variable PMA_USERNAME with the desired value and in this case when you login to your phpMyAdmin instance instead of using your AppFog username you can use the username you have set up with the variable PMA_USERNAME
 29) Congratulations! You have setup your instance of phpMyAdmin. You can create, drop tables etc. You are in charge.
 30) You can go back to your original application now in Codenvy. You can delete from your IDE (Codenvy) the extra application we have created for phpMyAdmin. Or you can keep it there. :)

 31) There is one more thing. How to connect from our app to the MySQL server? All the connection information is in an Environment Variable called VCAP_SERVICES. It is a JSON object. So you can convert it to an PHP array and get the username, password, database name etc. for your MySQL instance. You can find  an example code on how to parse and use the values in pastebin.com

32) You are in charge of your running application on AppFog and the services. You can Stop, Start, Remove etc. the instance of your application or you can manage the services directly from Codenvy if you like.
33) In order to remove the service you can go to AppFog and do it from their interface.
I hope you enjoyed the tutorial! If you find it useful share, comment and like.
Have fun! :)