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

<p><code>sudo ufw allow 8332</code></p>

<p>Easybitcoin library uses <code>cURL</code>, and it's not always enabled or installed by default.</p>

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

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

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

<p>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.</p>

CC BY-SA 3.0
2017-01-28T16:45:38.147Z
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.
Sven Williamson
CC BY-SA 3.0
2017-01-28T17:23:12.650Z
Use something like XAMPP, if you want to run PHP locally on your machine.
m1xolyd1an
CC BY-SA 3.0
2017-01-30T00:17:34.593Z
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
Carlos De la Garza
CC BY-SA 3.0
2017-01-30T03:37:34.793Z
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
CC BY-SA 3.0
2017-02-02T03:27:43.593Z
I'm running Bitcoin Core with `daemon=1` specified on my bitcoin.conf file. And works fine with localhost too.
Carlos De la Garza
CC BY-SA 3.0
2017-01-28T16:00:44.257Z
2017-01-28T16:00:44.257Z
m1xolyd1an
<p>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</p>

<p>I'm using easybitcoin.php JSON from <a href="http://github.com/aceat64/EasyBitcoin-PHP/" rel="nofollow noreferrer">Github</a>.</p>

<p>I'm trying with this JSON RPC call:</p>

<pre><code>require_once('easybitcoin.php');
    $bitcoin = new Bitcoin('myusername','mypassword','myip','8332');
    $bitcoin-&gt;getinfo();
</code></pre>

<h3>My bitcoin.conf file has:</h3>

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

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

<p>What I'm doing wrong?</p>

CC BY-SA 3.0
2017-01-28T06:36:14.483Z
Do you mind pasting the error message?
Nick ODell
CC BY-SA 3.0
2017-01-28T09:24:34.577Z
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`)
Sven Williamson
<bitcoind><api><json-rpc><php>
JSON RPC call from webpage to Bitcoin Core
Carlos De la Garza
# JSON RPC call from webpage to Bitcoin Core

(Asked by: username_0 on 2017-01-28)

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](http://github.com/aceat64/EasyBitcoin-PHP/).

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?

**Tags:** bitcoind, api, json-rpc, php

> **Comments:**
> **username_1**: Do you mind pasting the error message?  
> **username_2**: 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`)  

---

## 1 answers

### Answer by username_3 on 2017-01-28. Score: 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.

> **Comments:**
> **username_2**: 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.  
> **username_3**: Use something like XAMPP, if you want to run PHP locally on your machine.  
> **username_0**: 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  
> **username_3**: 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?  
> **username_0**: I'm running Bitcoin Core with `daemon=1` specified on my bitcoin.conf file. And works fine with localhost too.  

---

