Prerequisites :-
- An IBM Bluemix Account.
- Cloud Foundary CLI application
To Do First :
- 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).
- 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 |
- 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 |
- If everything goes well and you are logged in, then you will see a screen like below :
|
Logged in - techripper.in |
- Congrats, you are done. If not, repeat the same procedure until you are not done.
Creating ClearDB MySQL Database Service
- Enter the given command to create a clearDB MySQL service
cf create-service cleardb spark your-service-name-here
- Replace your-service-name-here with the name you like.
- Here you go , if everything goes fine , you’ll see a screen as below :
|
Creating ClearDB MySql Service - Techripper.in |
- Congrats , you are done.
Deploying Your PHP Application
- In your PHP application, replace your database connectivity part by following code and connect to database by using following variables :-
$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"];
- Now, create a new folder where your Cloud Foundry CLI application is installed name “ myphpapp ”.
- Open this folder. Create a new file manifest.yml using any text editor.
- Add following contents to it.
|
Application properties - Techripper.in |
- Replace myphpapp with the name of your application in both cases i.e. host and name.
- Change values for disk_quota and memory if required.
- Replace “ cleardb-mysql “ with the name you gave to your database service above.
- 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.
- Now , save this file.
- 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.
- In CMD, type “ cd myphpapp “ to enter your project directory then “ cf push ”.
- If everything goes OK , then you are done . Congrats.
Comments
Post a Comment