Changing permissions via chmod at runtime errors with "Operation not permitted"

Deepak picture Deepak · Oct 20, 2009 · Viewed 124.4k times · Source

When I use chmod() to change permissions at run time, it gives me the below message:

Warning: chmod() [function.chmod]: Operation not permitted in /home/loud/public_html/readalbum.php

How can I remove this error and make the chmod function work?

Answer

DigitalRoss picture DigitalRoss · Oct 20, 2009
$ sudo chmod ...

You need to either be the owner of the file or be the superuser, i.e., user root. If you own the directory but not the file, you can copy the file, rm the original, then mv it back, and then you will be able to chown it.

The easy way to temporarily be root is to run the command via sudo. ($ man 8 sudo)