rpc call using php command shell_exec

0 votes

hi guys,

we've been trying to issue cli commands using php command shell_exec.

it's been failing with this error:

error: You must set rpcpassword=<password> in the configuration file:
/.multichain/chain1/multichain.conf
If the file does not exist, create it with owner-readable-only file permissions.

substituting a command like "date" it works fine; and we can execute cli commands using the command line and python scripts.  all of this is on the same multichain peer.

is there an additional parameter we need to take into account?

thanks,

santosh

asked Nov 12, 2015 by santosh

1 Answer

0 votes

Are you using PHP within a web server, or running PHP code on the command line?

If within a web server, the problem is that the PHP code runs under the user of the web server (e.g. apache or httpd) and this is not the same user that you have used to create the blockchain. So the ~/.multichain/ directory points to a completely different place for that user.

You should not have a problem if you're running PHP on the command line, but please let me know if I'm wrong.

And if you want to run it from the web server, make sure the blockchain directory and multichain.conf file are readable for the user which the web server is running under, then use the -datadir option with multichain-cli to choose the appropriate directory for the chain you want to use.

answered Nov 12, 2015 by MultiChain
thanks for getting back to me.
we are using php within a web server; got the problem sorted by adding the php user to sudoers and then calling the cli command using sudo -u
...