I am working on Laravel 4. On remote server I took backup of old laravel.log and created new one and restored old one again by removing newly created one. Since then I am getting error:
Error in exception handler: The stream or file "/var/www/stage/webapp/app/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in /var/www/staging_html/webapp/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:84
I even change mode and but it did not work either. It's not happening across system, just a particular page.
I am on Amazon AWS
You recreated the file, so the permissions have changed, and apache can no longer access it. Run this in command line to set the permissions:
chown www-data:www-data /var/www/stage/webapp/app/storage/logs/laravel.log
That's if you're using apache. It changes ownership of the file to apache (web server). If the web server user isn't www-data. Find out by typing:
ls -l
In the command line to see what user owns the other files in your laravel directory. Replace www-data:www-data with the user that owns the other web files.
To be clear the left side of the colon is user group and the right side is the user. If you have a specific user group that needs access to those files as well like git or ftp, you may need to set it like this:
git:www-data
ftp:www-data
group:user //generic example
It just depends on your access requirements. If you have questions let me know.
Related
I have Laravel 5.4 installed on my Mac using Composer and MAMP Pro. The installation completed successfully, but when I try to load localhost/lsapp/public, an UnexpectedValueException error is returned. I have checked the file permissions for the storage and logs directories and both are set to 755 using the command line. It seems the log file cannot be written for some reason. Any suggestions?
Full permission denied message: The stream or file "/Applications/MAMP/htdocs/lsapp/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied
in StreamHandler.php (line 107)
When you go into a production environment, I'd recommend the following:
755 permissions for the /log
644 permission for the files inside
For example if you're using apache:
The user owner of the directory (www-data) can read, write and execute.
The assigned group (www-data, where my user is) can read and execute, but not write.
Everyone else can read and execute, but not write.
I just faced the same issue with my installation. Here's what I did to solve it:
Make sure that www-data (or your web server's user) is either the owner or group's owner of the logs directory.
Then make sure that this user have read-write-execute on that folder. On linux I used 770 for that folder. Then laravel is now working fine.
Hope that's help!
I did an installation of laravel, and copied the files to a xampp hosted folder on the same machine. When I try to visit my index.php file however, I'm getting the following error:
Error in exception handler: The stream or file "/Applications/XAMPP/xamppfiles/htdocs/TestManagement/app/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/TestManagement/bootstrap/compiled.php:8969
I'm always a bit hesitant about changing permissions, as I've done some pretty bad chmodding before. Was wondering if there was a rule of thumb or expected behavior for this. Should this be 777 or 755?
The Laravel and Monolog documentation appear to contain no reference to the 'right' permissions. You can make it work with restrictive permissions, but be aware of all of the users that need access:
the web server user
cron user (if you run artisan commands via cron)
anyone who manually runs artisan commands.
They will each need read/write permissions to the log files.
Always use 777 on app/storage folder
The php script is unable to create file owing to denial of permissions.
PHP Script:
<?
echo exec('whoami');
file_put_contents('/var/www/html/sample.txt','Some random Text');
?>
Output :
apache
**Warning**: file_put_contents(/var/www/html/test/samds.txt): failed to open stream: Permission denied in **/var/www/html/index.php** on line **3**
The directory permissions are all 777
I have had same issue and i misplaced some configuration.Firstly remeber that the user who created the php file can read the file and if the user who created php file is different than the apache user in your case it is apache in that case you will get this exception if you try to write from different users.So what you have to do is simply,and i would suggest you to revoke the 777 permissions as i do not like idea of your files being publicity available on read and write to the world,so get it back to 755 and do the next on the command line of your server.
cd /var/www
change the user of the HTML only as we need it to be writable only,so do not touch the var and www,so basically as soon as you have navigated to he www directory you are going to change the HTML directory owner to the one who is currently running the apache server,and you got that info already,in your case it is apache so we are going to do the next,
chown apache:apache html
At this stage the html file owner will be apache so you will be able to write onto it.Anyway and meanwhile i would strongly suggest you to create separate directory inside html lets say testDir and try there,i would not suggest to change the root folder permissions,i had bad experience with them.Anyway i hope it will help as i suffer more then hour and just now got the right way to do it.This got my issue fixed,hope it will fix your's too.!
Sorry, I could not find a tag better than php and json. I hope this gets to the right audience.
I am new to Laravel and am getting the following error with version 1.0.0. I create a test site with the command "laravel new test" and the results indicate success. "Application ready! Build something amazing".
When I attempt to access the built site with http://sitename.com/laravel_install/test/public/ I get
ErrorException
file_put_contents(/home/public/laravel_install/test/app
/storage/meta/services.json): failed to open stream:
Permission denied
I have done a chmod 777 to all directories in the chain, but I am unable to change the permission on services.json. This is the only file that has a different owner ("web")
I try chown owner:222222 services.json but get error message "chown: owner: illegal user name".
All of the other files and directories are owned by 222222.
I suspect the problem is in trying to update services.json
Any suggestions as to how to get services.json created under my ownerid ? How do I get past this ?
To change file ownership (assuming you are using a unix-based OS) you use
chown user:group file.name
You may need to sudo depending on parent directory ownership
user should be the user name you want to change to (ie www-data for apache in Ubuntu)
group should be the group name you want to change to (usually same as user)
you can add "-R" after chown to recursively change ownership on a directory and all of it's subdirectories
The command that you tried to run is looking for a user "owner" and group "222222" and is not finding that user in your system.
Hope that helps.
Edit:
Also, if you are using a redhat-based OS you may want to check that you have selinux running in permissive or disabled. If permissions are 777 you should be able to access the file regardless of the ownership unless the selinux context is not set correctly.
We have an PHP XML parsing script that uploads photos to a folder structure like /content/images/2012/05/31/%object_id%/. This parser runs primarily as a DirectAdmin cronjob. We run into many problems getting the folder permissions right to enable the uploading in that directory for both the cronjob as running the parser via the browser.
According to print_r(posix_getpwuid(fileowner($directory))); the owner of the directory is is the same as get_current_user(). Nevertheless I receive: Warning: mkdir() [function.mkdir]: Permission denied when running the script via the browser. It works fine when running it as a cron job.
All folders have chmod 0777 and new folders are created as such;
mkdir($path,0777,true);
Naturally we have the same permission problems with uploading and/or deleting the files themselves.
Is there any way to enable all the file actions running both as a cron job and through the browser?
We are running Linux with PHP Version 5.2.17.
Couple of thinks to note: get_current_user gets the owner of the .php file (i.e. the script) but NOT the name of the user that is running the php script. Invariably these are different as the file will be uploaded by you (a regular user) and php/apache will run as a different user (often called "apache" or "www".) You need the latter of these two. suggested snippet from the php manual to get this is:
$processUser = posix_getpwuid(posix_geteuid());
print $processUser['name'];
(http://php.net/manual/en/function.get-current-user.php - see comments)
To solve you current problem, though, my strong suggestion is to run the cron as the same user that the php/apache is running as (check man page on crontab) - the user should be the one in that snippet above, CHOWN the files and directories to that same user (they will currently be root) and to a group that is shared between you and the FTP client. Then make sure the user and group have read+write permissions so you can also edit from ftp. Make sure you change permissions on both directores (775) and files (644) as your script creates them.
Also note that if you mkdir(), then the directory above must also have write permissions for the user (and this might actually be your initial problem, and why only root/cron can write there).