Search code examples
phphtmlcentosrename

PHP function rename permission denied although permission set on 0777 for source and target folder


I want to move a file from one directory to another director with the rename() function. But I get the Error:

Warning: rename(/var/www/html/infodisplay-dashboard/uploads/Abo_Bonus.png,/var/www/html/infodisplay-dashboard/New/Abo_Bonus.png): Permission denied in /var/www/html/infodisplay-dashboard/index.php on line 43

I have the permissions on the source and target folder and also on the file set to 0777. Owner of the directories and files is the apache user.

I am working on Rocky Linux release 8.5 (Green Obsidian)

PHP Version is 8.1.0

The code looks like this:

$pfadOld = "/var/www/html/infodisplay-dashboard/uploads/".$fileName;
$pfadNew = "/var/www/html/infodisplay-dashboard/New/".$fileName;
rename($pfadOld, $pfadNew);

I know there are thousands of similar questions, but none of them helped me...


Solution

  • I found the solution for my problem: I needed to disable SELinux. Open /etc/selinux/config in an editor and disable SELinux: SELINUX=disabled After that reboot the system and everything should work as it should.