Bitcoin Forum
May 27, 2022, 11:14:43 PM *
News: Bitcoin Pizza bake-off contest
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [Step by step] Integrating Bitcoin Daemon with PHP  (Read 7635 times)
Shahrukh
Full Member
***
Offline Offline

Activity: 154
Merit: 100


View Profile WWW
January 12, 2014, 05:37:12 PM
 #1

Hey there ! Howdy?

Ok I was searching for tutorials all over internet on "how to integrate bitcoin daemon with php" I came up with many and none of them helped me to get it working flawlessly, some of them threw unexpected and strange errors after 90% completion and some of them good enough to throw error in starting only which saved my time and efforts. Now that I have done what I was looking for why not create a step by step tutorial to help fellow members. So let's get started.


Before we start you should install tmux which helps you save your work even if you are disconnected from the vps. To install tmux:

Code:
sudo apt-get install tmux

to start tmux simply type tmux and to get back on mai screen press ctrl b and then d to restore the session again type tmux attach.


I am expecting you have a Ubuntu 12.x or later because that is what i used for installation. Log in to your VPS or your computer's terminal and install python software properties by typing following command :

Code:
sudo apt-get install python-software-properties

then add repository ppa:bitcoin/bitcoin by typing following command

Code:
sudo add-apt-repository ppa:bitcoin/bitcoin

In my case this didn't work and threw an error stating that add-apt-repository command not found. In ubuntu later version versions this command is not found under python-software-properties package, like in previous versions, but available in software-properties-common. So I had installed it by running these commands :

Code:
sudo aptitude install software-properties-common

To find in which package the command we are looking for exists the following will be of help:

Code:
sudo apt-fille update


Unfortunately in my case this was also not installed so I had installed it by running following command :

Code:
apt-get install apt-file

Now I got the message "The file is up to date"

Now run
Code:
sudo apt-file search add-apt-repository

You will be prompted to confirm this installation, press Enter key to confirm.

Now run

Code:
sudo aptitude update

and then
Code:
sudo aptitude install bitcoind

Make a new directory by typing :

Code:
mkdir ~/.bitcoin
cd ~/.bitcoin

Create a new file inside this directory named bitcoin.conf by typing:
Code:
nano bitcoin.conf

insert the following code in the text file:

Code:
server=1
daemon=1
rpcuser=any_username
rpcpassword=any_password

Exit by pressing ctrl+x to confirm the changes press Y and then press return key. Start the bitcoin daemon by typing:
Code:
bitcoind

Bitcoin daemon is now installed and runing you can check it by running the following command
Code:
bitcoind getinfo

Now we will install apache and php on our server

To install apache we will run th following code:

Code:
sudo apt-get install apache2

once apache is installed verify it by typing your ip address in the browser it will say It works!

now we will install php by following command:

Code:
sudo apt-get install php5 libapache2-mod-php5

now navigate to var/www folder and download jsonRPCClient.php with the following command:

Code:
wget http://pmtocoins.com/JSON-RPC_PHP_light.zip

once downloaded unzip it by typing:
Code:
unzip JSON*.zip

no move to the directory by:
Code:
cd json*/includes

and move jsonRPCClient.php into your www folder

now create a new index.php file in www folder with following code

Code:

<?php
include_once('jsonRPCClient.php');
$bitcoin = new jsonRPCClient('http://your_username:your_password@127.0.0.1:8332/');
print_r($bitcoin->getinfo());
?>



and you are done navigate to your ip address on the browser e.g http://123.123.123.123/index.php and hurray


You can have a look on API call list here : https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list


I turned everyone down Sad Sorry for that
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1653693283
Hero Member
*
Offline Offline

Posts: 1653693283

View Profile Personal Message (Offline)

Ignore
1653693283
Reply with quote  #2

1653693283
Report to moderator
1653693283
Hero Member
*
Offline Offline

Posts: 1653693283

View Profile Personal Message (Offline)

Ignore
1653693283
Reply with quote  #2

1653693283
Report to moderator
Shahrukh
Full Member
***
Offline Offline

Activity: 154
Merit: 100


View Profile WWW
January 22, 2014, 08:50:55 PM
 #2

Bump

I turned everyone down Sad Sorry for that
Altoidnerd
Sr. Member
****
Offline Offline

Activity: 406
Merit: 251


http://altoidnerd.com


View Profile WWW
January 24, 2014, 02:10:55 PM
 #3

I'll bump it. 

Do you even mine?
http://altoidnerd.com 
12gKRdrz7yy7erg5apUvSRGemypTUvBRuJ
cr1776
Legendary
*
Offline Offline

Activity: 3346
Merit: 1220


View Profile
January 24, 2014, 03:41:26 PM
 #4

I'm sure this will be useful to many people going forward!
Dumbo
Member
**
Offline Offline

Activity: 114
Merit: 10


View Profile
January 24, 2014, 08:37:14 PM
 #5

Thanks sharukh! This just saved me a lot of time.
flangefrog
Newbie
*
Offline Offline

Activity: 56
Merit: 0


View Profile WWW
January 28, 2014, 10:56:22 AM
 #6

Nice tutorial. Thanks.
Sharrow
Member
**
Offline Offline

Activity: 66
Merit: 10


View Profile
January 28, 2014, 09:01:35 PM
 #7

I was looking for info like this a few days ago and it was hard piecing it together from scratch. This tutorial brings it all together... thank you so much!!!
kumarz
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
May 01, 2014, 03:30:46 PM
 #8

bump! ... legendary stuff cheers
kittucrypt
Sr. Member
****
Offline Offline

Activity: 300
Merit: 253

Ok Check!


View Profile
May 01, 2014, 03:32:00 PM
 #9

This is good stuff to know.

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!