0

So I was executing some PHP code in XAMPP to create a new file for each user and write some contents to it.
It worked in XAMPP on Windows, but when I copied it over to Ubuntu, it doesnt work.
The PHP page cannot create a new file. If the file already exists, it can detect it as it exists, can read the contents, but cannot open it in append mode.
What can I do?
How do I add permissions for the apache2 user so that it can write at the location of the site in /var/www/html/siteroot ?

2
  • 2
    sudo chgrp -R www-data /var/www/html, then add yourself to the group sudo gpasswd -a username www-data Feb 4, 2017 at 19:10
  • 2
    And make permissions 775 with sudo chmod -R 775 /var/www/html Feb 4, 2017 at 19:16

1 Answer 1

2

To resolve this do the following:

  1. Change group ownership of /var/www/html:

    sudo chgrp -R www-data /var/www/html
    
  2. Add yourself to the apache group:

    sudo gpasswd -a username www-data
    
  3. Modify the file permissions of /var/www/html:

    sudo chmod -R 775 /var/www/html
    
3
  • Sure, it worked. Thanks. However, it only works for file_put_contents(); and not for fopen($path,'w');
    – Aditya
    Feb 5, 2017 at 6:30
  • In church, mean while can I see the path your trying to access? Feb 5, 2017 at 7:58
  • Hi back home, can I see the path your trying to access? Feb 5, 2017 at 11:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .