Search code examples
phpserverphpstormsftpubuntu-server

Ubuntu server, PHP - Apache: Permission Denied


I've done a server, but I'm receiving a bad message when I try to create a php file in "/var/www/html". It says: permission denied.
I've looked for a solution, but I don't want make "myuser" permission like "root" amd I have also read that it is a bad practice. I've tried, with PHPStorm, to access to the server with SFTP, but in the end I however can't upload a file or create it.
Thank you before!


Solution

  • By default the owner of the files within /var/www/html is the www:data group. All you have to do is add your self to the www-data group.

    sudo adduser <username> www-data
    sudo chown -R www-data:www-data /var/www
    

    The first line adds you to the www-data group, the second line clears up any files with messed up ownership.

    See more about best practices here https://askubuntu.com/questions/46331/how-to-avoid-using-sudo-when-working-in-var-www

    Hope this helps!