简体   繁体   English

使用 Apache 在树莓 (Debian) 上运行的 PHP

[英]PHP running on raspberry (Debian) with Apache

I'm running PHP code with Apache on my raspberry which is a debian.我在我的 raspberry 上使用 Apache 运行 PHP 代码,这是一个 debian。 My PHP files are in this folder:我的 PHP 文件在此文件夹中:

/var/www/html/project /var/www/html/project

Sometimes my PHP scripts need to write in some files in this sub folder, but I get this error:有时我的 PHP 脚本需要写入此子文件夹中的某些文件,但出现此错误:

PHP Warning: chmod(): Operation not permitted in /var/www/h tml/project/vendor/launch/src/Extends.php on line 36 PHP 警告:chmod():在第 36 行的 /var/www/h tml/project/vendor/launch/src/Extends.php 中不允许操作

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.之后,我的PHP脚本没有错误,可以写入文件夹。

But my problem is if I run again my PHP script, I'll get the same error.但我的问题是如果我再次运行我的 PHP 脚本,我会得到同样的错误。 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?我该如何解决这个问题?

You might be able to add:您或许可以添加:

chmod($file, 0777);

before opening and writing on your file in the PHP file, you wish to write.在 PHP 文件中打开和写入文件之前,您希望写入。

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.您可能会查看这篇文章或一些类似的文章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM