Does any one know of any way of running either of these commands from PHP. I want to be able to set permissions on one certain file if they are incorrect. This file is set with no way of a user editing it to avoid any security problems. Tried using sudo but obviously need to enter a password to be able to use this function.
You need to make sure that they are enabled in your php.ini settings. Look for disable_settings and see if they are in there. You calso can't be running in safe mode. Also if you have things like suphp or other security related features, then it may not be possible to use these functions. You have to have write access to the folder that the file is on. If your php is running as an apache module, then it runs as nobody which will make it virtually impossible to execute this without opening up a security hole. exec('chmod 755 /home/directory/myfile.extension');
Safe mode isn't on and not running any other security features. What exactly am I looking for? Can't find any thing relating to "disable_settings"
PHP can only do what the user it ends up running as is allowed to do. If this file is setup so nobody can edit it but a superuser, chances are PHP will not be able to edit the file. Now, if you wrote an application that you can be executed from the commandline in C[++] or otherwise doesn't need an interpreter, and the only purpose of this application is to make that file permission change, you can setup sudo to allow the PHP user to execute that one single application without a password while keeping it unavailable to everyone else.
Hmm, that looks like a whole world of pain. Is it possible to do this from another approach? I know it's possible in IIS to login as the actual user of the server when accessing a certain folder. When executing "whoami" I think it returns "wwwdata" or something similar. Is it possible when accessing a certain folder (for example: http://www.site.com/admin/restricted/) that it asks me for a username and password, much like .htpswd (speeling may be wrong) would? But only to act under this user while using files within this directory.
You can always give the file to the www-data user you seem to have Apache/PHP running as. Any PHP script would be able to modify the file though. If you have a hole somewhere that would allow someone to execute their own PHP, and this file is something sensitive, this could be a problem.