APACHE Permissions are all set but still don't have permission - php

I recently faced this issue, as you can see in the picture, I granted all sorts of permissions to all files, but still I get this error.
Here's the code:
$zipdir=dirname(dirname(__FILE__)).'/tmp';
$zipname="$zipdir/$input[user]-".time().'.zip';
list($pdf,$pdfname)=test_pdf($request);
$zip=new ZipArchive();
if ($zip->open($zipname,ZipArchive::CREATE)!==true) return $error='Could not open zip archive for writing';
$zip->addFromString("pdf/$pdfname", $pdf->Output('','S'));
$zip->addFile("test-docs/",$testformname);
$zip->close();
if (!file_exists($zipname)) return $error='Could not create zip archive';
https://i.stack.imgur.com/kmxUg.png
And here's the log:
PHP Warning: ZipArchive::close(): Failure to create temporary file: Permission denied in /var/www/html/test/app/test.php

Problem just solved!
I needed to grant 775 or above permission to the whole "html" folder in this path :
"/var/www/html/..."
Not just files and folders in it because i tried that completely.
Also apache:apache permission is not needed, root does the work.
This comment helped a lot:
move_uploaded_file gives "failed to open stream: Permission denied" error

Related

The stream or file "D:\Inetpub.....\storage\logs/laravel.log" could not be opened in append mode: failed to open stream: Permission denied on Windows

I have a website made with Laravel, I need to upload it to windows server (Plesk Cpanel) i have set the database and everything is good, but when trying to open the website it shows me :
The stream or file "D:\Inetpub.....\storage\logs/laravel.log" could not be opened in append mode: failed to open stream: Permission denied
no solution found for windows any help, please?
You must change permissions for this file, or for all "storage" dir.
I found this in Google for Plesk - Link for Plesk and for Cpanel - Lunk for CPanel.
You must set 777 or read, write, execute permissions for all groups.
Or read here what permissions you need.
Good luck!
sudo chmod 777 path/to/project/storage/logs/laravel.log

Writing Log File Error file_put_contents(/var/www/html/myproject/ulogs/my-log.log): Failed to open stream: Permission denied

I have inherited a PHP application and need to investigate various issues. I am not a PHP programmer so bear with me.
I wrote a function to log messages to a custom log file.
<?php
function my_logger($log_msg)
{
error_log("USER INFO:::::",0);
error_log(get_current_user());
error_log(exec('whoami'));
file_put_contents('/var/www/html/myproject/ulogs/my-log.log', date('G:i:s') . ">>$ " . $log_msg . "\n", FILE_APPEND);
}
After a lot of 500 errors and no information I discovered that the following line is being written to the error_log.log
PHP Warning:
file_put_contents(/var/www/html/myproject/ulogs/my-log.log): Failed to
open stream: Permission denied in
/var/www/html/myproject/app/lib/log_fns.php on line 11
I have put in a call to get_current_user and whoami which shows me:
[07-Apr-2021 14:26:04 UTC] USER INFO::::
[07-Apr-2021 14:26:04 UTC] root
[07-Apr-2021 14:26:04 UTC] apache
I am calling this at the moment from a simple php page called at http:///test_log.php:
<?php
require("/var/www/html/myproject/app/lib/log_fns.php");
//phpinfo();
my_logger("This is a test message from test_log.php");
?>
I tried to chmod the files to 777 in the ./lib directory but was still getting this error. I have hard coded the path you can see above creating the ulogs directory.
I have tried combinations of chmod the ulogs directory to 777 and chown the directory to apache:apache but still get this error.
Any ideas where I can look next or how to solve?
TIA
Run this command
sudo chmod 777 /var/www/html/myproject/ulogs/
With this work you file_put_contents can generate or edit the file in this directory
This happened to me and no changing of file/folder permissions worked. The issue in the end was SELinux, which is setup as enforcing by default on CentOS.
To disable it, edit /etc/selinux/config, and change
SELINUX=enforcing
to
SELINUX=disabled
Reboot and it should work.

permission denied : copy / writing file (laravel / php)

I use on my application some fonctions about files. creation of files, copy/create from a directory to another, update. On my localhost, all is okay, that's work.
The main purpose is to have a manager for translation on the website.
rights of parent directories : 755
I have error :
1) if files doesn't exist the error is
copy(/blabla/path.php): failed to open stream: Permission denied
2) if I create files before (touch + chown on usr:usr) with basic rights (644) or with updated rights (775) :
file_put_contents(/blabla/path.php) : failed to open stream: Permission denied
On my localhost :
right of directories : 755
right of files : 644
I also tried to clean php cache (php artisan cache:clear)
edit :
I use 2 functions :
copy (who copy default translate file in the directory of second langage) and file_put_contents (who edit file)
public function replaceSlugs(Array $slugs,$filename, $lang)
{
$file=$this->path2File($filename,$lang);
if(!file_exists($file)){$this->duplicateFile($lang,$filename);}
$translate="<?php return ".var_export($slugs,true).";";
return file_put_contents ( $file , $translate, LOCK_EX );
}
private function duplicateFile($lang,$filename)
{
copy($this->path2File($filename),$this->path2File($filename,$lang));
}
private function path2File($filename,$lang="en")
{
return resource_path('lang/'.$lang.'/'.$filename.'.php');
}
Solution is Risky but it will do the trick
Give your folders full permission & clear Cache
Something like this.
sudo chmod -R 777 public/lang/en
if you don't give 777 permission you will also stuck while unit Test.

Unable to rename file in tmp folder in Symfony 2

I have changed the permissions of tmp folder to 0777 but still Symfony is throwing a permission error :
rename(\/tmp\/__CG__MyEntity.php.55eab1cb8bee30.16966444,\/tmp\/__CG__MyEntity.php), operation not permitted.

Kohana Logs file writable but permission denied

I have checked the install.php and it gives me the green light on the logs file. However, my application gets an error saying
ErrorException [ 2 ]: file_put_contents(/my/app/path/logs/2013/03/04.php): failed to open stream: Permission denied ~ SYSPATH/classes/Kohana/Log/File.php [ 90 ]
I am also faced the same issue,i solved it with help of below comment to make all sub directories writable.
chmod -R 777 cache/ logs/
This may help future referrer.
Even if logs/ directory exists and have proper permissions set, it's subdirectories (like logs/2013/ and logs/2013/03) could have improper permissions, for example due to some file copying or so...
Be sure that all subdirectories allow writting for user/group/other.

Categories