Showing posts with label mysql. Show all posts
Showing posts with label mysql. Show all posts

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.

Monday, June 9, 2014

Does BlueMix support Spring?

Before Write this topic,I got news for IBM site,the commercial BlueMix will be release at the end of June. Most service IBM provided are free of charge,you only need pay what use part of runtime enviroment fee.

 The Spring Framework is an open source application framework and inversion of control container for the Java platform. The framework's core features can be used by any Java application, but there are extensions for building web applications on top of the Java EE platform.Spring helps development teams everywhere build simple, portable,fast and flexible JVM-based systems and applications.

In order to demo the ability of the BlueMix ability we use the project on github.You can download it from https://github.com/cloudfoundry-samples/spring-hello-env.
After download the package and unzip it and you should see the below strcture.
 Since it provide  a project object model (POM) xml file, we can use Maven to manage a project's build, reporting and documentation from a central piece of information. You can use maven to build the project .
You can use mvn package under the project strcutre.
It will generate hello-spring-env.war.So you can use cf command tool to publish this to the BlueMix,
For example we can use below command to push your app to the BlueMix.We bing a mysql service to our app,so the env will include the mysql service.
cf create-service mysql 100 mysql_NMU
cf p SpringSample -p hello-spring-env.war
cf bind-service SpringSample mysql_NMU

After deployment,you can see the result through the below url.You can mysql service is in the VCAP_SERVICE.
Also we can deploy the app in the eclipse,I left a eclipse strctrue for your reference.We can use cloundry plug-in to deploy it to the BlueMix side.