Having trouble writing to a file with PHP on Ubuntu

后端 未结 3 932
臣服心动
臣服心动 2020-12-15 11:50

I am running PHP 5.5.9 on Ubuntu 14.04. I\'m having trouble writing to a file. I feel like this has to be a file permissions problem because I\'m pretty sure the code is cor

相关标签:
3条回答
  • 2020-12-15 12:06

    After some more research, I've got it figured out. Here is the solution for anyone having the same problem:

    Since localhost belongs to the www-data group, I just added my user to that group.

    sudo usermod -a -G www-data my_username
    

    Then, I added the folder to the group.

    sudo chgrp -R www-data /var/www
    

    Then, I gave write permissions to the www-data group.

    sudo chmod -R g+w /var/www
    

    This worked for me without any other issue. Thanks!

    0 讨论(0)
  • 2020-12-15 12:10

    Try giving the absolute path and the filename with open:

    $file = '/html/Projects/MD_ScrapingTool/files/filetest.txt';
    

    If the file does not exist, fopen should create the file with 'w' mode.

    0 讨论(0)
  • 2020-12-15 12:13

    You can verify that you have the permission on the folder '/html/Projects/MD_ScrapingTool/files/' and try with an absolute path.

    0 讨论(0)
提交回复
热议问题