FIle could not be opened in append mode: failed to open stream: Permission denied laradock - laravel

I'm setting up laradock (Setup for Multiple Projects) following the official documentation from the Laradock in my local machine.
After installation I installed the laravel through workspace container bash. I did configured the config file for the app in nginx/sites/ directory and in /etc/hosts file.
While visiting the development url I'm getting the following error message:
The stream or file "/var/www/laravel-api/storage/logs/laravel.log" could not be opened in append mode: failed to open stream: Permission denied

This worked for me:
chown -R www-data:www-data "project foldername"

If you are still facing the issue even after changing the permission and owner of file, just check for the OS of you Linux server.
Login to your server
$ ssh user#server-ip
check your OS running on linux server
$ cat /etc/os-release
//output
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
If it is CentOS, you need to disable Security-Enhanced Linux (SELinux) if enabled.
Check for SELinux status
$ sestatus
If it is enabled, then
$ setenforce Permissive
Or
$ sudo setenforce 0
Have a good day!

you have to enter the workspace first by typing "docker-compose exec workspace bash"(without quotes)
To give a write permission to a single file,
chmod -R 777 /var/www/laravel-api/storage/logs/laravel.log
or
chmod -R 777 /var/www/laravel-api/storage/logs
or
sudo chmod -R 777 /var/www/laravel-api/storage/logs/laravel.log
when the same error appears but different folders or files, do the same thing only change the folder name
example :
chmod -R 777 /var/www/laravel-api/storage/logs
chmod -R 777 /var/www/laravel-api/storage/framework/views
chmod -R 777 /var/www/laravel-api/storage/framework/sessions

If you aren't running your application as root on your web server, then it wont have write access based on the permissions you've provided.
Checked from workspace container bash. storage/logs/ directory has drwxr-xr-x 2 root root 4096 Aug 1 07:37 logs
The error is complaining about permission denial for opening in append mode - it doesn't have permission to write to the file, only root does.
What you need to do is make your web server group the owner of the storage directory:
chown -R www-data:www-data /var/www/laravel-api/storage/
The www-data can be switched out for whatever group your web server is associated with.
To avoid completely repeating an amazing and complete answer, I recommend you give this answer a read:
How to set up file permissions for Laravel?

Give group write access to /storage/logs/
sudo chmod g+w storage/logs

You need to run the following command. It works for me:
step 1:
sudo chmod -R +rwX .
step 2:
sudo chown -R $(whoami) .

Related

Chown directory via SSH on server using NPM script

I am trying to chown a directory via an NPM script. The script looks like the following:
chown -R 755 www-data root#XXX.XXX.XXX.XX:/var/www/test.com
But the message I get back is: chown: www-data: No such file or directory even though this exists. Any ideas much appreciated.
chown operates locally, not on remote servers. In your example, chown is attempting to operate on ./www-data and ./root#XXX.XXX.XXX.XX:/var/www/test.com, which don't exist in the directory of wherever you were when you executed the command.
You will need to execute chown as a command through ssh:
ssh root#XXX.XXX.XXX.XX chmod -R 755 /var/www/test.com/
Fixed this with following script.
ssh root#XXX.XXX.XXX.XX chmod -R 755 /var/www/test.com/
(I needed to login to the server first).

Permission denied on file transfer

I have a new instance and everything was going fine, I have the site installed and transferred over my database and uploaded most my wordpress file to the server.
But towards the end of my upload, files stopped being uploaded and I keep getting the message
***Error: Directory /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017/01: no such file or directory
Command: cd "/opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017"
Response: New directory is: "/opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017"
Command: mkdir "01"
Error: mkdir /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017/01: permission denied
Command: mkdir "/opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017/01"
Error: mkdir /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017/01: permission denied***
I've tried changing the permissions to 755 or 644 but get this error
***Status: Setting permissions of '/opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017/07' to '644'
Command: chmod 644 "07"
Error: set attrs for /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017/07: permission denied***
Video file transfer: https://www.screencast.com/t/d8BbFnxkp
Video permission fail: https://www.screencast.com/t/2XBr6zwqd
I'm just puzzled why the other transfers worked
Thanks for your help.
I found this solution that appears to work.
sudo chown -R bitnami:daemon /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads
sudo chmod -R 775 /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads
Then, you can try to upload and check if it works. If it doesn't, you can try doing this instead:
sudo chown -R daemon:daemon /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads
In my case I had this problem while publishing my application from JetBrains Rider to Ubuntu server via SFTP. As there is no way to use sudo, the easy solution was to set publish folder ownership for user, specified in ssh connection for SFTP.
sudo chown -R username:username /var/www/your-app-publish-folder
Or, if you are already logged in under this user on server:
sudo chown -R $USER:$USER /var/www/your-app-publish-folder

Laravel: file_put_contents() failed to open stream: Permission denied for Session folder

I am getting this issue for sessions even when I have given 777 and required user and group to the folders in storage.
ErrorException in Filesystem.php line 81: file_put_contents(/var/www/html/business/storage/framework/sessions/2b184c1b05d6d2af943d9a4e48875301321a56ec): failed to open stream: Permission denied
How can I get rid of this issue?
at HandleExceptions->handleError('2',
'file_put_contents(/var/www/html/business/storage/framework/sessions/2b184c1b05d6d2af943d9a4e48875301321a56ec):
failed to open stream: Permission denied',
'/var/www/html/business/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php',
'81', array('path' =>
'/var/www/html/business/storage/framework/sessions/2b184c1b05d6d2af943d9a4e48875301321a56ec',
'contents' =>
'a:5:{s:6:"_token";s:40:"Dyi8ML8zxaQJOEiVvqBpqk3noLDJTkIdqiC67qs9";s:9:"_previous";a:1:{s:3:"url";s:29:"http://XXXXX:8333";}s:22:"PHPDEBUGBAR_STACK_DATA";a:0:{}s:9:"_sf2_meta";a:3:{s:1:"u";i:1470895812;s:1:"c";i:1470895812;s:1:"l";s:1:"0";}s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}}',
'lock' => true))
I had a problem like that and doing the following solved it for me
chmod -R gu+w storage
chmod -R guo+w storage
php artisan cache:clear
Got it from the answer here
if you try
chmod -R gu+w storage
chmod -R guo+w storage
php artisan cache:clear
and it still doesn't work.
you have two ways:
Disable your SELinux (i really don't recommend this way, unless you are on training or learning)
Configuring SELinux Policies for Apache Web Servers
i want to break down every steps for confirguring selinux policies
assumption: you've already installed all database like mysql, postgresql, or others. you've installed web server
install semanage with command "yum provides /usr/sbin/semanage"
install policycoreutils-python with command "yum install -y policycoreutils-python"
create policies:
a. sudo semanage fcontext -a -t httpd_sys_content_t "/var/www/html/webapp(/.*)?"
b. sudo semanage fcontext -a -t httpd_log_t "/var/www/html/webapp/logs(/.*)?"
c. sudo semanage fcontext -a -t httpd_cache_t "/var/www/html/webapp/cache(/.*)?"
Allowing ReadWrite Access:
a. sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/webapp/storage(/.*)?"
ACCESS YOUR WEBAPP
b. restorecon -Rv /var/www/html/webapp
Giving 777 to the folder session works for me.
chown -R www-data:www-data project_folder
sudo service apache2 reload
chmod -R gu+w storage
chmod -R guo+w storage
php artisan cache:clear
This worked for me for my laravel 8 application.
First run this command in your Laravel app folder
sudo composer update
After that run the following in order
sudo chown -R $USER:www-data storage
sudo chown -R $USER:www-data bootstrap/cache
sudo chmod -R 775 storage
sudo chmod -R 775 bootstrap/cache
run the following command
docker-compose exec <your webserver container name> sh OR bash(if it uses bash)
then
ls -l /var/www/storage/framework/views/ | grep 7369b96b4 (this number is part of the file name you are trying to see it permission) you will see something like this -rw-r--r--
the run
chmod 777 var/www/storage/framework/views/7369b96b436adb2109e56fbb8ed7ba805568c985.php(the full file name)
reload the page
Goto project root folder and run the following command
sudo chmod -R 777 storage/* bootstrap/cache/*
Go to the session folder and make the permission like 755. It's worked for me.

Get permission to work with files on my Amazon EC2 Ubuntu server using FTP-WinSCP

I have an Ubuntu server on Amazon, I installed everything for working with it (php, mysql, phpmyadmin, apache..), The problem is that I cant move around or edit files using the FTP.
I get the error message:
Permission denied.
Error code: 3
Error message from server: Permission denied
from my WINSCP.
The only way I can trancefer/edit file is using 'putty' with the sudo/nano command.
I found a lot of information about this on google, but there are no updated soulution I can find. Linux isn't my usual work-space.
How do I get the permissions working for the WINSCP ?
A lot of answers say to change permissions on /var/www/ ... however AWS shortcuts out of the WWW folder and into the /var/app/current/ directory. If all else fails try:
sudo chown -R -v ec2-user /var/app/current/
On Ubuntu image in AWS, default user is ubuntu. Instead of using system folders like /var/... better to use /home/your_folder. Then change the ownership using {chown} command. For eg.
$ sudo chown -R -v ubuntu /home/your_folder/
This will change the ownership of 'your_folder' and contents inside it from 'root' user to 'ubuntu'. Then Winscp should be able to upload/delete/create files using SFTP/FTP etc..
I had the same issues. The solution is: You can solve this by changing WordPress ownership type:
sudo chown -R www-data:ubuntu /var/www/wordpress
Then, Change the right permission for the particular files and directories, type command
sudo find /var/www/wordpress/ -type d -exec chmod 755 {} \;
sudo find /var/www/wordpress/ -type f -exec chmod 644 {} \;
Apart from this, set the following important files to chmod 600 so that only the owner can fully read and write access to these files:
sudo chmod 600 /var/www/wordpress/wp-config.php
sudo chmod 600 /var/www/wordpress/.htaccess
Then everything will work. You will be able to access your wordpress files
for me using free tier from cloud providers will not give you root access, to fix this you have to change folder permission from SSH or try this solution
OS: windows 10 Pro
Open WinSCP instead of SFTP you select SCP go to advance settings click on SCP/Shell and change the shell option to sudo su -
Now you will be able to get permission.
Change file permision by command chmod 777 /var/app/current/ and transfer files to the directory

Meteor will not run without Sudo?

On OSX Yosemite and the latest version of meteor (1.0.1), no matter how many times I uninstall and reinstall it, I can't seem to get it running without sudo. My user account is an administrator account. But meteor refuses to run without sudo. The errors I'm getting are all:
-bash: meteor: command not found
I've seen a few posts on here with similar problems. I've tried repairing disk permissions with disk utility. I've tried:
sudo chown -R $myUsername /usr/local/bin/meteor
I'm not sure what else I can do, because it seems to be a permissions issue. Does anyone have any suggestions?
Additional info that might help:
$ sudo which meteor
/usr/local/bin/meteor
$ sudo ls -l /usr/local/bin/meteor
-rwxrwxrwx 1 root wheel 3528 Dec 18 23:14 /usr/local/bin/meteor
$ ls -ld /usr/local/bin
drwx------ 6 502 wheel 204 Dec 18 23:14 /usr/local/bin
By the way, ls -l /usr/local/bin/meteor only works with sudo.
After we clarified the permissions of the meteor executable and its base directory,
the problem became quite clear:
The Meteor binary is located in /usr/local/bin/meteor
Your user didn't have permission to the directory /usr/local/bin
The steps to resolve:
Add permission on the base directory: sudo chmod +rx /usr/local/bin
If necessary, add the base directory to PATH: PATH=$PATH:/usr/local/bin
For future reference:
When you get this kind of error: -bash: XYZ: command not found
The first thing to check is find the absolute path of XYZ, for example /path/to/XYZ
Try to run with the absolute path /path/to/XYZ
If running with /path/to/XYZ gives -bash: /path/to/XYZ: Permission denied that means you have a problem with permissions on the file and/or directories:
You need read and exec permission on the file itself: sudo chmod +rx /path/to/XYZ
You need exec permission on all path elements leading up to the file: sudo chmod +x /path /path/to
After fixing permission issues, running with /path/to/XYZ should work
After fixing permission issues, if running with XYZ (without full path) still doesn't work, that means /path/to is not on your PATH. Fix with PATH=$PATH:/path/to
Note: the above sudo chmod commands give permissions (read and exec) to all users: owner + group + other. In the case of the OP (and in most common cases), this is perfectly fine.
In situations with more sophisticated permission setup, you might need to be more specific, and use g+rx instead of +rx.
(for the record)
If it works with sudo, and without sudo you get command not found, that means that meteor is on the PATH for root but not for your user. To make it work for your user, you need to find the path to meteor and add it to your user's PATH. For example:
Become root with sudo su -
Find the path of meteor, run command: which meteor
Logout from root (Control-D) to return to your user
Add the base directory to PATH, for example if earlier which meteor gave you /usr/local/bin/meteor, then do this: PATH=$PATH:/usr/local/bin
After this, it should work with your user. To make it "permanent", add the last step in your ~/.bashrc.
If this still doesn't work, then perhaps your user doesn't have the execute permission on the file. Fix that with this command:
sudo chmod +x /usr/local/bin/meteor
From your comments it also seems your user doesn't have permission on the /usr/local/bin directory itself. Fix that with this command:
sudo chmod +rx /usr/local/bin
Shouldn't need an admin account to run it, standard user account works fine. You can locate the meteor file by typing which meteor. It will tell you what file is being used to execute.
Try removing the .meteor folder in your home directory, something like rm -rf ~/.meteor and the script from the bin folder rm /usr/local/bin/meteor or rm 'which meteor' (speech marks there are the ones above ~)
And then reinstall meteor without sudo using the curl https://install.meteor.com/ | sh command.
Should hopefully install with all the correct permissions...

Resources