简体   繁体   English

无法在 Linux 服务器上使用 PHP 写入文件

[英]Can't write file with PHP on Linux Server

Heys Guys.嘿伙计们。 I'm trying to create a new xml file with php on my ubuntu server.我正在尝试在我的 ubuntu 服务器上使用 php 创建一个新的 xml 文件。 The code looks like代码看起来像

$myfile = fopen("test.xml", "w") or die ("Unable to write file");
fwrite($myfile, "Test");
fclose($myfile);

But whenever this php file is called I get "Unable to write file".但是,每当调用此 php 文件时,我都会收到“无法写入文件”。 Does anybody know what the issue is and how to fix it?有谁知道问题是什么以及如何解决? Thanks谢谢

In the Linux server, it may be a file permission issue try this command below in your directory.在 Linux 服务器中,可能是文件权限问题,请在您的目录中尝试以下命令。 I am assuming your directory is /var/www/html if not replace this with your directory path and run commands.我假设您的目录是 /var/www/html 如果不将其替换为您的目录路径并运行命令。

chown -R www-data:www-data /var/www/html chown -R www-data:www-data /var/www/html

chmod -R 755 /var/www/html chmod -R 755 /var/www/html

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

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