Skip to content
Advertisement

EC2 User Access or File Access Problems?

I’ve been having some issues using an EC2 instance when I try and call CLI commands. I am using Laravel but I cant quite be sure if it is a Laravel issue or EC2.

When I ssh into my EC2 instance, I run the following laravel command to migrate my database:

php artisan migrate

And I get the following error:

PHP Fatal error: Uncaught exception ‘UnexpectedValueException’ with message ‘The stream or file “/var/app/current/storage/logs/laravel.log” could not be opened: failed to open stream: Permission denied’ in /var/app/current/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107

I then run sudo php artisan migrate and get a totally different error:

[PDOException] SQLSTATE[HY000] [2002] No such file or directory

Then I run php artisan migrate again and it all works as expected!

Anyone have any ideas what is causing this behaviour or how I might fault find?

NOTE: EC2 is 64bit Amazon Linux 2016.03 v2.1.4 running PHP 5.5

Advertisement

Answer

sudo chmod -R g+s storage
sudo chmod -R g+s bootstrap/cache

sudo chmod -R u+s storage
sudo chmod -R u+s bootstrap/cache

sudo find storage -type d -exec chmod 775 {} ;
sudo find storage -type f -exec chmod 664 {} ;


sudo find bootstrap/cache -type d -exec chmod 775 {} ;
sudo find bootstrap/cache -type f -exec chmod 664 {} ;

NOT RECOMMENDED: Change the permissions of bootstrap and storage to 777.

[ec2-user@ip-172-31-42-2 current]$ sudo chmod -R 777 storage
[ec2-user@ip-172-31-42-2 current]$ sudo  chmod -R 777 bootstrap
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement