file_put_contents failed to open stream: Permission denied - php

I get this error while trying to do file_put_contents().
Apache is working as apache group, started with sudo rights. My user is in apache group. All dirs and files have 755 chmod.
File exists.
Locally it works fine, on remote CentOS server not. Why? How to debug that thing?

Sometimes SELINUX will prevent writing as was my problem serving from Fedora. Run:
sudo setenforce 0

This can be solved by changing directory permission.
Run the command like
chmod 777 database (the directory)
You can use getcwd()" to find the directory path.
Please have a look here

Related

i need help in laravel 5.4 permission denied

it gives me this error when i put laravel on apache server
The stream or file "/var/www/app/storage/logs/laravel-2019-01-02.log" could not be opened: failed to open stream: Permission denied
i have tried everything i set permission to 777 and set owner to root and i try permission 775 also didnot work can any one help me with this...?
note: i am working on apache server on CentOS7
It's a permission issue:
Just Open Your CMD -> Go to your project folder -> Run the following command:
sudo chmod 777 storage/
i fix it...
after using this command i still didnot know what is the reason
1.cd /var/www/html
2.setenforce 0
3.service httpd restart

How do I fix laravel.log cannot be opened in AWS deploy?

We have a Laravel app (version 4) that we're trying to deploy on AWS. Previously, it was hosted in our local servers via XAMPP. On AWS, I created a folder for the laravel app in var/www/html directory path. But as I try to access http://aws-url/laravel_folder/public, I get the error message:
Error in exception handler: The stream or file "/var/www/html/laravel_folder/app/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in /var/www/html/laravel_folder/bootstrap/compiled.php:9134
I've checkout all similar questions and have followed the suggestions, i.e. setting permission of laravel.log to 777, but still keep getting the same problem.
How do I fix this problem?
Thank you
First 777 permission is not a good idea.
If you're on linux, use the following command:
chmod -R 770 logs (add sudo in front if you're not the owner of the folder!)
That will give owner and group read-write-execute permission on the logs folder and everything inside it but will give no permission to other users.
Also make sure that the folder and files inside it have the web server's user as group.
Hope that's help!
You need to set the permissions for the entire storage folder to 777
sudo chmod -R 777 storage/

Laravel 5 not getting any error logs

I installed Laravel 5 on a new VPS, I was running everything fine but I noticed I wasn't getting any Laravel errors the system would only fire a server 500 error at me which is no help when debugging my code.
When I looked in the laravel storage/log it was empty which was strange because I had set the correct file permissions of 777.
So how do I get laravel logs? Why aren't they being written to my storage/log file.
If you've set your file permissions correctly on the /storage file directory and you're running on a VPS not shared hosting you might want to check your apache log, inside var/log/apache2/error.log
Here you might just see a line that read something along the lines of /var/www/html/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied
Well this is strange because you have the correct file permissions...
Let's start by SSH'ing into your VPS head to the directory where laravel is installed normally cd /var/www/html
In here if you run ls -l You should get some results similar to this image below:
Notice how we've been accessing the site as the root user, this is our problem and we can confirm this by running ps aux | grep apache2
You can see here apache2 is running as the user www-data, which is normal for apache. Which means when our laravel installation trys to move files either using ->move() or just trying to write the log file it fails as the www-data user doesn't have permission. So you can change to this www-data user by running: chown -R www-data:www-data * (shorthand for same user/group chown -R www-data. *)
Now if you run ls -l in your www/html directory you should see root user changed to www-data:
This means were now editing the files as the www-data user which has permission, so any changes you make via SFTP should reflect this user change. Fixed!
Edit - This is the first time I answered my own question hopefully it's okay.

Wrong permissions on configuration file, should not be world writable

I'm using MAMP to work on my localhost with a SQL database.
When i'm trying to open my 'PhPMyAdmin' (tools->phpMyAdmin) I get this error
Wrong permissions on configuration file, should not be world writable! MAMP
I googled it and I changed the permission of the config.inc.php file but it still doesn't work.
phpMyAdmin folder has wrong permissions. You need to reset this permissions:
sudo chmod -R 755 /Applications/MAMP/bin/phpMyAdmin
If you're using MAMP PRO:
sudo chmod -R 755 /Library/Application\ Support/appsolute/MAMP\ PRO/phpMyAdmin
Find the file in your Finder, then open up your terminal type in sudo chmod 644, (leaving a space at the end); then drag and drop the file from Finder to your terminal and hit enter.
Still no luck? It could be that your config.inc.php has some invalid PHP in it. Try manually going to localhost/phpMyAdmin/config.inc.php and see if you get an error message. You can also try the server logs in MAMP to see if you get any interesting PHP errors from it.
On MAMP the phpMyAdmin folder is now phpMyAdmin5. I found that the following solved the problem:
sudo chmod 644 /Applications/MAMP/bin/phpMyAdmin5/config.inc.php
I basically located the config.inc.php file in Finder then dropped it into the Terminal and prefixed this with sudo chmod 644 ensuring there is a space after the 644.

Vagrant file_put_contents permission denied

I cannot seem to allow permissions in vagrant. I am attempting to run importbuddy.php in order to migrate a WordPress instance. I get the following error.
file_put_contents(/path/): failed to open stream: Permission denied
I have setup permissions to 777 on the www directory, but that changes nothing. Any idea on how to fix this?
While recursively setting folder and file permissions to 777 should fix your problem (instructions for doing so here), the root of this is probably an issue with the ownership of the files and folders.
The owner of shared folders is usually 'vagrant' but the server itself (if you're using Ubuntu) runs as user and group 'www-data'. You can view the user/group of your files by sshing into your VM (vagrant ssh), navigating to the directory in question and entering ls -l in your console.
If you're running apache, then you can update the user to 'vagrant' by editing the following file (/etc/apache2/envvars) like below:
Find this section
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
And change it to
export APACHE_RUN_USER=vagrant
export APACHE_RUN_GROUP=vagrant
Afterward just be sure to restart apache (with this command sudo service apache2 restart) and the file permission errors should be fixed

Categories