Wednesday, 28 August 2013

Using multiple heroku accounts

Managing multiple heroku accounts can be difficult as each account requires a unique ssh key ,

To generate unique ssh key for each account use the following steps:
1. create a ssh key by  $ssh-keygen -t rsa -C "youremailid@provider.com" -f  ~/.ssh/unique_name

here youremailid@provider.com is the email id used for heroku account 

you may be asked to enter a passphrase , passphrase is something like a password for the ssh key.

2.Add this key to your server by    $ ssh-add ~/.ssh/unique_name

3. Login to your heroku 

4. then  use,  $ heroku  keys:add 

It will then indicate the list of keys available in the system, as

Found the following SSH public keys:
1) xxxx.pub
2) xxxx.pub
etc
select by indicating the number 1 or 2

You are done.


Now you have authenticated the email id. To allow usage git repository from your system create a new user by $adduser username
and provide a password for the same.

switch to the new user by $su username

then create a ssh key by  $ ssh-keygen -t rsa   


once the key is created , get the public key by using $ cat /path/.ssh/id_rsa.pub

login to your heroku account from a browser and click account, its top left beside the gravatar.

in your account you have an option to add ssh key, copy paste the key generated there.


Once done, whenever you want to push your git repo to heroku thats before $git push heroku master

switch user $su username

then try pushing it . Thus you can manage multiple account wherin a new user for different email is needed.

BubbleFeeds facebook application

Check out bubblefeeds app on facebook.

The application was built using php and d3.js and is hosted on heroku .; d3.js allows document manipulation based on data.

The application is aimed to declutter the wall as in ,it allows the user to select the friend whose wall the user wishes to see.The application will then display all the posts in the friends wall by bubbles , the color of each determined by the type of the post and the dimension determined by number of likes which depicts the popularity of the post


each bubble is a clickable link which takes the user to the post.


The legend to understand the bubble :

Wednesday, 21 August 2013

Using database on heroku

Heroku allows applications to be hosted which need database. Either mysql or postgresql can be used, it is easier to host an application which uses postgres hence we shall be using the same.

To use postgresql you may want to check this .

After logging in to your heroku account in the terminal (check this) add an addon for the current app by
using $ heroku addons:add heroku-postgresql:dev

Then login to your account and check the app, your database can be observed  here.


You can then use the host,database,user and password information in your application to access the tables in the database.

use $ su postgresql_username

to login to postgresql .

Then to access the remote database on heroku , use
$ psql -h host -U user database

(note: here host,user and database implies those indicated in the image or the details from here.)


Now you are logged in. you can now enter create table etc sql commands to be executed on the remote server.
The table can then be accessed in the application.But note that the database in psql and not mysql.


if your app is using mysql, then convert mysql to psql replace the following set of instructions:

mysql_connect to pg_connect
mysql_query to pg_query
mysql_fetch_row to pg_fetch_row

and so on.

Installing phppgadmin and configuring it with postgresql in linux

phppgadmin can be used for developing application which uses psql for database.

Lets begin :

1.install postgresql  by  $ sudo apt-get install postgresql

2. install phppgadmin by $ sudo apt-get install phppgadmin

3. Create a user for postgresql by $ sudo -u postgres createuser -d -r -P username
then enter password for the user created.

4.make apache acknowledge postgresql as a database server by editing the conf file of apache
$sudo gedit '/etc/apache2/apache2.conf'  
and add this in a new line  at the end                   Include /etc/phppgadmin/apache.conf  

5.Restart apache2 server by  $ sudo /etc/init.d/apache2 restart

6. If localhost/phppgadmin throws up 404  then configure postgresql by
editing the conf file  $ sudo gedit /etc/postgresql/9.1/main/postgresql.conf

and add this at the end of file in a new line           listen_addresses = 'localhost'

7. now edit  pg_hba.conf by $ sudo vi /etc/postgresql/9.1/main/pg_hba.conf

Replace         local all all ident sameuser            with              local   all         all                               md5

That would be it.

you can also access postgres by  $ sudo -u postgres psql username

Saturday, 17 August 2013

PHP on Heroku

Heroku allows you to host your php applications free of cost , until your user base increases . This is hence a good place to host ,if you are testing out your application in the market.

Heroku requires GIT which is version control tool, which allows you to track changes you have made to your code.

Lets begin,

Install GIT

Linux users can try the   $sudo apt get install git


You also need to have a Heroku account ,go here


Then install the heroku toolbelt , its a command line interface to upload codes onto heroku; For this go here.  Linux users can  do so by running

$wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh



login to your heroku account from the terminal by
$ heroku login





Go to the directory/folder where you have developed your php application.
Then run   $ git init


This creates a new subdirectory named .git that contains all of your necessary repository files — a Git repository skeleton


You can add all the content in the directory to the git repository by
$ git add .


Once done , commit it by
$ git commit -m "message"




Then run  $ heroku create  . First time users will be asked to add a key, verify the rsa key, the key for git being  16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48


Push the commited code to heroku by
$ git push heroku master




Then run      $heroku open   



It should open up your php application in the default browser !!!





Note , If you make any changes in your code later on, just commit it by 'git commit'  and push it to heroku by 'git push heroku master'