使用XAMPP和PEAR进行设置后找不到AWS SDK

I'm trying to set up the AWS SDK for PHP on an EC2 instance, but I am having trouble getting the SDK to work. Just to note, I'm new to all AWS services, and I've only written PHP scripts, I've never configured it before. When I run the following script, I get "Fatal error: Class 'AmazonEC2' not found in /opt/lampp/htdocs/index.php on line 6":

require_once 'sdk.class.php';
$ec2 = new AmazonEC2(); //Line 6

As far as I can tell, the AmazonEC2 class is in:

/opt/lampp/lib/php/AWSSDKforPHP/services/ec2.class.php

I followed this setup guide: http://aws.amazon.com/articles/PHP/4261

Here are some details:

  • EC2 Instance: t1.Micro node of Basic 32-bit Amazon Linux AMI 2010.11.1 Beta (AMI Id: ami-76f0061f)
  • PHP is set up using XAMPP. Basically untar into /opt/lampp, where it is self contained.
  • SDK installed using PEAR. Done with:
    • sudo /opt/lampp/bin/pear channel-discover pear.amazonwebservices.com
    • sudo /opt/lampp/bin/pear install aws/sdk

My path was set to ".:/opt/lampp/lib/php" by default. I tried adding ".:/opt/lampp/lib/php/AWSSDKforPHP" but that didn't work. I tried changing file permissions, but no dice.

I've never used PEAR before, or XAMPP. Any ideas for how I can get the SDK working with PHP? I'm thinking it has to be just an include_path issue, but I'm not sure what to set it to work. (I reset apache after I change php.ini so that isn't the issue either).

Here are some paths on my system:

/opt/lampp/lib/php/AWSSDKforPHP
/opt/lampp/etc/php.ini
/opt/lampp/htdocs/index.php
/home/ec2-user/.aws/sdk/config.inc.php

Have you updated your PHP's include_path in php.ini?

Edit: On second look, it appears you did. Have you tried including the services/ec2.class.php file in the script you're trying to run?

You most likely need to either add the 'services' folder to your path or require the class this way:

require_once('services/ec2.class.php');

I found your identical AWS forum thread while searching for a possible answer: https://forums.aws.amazon.com/thread.jspa?threadID=59213

Have you tried NOT using PEAR? They also provide installation via git and a downloadable .zip file. In my experience, PEAR can be bitchy and unreliable at times. I certainly wouldn't recommend it to people new to PHP or the CLI.

I had a similar problem earlier. In my case, sdk.class.php was in a different folder where I had included.

So you might want to check the path for where sdk.class is, probably create your own .php file there with a couple of functions, require_once them and confirm if you are accessing right path.

Kind of an old thread...meh.

I had the same problem, but with using WAMP on Windows and using Amazon S3 instead of EC2. Adding the following include solved my problem:

require_once 'AWSSDKforPHP/sdk.class.php';

Including "AWSSDKforPHP/services/s3.class.php", along the lines of what others have suggested, just threw more errors for other missing classes.

I think PEAR does this automatically, but also check to make sure the PEAR folder is in the "include_path" setting of your php.ini file:

include_path=".;C:\Program Files\wamp\bin\php\php5.2.11\pear"