-2

I'm running PHP code with Apache on my raspberry which is a debian. My PHP files are in this folder:

/var/www/html/project

Sometimes my PHP scripts need to write in some files in this sub folder, but I get this error:

PHP Warning: chmod(): Operation not permitted in /var/www/h tml/project/vendor/launch/src/Extends.php on line 36

To correct this, I run the commande below:

sudo chmod -R 777 /var/www/html/project

After that, my PHP script has no error and it can write in the folder.

But my problem is if I run again my PHP script, I'll get the same error. So I have to re-run the same command:

sudo chmod -R 777 /var/www/html/project 

What is the problem? The folder permissions change automatically after a few hours?

How do I solve this problem?

Emma
  • 27,428
  • 11
  • 44
  • 69
Wazer94
  • 1
  • 1
  • what's the folder permission being changed to? who is the owner? is that changing as well? –  Apr 25 '19 at 23:42
  • Which group/user are you using to run Apache? www-data? If so, please make sure this folder is owner by the same user/group. – Bruno Leveque Apr 25 '19 at 23:53
  • 1
    Possible duplicate of [Changing permissions via chmod at runtime errors with "Operation not permitted"](https://stackoverflow.com/q/1592303/608639), [PHP chmod( ):Operation not permitted, safe_mode deprecation involved?](https://stackoverflow.com/q/23070266/608639), [Unable to chmod files: “Operation not permitted”](https://stackoverflow.com/q/2985582/608639), etc. – jww Apr 26 '19 at 00:06
  • When I run the command "sudo chmod -R 777 /var/www/html/project" the properties change for "Change content: Anyone" (before it was "Change content: Only Owner and group") I tried to add my user "pi" to the group "www-data" (sudo adduser pi www-data) but I still get the same error. How you know which group/user is used to run Apache? I run the command "ps aux | egrep '(apache|httpd)'" and there is user root, www-data and now pi. – Wazer94 Apr 26 '19 at 08:40

1 Answers1

0

You might be able to add:

chmod($file, 0777);

before opening and writing on your file in the PHP file, you wish to write.

Then, after you did writing or closing you might add:

chmod($file, 0755);

Or any other permission level that you wish. You might look into this post or some similar posts.

Emma
  • 27,428
  • 11
  • 44
  • 69
  • 1
    I can't add chmod($file, 0777) because there is a few files concerned and the same program is running on other environment (windows too) and I didn't get this problem – Wazer94 Apr 26 '19 at 08:41