I've deployed a Laravel application on AWS ElasticBeanstalk (PHP 7.3 running on 64bit Amazon Linux/2.9.7). The application runs fine when it does, but randomly throws following error for few requests.
PHP Fatal error: Uncaught UnexpectedValueException: 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:110\nStack trace:\n#0 /var/app/current/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(42): Monolog\Handler\StreamHandler->write(Array)\n#1 /var/app/current/vendor/monolog/monolog/src/Monolog/Logger.php(323): Monolog\Handler\AbstractProcessingHandler->handle(Array)\n#2 /var/app/current/vendor/monolog/monolog/src/Monolog/Logger.php(541): Monolog\Logger->addRecord(400, 'Unhandled Excep...', Array)\n#3 /var/app/current/vendor/laravel/framework/src/Illuminate/Log/Logger.php(174): Monolog\Logger->error('Unhandled Excep...', Array)\n#4 /var/app/current/vendor/laravel/framework/src/Illuminate/Log/Logger.php(87): Illuminate\Log\Logger->writeLog('error', 'Unhandled Excep...', Array)\n#5 /var/app/current/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(54 in /var/app/current/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 110
I dont understand why it throws error for some requests only and not others. Nonetheless i tried applying the permissions to the storage and bootstrap folders as suggested by few posts through .ebextensions as below but did not get it working.
"/opt/elasticbeanstalk/hooks/appdeploy/post/99_make_storage_writable.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
echo "Making /storage and /bootstrap writeable..."
chmod -R 777 /var/app/current/storage
chmod -R 777 /var/app/current/bootstrap
Can someone please help me here? I'm new to Laravel and AWS both and very confused as to what might be wrong here.