Fix Permission problems on servers
Notice: If you are not familiar with linux and unsure how to
correctly execute commands, we advise that you
backup current server, before making the below changes.
Many times, on VPS servers (ubuntu, linux, debian, etc…) you might face an issue, like in PHP, showing an error message like:
Warning: rename/move/write/access/create ….. Permission denied in /path/your_file.php
Most times, the reason could be that one user (like root) owns the directory, and another user (i.e. www-data, which is apache instance user) tries to modify the file. For me, the best solution to such problems was to create a Group of users (let’s name it myusers), consisting of both root and www-data:
groupadd myusers gpasswd -a www-data myusers gpasswd -a root myusers gpasswd -a other_user myusers
and then give that group the needed privileges (change your desired path):
sudo chown -R :myusers /var/www/
So, you can modify the file/folder from i.e. FTP or terminal, and also from Web-interface (which is Apache). And finally, assign correct chmod
permissions to d
irectories and f
iles :
find /var/www/ -type d -exec chmod u+rwx,g+rwx,o+rx {} \; find /var/www/ -type f -exec chmod u+rw,g+rw,o+r {} \;
That’s all . (btw, sometimes, instead of rwx
you might need rwxs
)
Definitions:
*u
= user
, g
= group
, o
= others
* r
= read
(same as 4
), w
= write
(same as 2
), x
= execute
(same as 1
)
i.e. rwx
is 4+2+1 = 7
; So, u+rwx,g+rwx,o+rx
is same as 775
_______
Additional resources:
- question: group-permissions-allow-but-still-get-permission-denied
- question: multiple-owner-of-same-folder
- question: reset-default-permissions-for-var-www
- question: change-folder-permissions-and-ownership
- question: whats-the-simplest-way-to-edit-and-add-files-to-var-www
- (Combined command was made from this source)