4

I want to make API calls to my Bitcoin Core wallet from my webpage but when I try to connect it gives me Internal Server Error

I'm using easybitcoin.php JSON from Github.

I'm trying with this JSON RPC call:

require_once('easybitcoin.php');
    $bitcoin = new Bitcoin('myusername','mypassword','myip','8332');
    $bitcoin->getinfo();

My bitcoin.conf file has:

  • listen=1
  • maxconnections=15
  • server=1
  • daemon=1
  • rpcuser=myusername
  • rpcpassword=mypassword
  • rpcclienttimeout=60
  • rpcport=8332
  • rpcallowip=0.0.0.0/0 (Before I put my IP address here but it didn't solve too)

When I use bitcoin-cli.exe client to send commands to my Bitcoin Core server via 127.0.0.1 (localhost) it works perfectly.

What I'm doing wrong?

2
  • Do you mind pasting the error message?
    – Nick ODell
    Jan 28, 2017 at 6:36
  • For what it's worth, your code works perfectly for me on the bitcoind host with myip=localhost or with myip=127.0.0.1. It also works from a separate host on local network with myip=192.168.0.xx provided I set up my Linux firewall ufw to allow connection to port 8332 on the bitcoind host, and provided I have rpcallowip=0.0.0.0/0 on my bitcoind config file (and remember to restart bitcoind after updating config file). I suggest you use var_dump($bitcoin->getinfo()); so you can really see if it is working (you may have failures without exception being thrown returning false) Jan 28, 2017 at 9:24

1 Answer 1

1

Make sure your 8332 port is open using ufw. Some VPS providers only have very few open by default for security. Digitalocean, for example doesn't have it open by default anymore.

sudo ufw allow 8332

Easybitcoin library uses cURL, and it's not always enabled or installed by default.

With PHP 5, you can easily install it by running apt-get install php5-curl command. With PHP7, sudo apt-get install php-curl

Once installed make sure its enabled. Locate your php.ini file and uncomment ;extension=php_curl.dll this line by removing ;(semi colon).

Run a test page with phpinfo(); and make sure curl is installed and enabled. Restart Apache, sudo service apache2 restart.

If you still can't get it to work go back to your php.ini file and turn on all error reporting and let us know what the error is. Be sure you turn the error messages off again before you go live.

5
  • Once I have it running as php script on terminal window, having also apache2 running (with default index.html page), how do I quickly make my php run on firefox from localhost. I tried introducing `<?php echo 'This is php' ?> in my html but it seems I need more than that. Don't worry if too long to explain, I will study web programming at some point. Jan 28, 2017 at 16:45
  • Use something like XAMPP, if you want to run PHP locally on your machine.
    – m1xolyd1an
    Jan 28, 2017 at 17:23
  • I have instaled Curl on my webserver curl, when I do a simply curl request from my server it gives me error like: (7) Failed to connect to 187.223.x.x port 8332: Connection refused Jan 30, 2017 at 0:17
  • Ok I was able to recreate this same error message when my node is not running, or when I run the bitcoin core GUI client. It works fine when I run bitcoind. I assume you're running bitcoind?
    – m1xolyd1an
    Jan 30, 2017 at 3:37
  • I'm running Bitcoin Core with daemon=1 specified on my bitcoin.conf file. And works fine with localhost too. Feb 2, 2017 at 3:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.