简体   繁体   English

Amazon Server EC2上的Composer-自动加载不起作用

[英]Composer on Amazon Server ec2 - autoload not working

I configured an Amazon Cloud server, installed php, apache, etc. Then installed composer and ran $php composer.phar and its working. 我配置了一个Amazon Cloud服务器,安装了php,apache等。然后安装了composer并运行$php composer.phar及其工作程序。

But when I tried to include the vendor/autoload.php file (which I can clearly see on the server), I get this warning and fatal error because it can't seem to find the file: 但是,当我尝试包含vendor / autoload.php文件(可以在服务器上清楚看到)时,由于出现了找不到文件的提示,因此收到此警告和致命错误:

Warning: require(/home/ec2-user/vendor/autoload.php): failed to open stream: Permission denied in /var/www/html/index.php on line 12 警告:require(/home/ec2-user/vendor/autoload.php):无法打开流:在第12行的/var/www/html/index.php中,权限被拒绝

Fatal error: require(): Failed opening required '/home/ec2-user/vendor/autoload.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/index.php on line 12 致命错误:require():无法在/ var / www中打开所需的'/home/ec2-user/vendor/autoload.php'(include_path ='。:/ usr / share / pear:/ usr / share / php') /html/index.php,第12行

Line 12 is simply: 第12行只是:

require "/home/ec2-user/vendor/autoload.php";

Does anybody know what is causing this error or anything that would help eliminate the error? 是否有人知道导致此错误的原因或任何有助于消除该错误的因素? Thanks. 谢谢。

I had the same problem, here are the steps i followed to solve it: 我遇到了同样的问题,下面是解决该问题的步骤:

  1. Install composer as described in: https://docs.aws.amazon.com/aws-sdk-php/v3/guide/getting-started/installation.html 按照以下说明安装Composer: https : //docs.aws.amazon.com/aws-sdk-php/v3/guide/getting-started/installation.html
  2. Copy all composer components under www root 将所有Composer组件复制到www根目录下
  3. Change ownership of composer components to apache 将作曲者组件的所有权更改为Apache
  4. If you are using an ini file for the AWS credentials, place it under /.aws (under the root folder) 如果您将ini文件用于AWS凭证,请将其放在/.aws下(根文件夹下)

Here are the steps: 步骤如下:

cd ~
mkdir composer
cd composer
curl -sS https://getcomposer.org/installer | php
php composer.phar require aws/aws-sdk-php
sudo cp -r ~/composer /var/www/html
sudo chown -R apache:apache /var/www/html/composer
sudo mkdir /.aws

Don't forget to copy the credentials file to ./aws. 不要忘记将凭据文件复制到./aws。 You can also restrict read access to the credentials file to apace only: 您还可以将对凭据文件的读取访问限制为仅快速:

sudo chown apahce:apache ./aws/credentials
sudo chmod 440 ./aws/credentials

Finally, update the required statement in the php file. 最后,更新php文件中的所需语句。 In the example above i placed composer in its own folder so the reference would be: 在上面的示例中,我将composer放置在其自己的文件夹中,因此引用为:

require 'composer/vendor/autoload.php';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM