Re: getting "chmod(): Operation not permitted" on attempted file changes



javelin wrote:

On Oct 2, 11:31 pm, Tim Greer <t...@xxxxxxxxxxxxx> wrote:
javelin wrote:
I have a script that works fine on one server, but not on another.
I upload files thru this script, and am trying to modify them after
this, but I get the following message:    "Warning: chmod():
Operation not permitted"

I was told that this is because the file is created by "nobody", so
only "nobody" may edit the file. Can anyone advise on how to
execute scripts as this "nobody"? Also, how do I display a list of
valid users?

Thanks.

J

Your server has their web service set to run PHP in the web server's
API, and it runs as the global web server user (nobody), instead of
the uid (user ID) of your own user.  If a file is created and owned
by the nobody user, it means you'll have to have a script (also
running as nobody) perform the permission change via chmod.  However,
it can fail if the directory it's in isn't set to read, write and
execute.  The directory itself would need to be owned by the nobody
user unless the world (other) group was allowed read, write and
execute.

If your host recently changed from mod_php (Apache API), for example,
to phpsuexec or suPHP, which runs it as CGI as your own user, then
any nobody owned files will need to be changed to your user and group
ownership.  However, it sounds like they have it set to run in the
Apache API amd the permissions just need to be set on the directory
that file is in that you want to run chmod against.  Ideally, ask
your host for help, unless this is your own server.

By the way, maybe I'm mistaken, did you have the PHP script create
the file and then tried to run chmod via FTP or a control panel
interface, or in shell?  This is actually a simple problem and fix, I
just don't want to guess too much about the actual issue and cause
any confusion. --


Hi, thanks for the response. I have a friend hosting this for me. The
PHP script uploads the file, then I try to chmod via cpanel and to
delete or rename the file.

Thanks.

I see. Then he just needs to (as root) set the ownership to your user
so you have permission to modify/rename the file. Be sure he sets the
permissions appropriately, if you still need the PHP script to write
to, modify or rename it as well, after the ownerships are changed to
your own user. In the future, if you want, you can run your PHP
scripts in the CGI API instead, which will not embed the PHP process in
the httpd itself and will therefore run as your own user. CGI spawns a
new process outside of the httpd process itself, which creates a
negligible amount of overhead (which is only an issue if your site is
extremely busy -- but good, efficient code is the key anyway)) and some
things will not work in CGI (though any common thing would and there
are ways around the things that don't), and it will overcome this issue
and actually allow you a more secure environment, if it's a shared
server.
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
.



Relevant Pages