Amy Neville Amy Neville - 1 year ago 119
PHP Question

Composer.json Installation On AWS Elastic Beanstalk

I read in the AWS Elastic Beanstalk documentation that you can simply include the composer.json file in the root of your package and it will install an application and it's dependencies:

"require": {
"coinbase/coinbase": "~2.0"

Then I created a PHP file with the following to test if it worked:

ini_set('display_errors', 1);

$apiKey = 'workingkey';

$apiSecret = 'workingkey';

use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;

$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);

$buyPrice = $client->getBuyPrice('BTC-USD');

echo $buyPrice;

Unfortunately it gives the following error:

Fatal error: Uncaught Error: Class 'Coinbase\Wallet\Configuration' not found in /var/app/current/test.php:20 Stack trace: #0 {main} thrown in /var/app/current/test.php on line 20

I've tried everything I can think of to get this to work. What am I missing here?

Answer Source

You missed to include the autoloader of composer.

Add this at the beginning of your file and it should work:

require __DIR__.'/vendor/autoload.php';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download