How to deploy a web application on IBM Bluemix using cloud foundry CLI

Prerequisites :- 

  • An IBM Bluemix Account.
  • Cloud Foundary CLI application

To Do First :

  1. Open Command Prompt. Go to the path where your Cloud Foundry CLI application is installed (Or you can add it in system variables for faster access for next time).
  2. Now, type in " cf login ". You would get following screen. Enter your E-Mail Id associated with Bluemix account and your password.
    Login via Cloud Foundry CLI - Techripper.in
  3. Then it will ask you to select a space via a menu driven interface as follows. Select the desired space and press enter.
    Select Space - Techripper.in
  4. If everything goes well and you are logged in, then you will see a screen like below :
    Logged in - techripper.in
  5. Congrats, you are done. If not, repeat the same procedure until you are not done.

Creating ClearDB MySQL Database Service

  1. Enter the given command to create a clearDB MySQL service
    cf create-service cleardb spark your-service-name-here
  2. Replace your-service-name-here with the name you like.
  3. Here you go , if everything goes fine , you’ll see a screen as below :
    Creating ClearDB MySql Service - Techripper.in
  4. Congrats , you are done.

Deploying Your PHP Application

  1. In your PHP application, replace your database connectivity part by following code and  connect to database by using following variables :-
  2. $services = getenv("VCAP_SERVICES");
    $services_json = json_decode($services,true);
    $mysql_config = $services_json["cleardb"][0]["credentials"];
    $dbname = $mysql_config["name"];
    $servername = $mysql_config["hostname"].':'.$mysql_config["port"];
    $username = $mysql_config["username"];
    $password = $mysql_config["password"];
    
  3. Now, create a new folder where your Cloud Foundry CLI application is installed name “ myphpapp ”.
  4. Open this folder. Create a new file manifest.yml using any text editor.
  5. Add following contents to it.
    Application properties - Techripper.in
  6. Replace myphpapp with the name of your application in both cases i.e. host and name.
  7. Change values for disk_quota and memory if required.
  8. Replace “ cleardb-mysql “  with the name you gave to your database service above.
  9. Note - Do not remove the hyphen(-) appended in front of your database service name , because its basically a list of services binded to your application and when you’ll try to push your app without that hyphen , you will receive error.
  10. Now , save this file.
  11. Add all your PHP project files in the same folder. Note that your project should not be in any subdirectory. Your “ index.php “ should appear in “ myphpapp ” folder or whatever the named folder you create.
  12. In CMD, type “ cd myphpapp “ to enter your project directory then “ cf push ”.
  13. If everything goes OK , then you are done . Congrats.

Comments

Popular Posts