当我尝试调用 CLI 命令时,我在使用 EC2 实例时遇到了一些问题。我正在使用 Laravel,但我不能确定这是 Laravel 问题还是 EC2。
当我通过 ssh 进入我的 EC2 实例时,我运行以下 laravel 命令来迁移我的数据库:
php artisan 迁移
我收到以下错误:
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
然后我运行 sudo php artisan migrate
并得到一个完全不同的错误:
[PDOException] SQLSTATE[HY000] [2002] No such file or directory
然后我再次运行 php artisan migrate
,一切都按预期运行!
任何人都知道是什么导致了这种行为,或者我如何发现错误?
注意:EC2 是运行 PHP 5.5 的 64 位 Amazon Linux 2016.03 v2.1.4
最佳答案
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 {} \;
不推荐:将 Bootstrap 和存储的权限更改为 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
关于linux - EC2 用户访问或文件访问问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38497022/