Setting proper permissions for laravel logs - laravel

I cannot figure out how to set up proper permissions for my storage/logs folder.
I am trying to run an artisan command in the console and I am getting an error saying The stream or file "/var/www/html/laravel-project/storage/logs/laravel-2019-05-04.log" could not be opened: failed to open stream: Permission denied.
Current permissions
drwxrwxr-x 6 www-data www-data 4096 May 3 02:45 storage
drwxrwxr-x 2 www-data www-data 4096 May 4 09:44 logs
-rwxrwxr-x 1 www-data www-data 294932 May 4 19:58 laravel-2019-05-04.log
At first I set my permissions like
1)
sudo chown -R www-data:www-data root/of/laravel/project
2) Added my user Ubuntu to the www-data group
sudo usermod -a -G www-data ubuntu
3) Set all files to 644
sudo find /root/of/laravel/project -type f -exec chmod 644 {} \;
4) Set all directories to 755
sudo find /path/to/your/laravel/root/directory -type d -exec chmod 755 {} \;
If I would run commands like in the console that caused an error I would get an error saying I did not have permissions to write to the log
So I tried it this way
1) Change owner of all directories to myself
sudo chown -R ubuntu:www-data /root/of/laravel/project
2) Give myself and the server permissions
sudo find /root/of/laravel/project -type f -exec chmod 664 {} \;
sudo find /root/of/laravel/project -type d -exec chmod 775 {} \;
3) Give the webserver read & write permissions for storage and cache folders
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
What is the proper way to set permissions properly so that I my user can write to the storage folder AND the web server can as well?

Related

Error 500 in fresh magento 2.4.2 installation

I am making a new fresh install and i get error 500
I am running a magento 2.4.2 with php 7.416 and apache
Memory limit is at 2048M
I have runned the following commands
find . -type f -exec chmod 644 {} \; // 644 permission for files
find . -type d -exec chmod 755 {} \; // 755 permission for directory
find ./var -type d -exec chmod 777 {} \; // 777 permission for var folder
find ./pub/media -type d -exec chmod 777 {} \;
find ./pub/static -type d -exec chmod 777 {} \;
chmod 777 ./app/etc
chmod 644 ./app/etc/*.xml
But i still get error 500.
Can someone please help me?
The reason for 500 is basically the web server has no permissions to load the pages from the installed magento directory. I personally faced the same issue while I was installing magento2 and it was really frustrating to see this after spending long hours at installation.
A quick fix is to add the Magento file system owner to the web server group and re-login to the user account or run bash if you are on ubuntu.
sudo usermod -a -G www-data <user name>
For a hassle free and straight forward installation help, refer to the blog where I clearly explained the requirements and steps for 2.4.2

Laravel The stream or file "storage/laravel.log" could not be opened in append mode: failed to open stream: Permission denied in RHEL8

I need help here. I installed Laravel in my RHEL 8 Server
But I'm getting this error. I know this question already posted many times but I tried to follow the suggestion but no luck for me so far. I have no idea why.
The stream or file "/var/www/html/vpa/storage/logs/laravel.log" could not be opened in append mode: failed to open stream: Permission denied
I tried to use this command to change the permission but it didn't work .
sudo chown -R $USER:www-data storage
sudo chown -R $USER:www-data bootstrap/cache
sudo chmod -R 755 storage
sudo chmod -R 755 bootstrap/cache
sudo setenforce 0
sudo chcon -t httpd_sys_rw_content_t storage
php artisan config:clear
php artisan config:cache
composer dump-autoload
sudo systemctl restart httpd
sudo reboot
Nothing seems to work on my side . I don't know what else to do. Please help me
on ubuntu this step solved it
php artisan config:clear
php artisan cache:clear
sudo chmod -R 775 /var/www/your_folder
sudo chown -R www-data:www-data var/www/your_folder
sudo chmod +w storage/logs/laravel.log
Never use 777
Those are irresponsible permissions
I had changed my storage permission by run following command.It works for me:
step 1:
sudo chmod -R +rwX .
step 2:
sudo chown -R $(whoami) .
In my case, apart from ensuring all permissions were correct, I also had to disable SELinux.
this work for me
sudo chown -R www-data:www-data ./storage
find ./storage -type d -exec chmod 775 {} \;
find ./storage -type f -exec chmod 664 {} \;
sudo chown www-data:www-data ./bootstrap/cache -R
find ./bootstrap/cache -type d -exec chmod 775 {} \;
sudo chown -R www-data:www-data .env
find .env -type d -exec chmod 775 {} \;
Worked for me.
sudo chown -R $USER:$USER /var/www
sudo chmod -R 755 /var/www
sudo chmod -R 755 storage/*
sudo chmod -R 755 bootstrap/*
Simply Read/Write Permission Allow run this commnad
chmod -R 755 /storage/laravel.log”

I am not able to write content to var file

I am not able to write content to var file.
/var/www/html
sudo groupadd www
sudo usermod -a -G www ec2-user
sudo chown -R root:www /var/www
sudo chmod 2775 /var/www
find /var/www -type d -exec sudo chmod 2775 {} \;
find /var/www -type f -exec sudo chmod 0664 {} \;
The commands executed. I get permission denied each time I try creating phpinfo in var folder.
echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php
How do I go about this?
Permission is given only to the owner (root) and group (www). When you run
echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php
The user must be a root or belong to group www.
Any other user or group will be denied to access the filesystem.

services.json failed to open stream: Permission denied in Laravel 4

I was playing around with a working Laravel 4 installation and moved everything into a sub folder. Then I decided to not do that and I moved it all back (all via the command line):
mv * /folder
and then
cd folder
mv * ../
Now, the site is throwing the following error:
file_put_contents(/var/www/quantquote/app/storage/meta/services.json): failed to open stream: Permission denied
Here is a screenshot of the full error:
http://i.imgur.com/8deGG97.png
I've already tried setting permissions on the /storage folder to 777 to no avail.
Spent a whole day for solving this and this command simply solved my problem.
If your permissions are 777 for Laravel App folder and you still get this error, it's because SEliux has blocked it. You can easily unblock your application's folder using this command:
su -c "chcon -R -h -t httpd_sys_script_rw_t /usr/share/nginx/YOUR_LARAVEL_APP/"
That's it!
BTW never disable SElinux: http://stopdisablingselinux.com/
As I stated in my comment:
find app/storage -type d -exec chmod 777 {} \;
find app/storage -type f -exec chmod 777 {} \;
This will chmod all directories and files in app/storage to 777.
As the problem is related to permissions try re-giving the right permissions to app/storage and all its sub-directories and file.
You can do so from the root path of your Laravel app typing:
chmod -Rvc 777 app/storage
If for some reason this doesn't work, try:
find app/storage -type d -exec chmod -vc 777 {} \;
find app/storage -type f -exec chmod -vc 777 {} \;
When chmod 777 or chmod 775 fails check that subdirectories really exists:
app/storage/
├── cache
├── logs
├── meta
├── sessions
└── views
in case these folders does not exists you must to create it:
cd app/storage/
mkdir meta logs cache sessions views
cd ../
find storage -type d -exec chmod 775 {} \;
find storage -type f -exec chmod 664 {} \;
UPDATE 2016 for laravel 5+
In a default Laravel 5+ application structure, storage is at the same level than app. So the previous command becomes:
cd storage/
mkdir meta logs cache sessions views
find . -type d -exec chmod 775 {} \;
find . -type f -exec chmod 664 {} \;
https://laravel.com/docs/5.0/structure
If you're using CentOS7, follows these steps:
Change app/storage directory ownership
chown apache:apache app/storage
Change app/storage permissions
chmod -R 775 app/storage
Prevent SELinux from blocking the app/storage directory
su -c "chcon -R -h -t httpd_sys_script_rw_t [fullpath]/app/storage"
just type this on terminal:
php artisan cache:clear
Never run a 777, in recursive mode. It's a security issue.
For now, remove the services.json file, and try this :
Laravel 4: Failed to open stream: Permission denied
Try these commands one by one:
setenforce 0
setsebool -P httpd_can_network_connect_db on

Warning: Your Magento folder does not have sufficient write permissions

I am new to Magento, I am trying to install a theme via magento connect manager, I copy and paste the extension key then click install and then proceed.I get error 'Warning: Your Magento folder does not have sufficient write permissions.'
please give some solution .Any help would be highly appreciated.
go to Magento home directory and just give permissions for your webroot.
e.g. (in ubuntu) : sudo chown -R www-data .
You could also change the permissions
chmod 777 -R downloader/*
I hope it helps.
[EDIT]
How about in your magento directory (use sudo for below commands if required.):
find . -type d -exec chmod 775 {} \;
find . -type f -exec chmod 664 {} \;
For the normal operation or installation of a Magento store, only 2 folders need to be writable:
/media - for web accessible files, such as product images
/var - for temporary (cache, session) and import/export files
Source here
To reset file permissions run:
find . -type d -exec chmod 775 {} \;
find . -type f -exec chmod 664 {} \;
chmod 777 -R downloader var media
In my case this wasn't enough. I had to set 777 permision also to parent folder - public_html (NOT recursive).
Here is a complete shell script that I wrote to help you setup permissions/ownership of your Magento Installation : mage-set-perms
The shell script is based on the recommendation of Magento official article found here
With me works with this reset permissions:
chmod -R 777 media/
chmod -R 755 var/
I follow some instructions in this url:
http://www.magentocommerce.com/wiki/groups/227/resetting_file_permissions
I used the other solutions listed, e.g.:
cd /var/www/html
find . -type d -exec chmod 775 {} \;
find . -type f -exec chmod 664 {} \;
chmod -R 777 downloader var media
But I also had to do:
chown apache:apache /var/www/html
Since the web root directory was still owned by 'root:root' and causing problems (by continuing to display the Magento error message).
Of all of these what worked was
public_html# find . -type d -exec chmod 775 {} \;
and
chgrp -R www-data
This returns the ability to use Local file system as opposed to FTP
755 does not have group create and delete permissions so 775 worked
Return /media and /var permissions back to /public_html/media# find . -type d -exec chmod 777 {} \;
/public_html/var# find . -type d -exec chmod 777 {} \;

Resources