简体   繁体   中英

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.

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:

Warning: require(/home/ec2-user/vendor/autoload.php): failed to open stream: Permission denied in /var/www/html/index.php on line 12

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

Line 12 is simply:

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
  2. Copy all composer components under www root
  3. Change ownership of composer components to apache
  4. If you are using an ini file for the AWS credentials, place it under /.aws (under the root folder)

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. 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. In the example above i placed composer in its own folder so the reference would be:

require 'composer/vendor/autoload.php';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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