Laravel on ElasticBeanstalk 'log file permission denied' error keeps coming up even the permission is set in the .ebextensions config file - laravel

I am deploying my Laravel application to the ElasticBeanstalk environment. But I am having issue with laravel.log file permissions.
I deployed my application using "eb deploy" command. After I deployed, I access my application. But it is throwing the following error.
The stream or file "/var/app/current/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied
To solve the issue, I ssh into the server and run the following command.
sudo -u root chmod 777 -R /var/app/current/storage/logs
The problem is solved. Now my application is working. But I deploy my application again running "be deploy" command. After the deployment, the issue popped up again. To solve the issue in a consistent way. I tried to run the command in the .ebextensions config file as follow.
container_commands:
01-migrations:
command: "php artisan migrate --force"
02-log-storage-permissions:
command: "sudo -u root chmod -R 777 /var/app/current/storage/logs/"
I could deploy my application. But the issue still persists. It seems like the command is not working. What is wrong with my configuration and how can I fix it?

I believe that this is because container_commands run when your application is in the staging folder. Thus, after you run 02-log-storage-permissions, your /var/app/current will be replaced anyway with the staging folder. So your chmod wont persist.
To rectify the issue, you can try one of the two options:
Use
02-log-storage-permissions:
command: "sudo -u chmod -R 777 ./storage/logs/"
to change the logs in staging folder.
use postdeploy hook to run your script:
after the Elastic Beanstalk platform engine deploys the application and proxy server.

Related

Setting a laravel storage directory permission by ebextentions

I'm working on elastic beanstalk exextentions. A storage-permission-denied error occurs every deployments and I a have to type command to resolve that. Does the code below(.extensions/chmod.config), prevent the error occur ?
container_commands:
01addpermission:
command: "chmod -R 755 /var/app/current/storage"
01clearcache:
command: "php /var/app/current config:cache"
The code sadly will not work. The reason is that container commands run when your app is in the staging folder, not in current folder:
The specified commands run as the root user, and are processed in alphabetical order by name. Container commands are run from the staging directory, where your source code is extracted prior to being deployed to the application server.
You can try to use relative paths:
container_commands:
01addpermission:
command: "chmod -R 755 ./storage"
02clearcache:
command: "php . config:cache"
The alternative is to use postdeploy platform hook which runs commands after you app is deployed:
Files here run after the Elastic Beanstalk platform engine deploys the application and proxy server

How to access Laravel Folder in Google Cloud

I received an error on my Laravel App
/app/storage/logs/laravel-2020-02-20.log" could not be opened: failed to open stream: Permission denied
So I google the error, and I discovered it a permission error.
chmod -R 775 storage
chmod -R 775 bootstrap/cache
Apparently, this fixes the error, but anytime I tried to run the command in the cloud console. It keeps saying
No directory found.
Can someone advice me on how to access storage directory.
From the tags, I can tell it is GAE flex on GCP. Flex gives you SSH access, but it is not advisable to execute read/write operations directly on the Instances as they are preemptive - can be restarted anytime by GCP. So any command you execute will have to be repeated whenever a new instance starts, which will of course defeats the purpose of scalability on GAE flex.
Try this instead:
On the composer.json file in your project directory, add the follow to the scripts:
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"#php artisan optimize",
"chmod -R 755 storage bootstrap\/cache" ]
For more info, check this community link: https://cloud.google.com/community/tutorials/run-laravel-on-appengine-flexible

How to change files ownership in laravel via docker using powershell

I'm using docker on windows. After I created image from Dockerfile docker build -t my-laravel-image in my laravel project I tried to run it docker run -p 8000:8000 my-laravel-image but got the error in the browser ERR_ADDRESS_INVALID
After some digging I found that it is because /storage and /vendor doesn't have right permissions to write. However, I red on linux forum, that to to give permissions to everyone with chmod 777 is bad so I should change owner with chown, however, I could find command which would do the job on Powershell, so I'm asking you for help
the tutorial I am following is https://www.techiediaries.com/docker-compose-laravel/
EDIT
Tried this ICACLS "C:\Users\Dominykas\Projects\laravel" /setowner "administrator" it succeded, but I get the same error
docker exec -it <your container> chown -R myuser:mygroup laraveldir

"Unable to write to the configuration file." Error with Magento Connect Manager 1.9.3.2

After migrating my Apache server from Ubuntu 14.04 to CentOS 7, I started experiencing these permission errors.
On the Magento Connect Manager login page, I'm hit with an error message and unable to login:
Unable to write to the configuration file.
The error remained even after I set the permission for every file and folder to 0777.
I then deleted the .cfg files in the "downloader" folder. Now the error message has become:
Settings has not been loaded. Used default settings Config file does not exists please save Settings Unable to write to the configuration file.
After login/logout, restarting the Apache server and even the entire host, the error remained. The error logs did not record anything at all.
On Debian 8.6 with Magento-1.9.3.6 the chown following command:
chown www-data:www-data var/brute-force.ini
enable right to write and unlock the access to Magento Connect Manager
Solved!
SELinux was preventing Apache from writing to the directory.
I used the following command to enable it:
chcon -t httpd_sys_rw_content_t /var/www/html -R

Laravel and AWS Elastic Beanstalk - File Permissions

I've created a Laravel app and deployed it to an EC2 instance using Elastic Beanstalk. Everything seems to work except that PHP can't write to the storage directory so I get this error:
Error in exception handler: The stream or file "/var/app/current/site/app/storage/logs/laravel.log"
could not be opened: failed to open stream:
No such file or directory in /var/app/current/site/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:84
This looks like a permissions problem to me, so I've tried using the instructions at http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html to set the permissions.
I have one file 01permissions.config in the .ebextensions directory:
commands:
storage_permissions:
command: chmod -R 755 $EB_CONFIG_APP_ONDECK/site/app/storage
I get the following errors in server logs:
[ERROR] Command storage_permissions (chmod -R 755 $EB_CONFIG_APP_ONDECK/site/app/storage) failed
[DEBUG] Command storage_permissions output: chmod: cannot access ‘/site/app/storage’: No such file or directory
Any ideas what's going on here?
The issue was that I had ignored the logs directory so it wasn't on the server at all. It's not that the server couldn't write to it, it's that it didn't exist.
The default permissions for an instance created by Elastic Beanstalk are:
File 664
Dir 775
They are deployed and owned by the Apache user.
For anyone else with this problem... this would have worked:
container_commands:
01storage_permissions:
command: "chmod -fR 755 /var/app/ondeck/app/storage"

Resources