使用 XAMPP 和 PEAR 设置后未找到 AWS SDK
我尝试在 EC2 实例上设置适用于 PHP 的 AWS 开发工具包,但无法让该开发工具包正常工作。请注意,我对所有 AWS 服务都是新手,而且我只编写过 PHP 脚本,以前从未配置过它。当我运行以下脚本时,我收到“致命错误:在第 6 行的 /opt/lampp/htdocs/index.php 中找不到类 'AmazonEC2'”
require_once 'sdk.class.php';
$ec2 = new AmazonEC2(); //Line 6
:据我所知,AmazonEC2 类位于:
/opt/lampp/lib/php/AWSSDKforPHP/services/ec2.class.php
我遵循了此设置指南: http://aws .amazon.com/articles/PHP/4261
以下是一些详细信息:
- EC2 实例:t1.
Basic 32 位 Amazon Linux AMI 2010.11.1 Beta 的微节点(AMI Id:ami-76f0061f)< /code>
- PHP 是使用 XAMPP 设置的。基本上解压到 /opt/lampp 中,它是独立的。
- 使用 PEAR 安装 SDK。完成:
- sudo /opt/lampp/bin/pear 频道发现 pear.amazonwebservices.com
- sudo /opt/lampp/bin/pear 安装 aws/sdk
我的路径设置为“.:/opt/lampp/lib/php “ 默认情况下。我尝试添加“.:/opt/lampp/lib/php/AWSSDKforPHP”,但这不起作用。我尝试更改文件权限,但没有成功。
我以前从未使用过 PEAR 或 XAMPP。关于如何让 SDK 与 PHP 配合使用,有什么想法吗?我认为这一定只是一个 include_path 问题,但我不确定如何设置它才能工作。 (我在更改 php.ini 后重置了 apache,所以这也不是问题)。
以下是我的系统上的一些路径:
/opt/lampp/lib/php/AWSSDKforPHP
/opt/lampp/etc/php.ini
/opt/lampp/htdocs/index.php
/home/ec2-user/.aws/sdk/config.inc.php
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
有点旧线程...嗯。
我遇到了同样的问题,但是在 Windows 上使用 WAMP 并使用 Amazon S3 而不是 EC2。添加以下内容解决了我的问题:
包括“AWSSDKforPHP/services/s3.class.php”,按照其他人的建议,只是为其他缺失的类引发了更多错误。
我认为 PEAR 会自动执行此操作,但还要检查以确保 PEAR 文件夹位于 php.ini 文件的“include_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:
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:
我在搜索可能的答案时发现了与您相同的 AWS 论坛主题: https://forums .aws.amazon.com/thread.jspa?threadID=59213
您是否尝试过不使用 PEAR?他们还提供通过 git 的安装和可下载的 .zip 文件。根据我的经验,PEAR 有时可能很恶毒且不可靠。我当然不会向 PHP 或 CLI 新手推荐它。
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.
您是否在 php 中更新了 PHP 的 include_path ? ini?
编辑:再看一遍,你似乎做到了。您是否尝试过将
services/ec2.class.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?您很可能需要将“services”文件夹添加到您的路径中或以这种方式需要该类:
You most likely need to either add the 'services' folder to your path or require the class this way:
我之前也遇到过类似的问题。
就我而言,sdk.class.php 位于我包含的另一个文件夹中。
所以你可能想检查 sdk.class 所在的路径,
可能会在那里创建您自己的 .php 文件,其中包含几个函数, require_once 它们并确认您是否正在访问正确的路径。
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.