Saturday, June 14, 2014

Manage MySql,PostgreSQL on the BlueMix

Actually BlueMix don;t provide the solution to operate   db like mysql,mongodb,PostgreSQL etc on the web UI.When people develop their application usually will create db or insert data for these open source db on the BlueMix.So we need a solution to manage these db on the BlueMix.I have already discussed about to maintain mongodb on the BlueMix in the previous post.Today I will talked about how to use manage mysql on the BlueMix.

Deploy phpMyAdmin on BlueMix

phpMyAdmin is a free software tool written in php, intended to handle the administration of MySQl over the Web. phpMyAdmin supports a wide range of operations on MySQL, MariaDB and Drizzle. Frequently used operations (managing databases, tables, columns, relations, indexes, users, permissions, etc) can be performed via the user interface, while you still have the ability to directly execute any SQL statement.

In the BlueMix category,we don;t have php runtime support that.So we will use php buildback to support that.I list the most import steps for you .

1.Since we need to use cf tool to deploy on the BlueMix,you need to download and install it from github.
https://github.com/cloudfoundry/cli

2.We use cf command or web console to create our mysql service.Before create the service,make sure you have use cf login -a api.ng.bluemix.net command to login into it.
create the MySQL service that the application will use. The command syntax is:

cf create-service SERVICE PLAN SERVICE_INSTANCE​

The service name is mysql, the plan is 100, and the service instance name is mysql_NMU. So you'll create your MySQL service like this:

cf create-service mysql 100 mysql_NMU

Here I create mysql service name is called mysql_NMU

3.The next step you need to download or clone the phpMyAdmin package from github from below address
https://github.com/dmikusa-pivotal/cf-ex-phpmyadmin
4.After you donwoload the installation package and open the htdocs\config.inc.php file.
Located the line 28,change 'cleardb-n/a' to 'mysql-5.5' .Below is the code after change.

/*
 * Read MySQL service properties from _ENV['VCAP_SERVICES']
 */
$services = json_decode($_ENV['VCAP_SERVICES'], true);
$service = $services['mysql-5.5'][0]; // pick the first service

4. Since we don;t want use the manifest.yml shipped in the default file,so we can use below command to push on the BlueMix.

cf push phpmyadminbluemix -b https://github.com/dmikusa-pivotal/cf-php-build-pack.git -m 128M --no-manifest --no-start

Bind previous created mysql service
cf bind-service phpmyadminbluemix  mysql_NMU

The we can start our application use below command

 cf start phpmyadminbluemix

5.After start the app,we need to use mysql credential to login into it.You can double click the application,click the runtime menu and find user name and password from Environment Variables.

6.Launch the url from the http://phpmyadminbluemix.mybluemix.net/,you can see below login screenshot.

7.Use the username and password provide by step5,you can login into it and maintain the mysql on the Cloud.


Deploy WebSQL on the BlueMix

WebSQL is the ultimate desktop replacement for managing your MySQL databases over the web. With interface that works just like your favourite desktop applications, you don't need to keep switching over webpages to get simple things done. Just login to your database and manage your database as if your are working on your desktop.It support MySQL, SQLite and PostgreSQL three dbs.

You can download the latest package from http://sourceforge.net/projects/mywebsql/files/stable/mywebsql-3.4.zip/download.

Deploy on the BlueMix for this php based application i same with phpMyAdmin.So I don't want to repeat the same steps here.But one place you might need to change on you side.Open the servers.php in the config foler.Change the code like below.If you want to manage PostgreSQL you can uncomment the line ,and comment mysql serice line for that.
/*
* Read MySQL service properties from _ENV['VCAP_SERVICES']
*/
$services = json_decode($_ENV['VCAP_SERVICES'], true);
$service = $services['mysql-5.5'][0]; // if you choose  the mysql service
       //$service = $services['postgresql-9.1'][0];//if use choose the postgresql-9.1
$host = $service['credentials']['hostname'];
$port=$service['credentials']['port'];

$SERVER_LIST = array(
'MySQL'           => array(
                            'host'     => $host. ':' . $port,
                            'driver'   => 'mysql5'
                        )
/* 'Localhost PostgreSQL'     => array(
                            'host'     =>$host. ':' . $port,
                            'driver'   => 'pgsql'
                       ),
*/
);

If your deployment on BlueMix is successful,you should see below screenshot.


So from below two apps deployment guide ,you can try similar solution with me to support other db on BlueMix.

4 comments:

  1. Thanks for the post. However when I run cf push I get a Server 500 error. I run OS X. Any ideas why this is happening?

    ReplyDelete
  2. This post helped me a lot. Thank you very much.

    ReplyDelete
  3. I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in TECHNOLOGY , kindly contact us http://www.maxmunus.com/contact
    MaxMunus Offer World Class Virtual Instructor led training on TECHNOLOGY. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us.
    Sangita Mohanty
    MaxMunus
    E-mail: sangita@maxmunus.com
    Skype id: training_maxmunus
    Ph:(0) 9738075708 / 080 - 41103383
    http://www.maxmunus.com/

    ReplyDelete
  4. Wonderful bloggers like yourself who would positively reply encouraged me to be more open and engaging in commenting.So know it's helpful.
    PHP Training in Chennai

    ReplyDelete