php chmod and safe mode

Changing file permissions on a server is usually pretty straight forward, just log in with your favorite ftp client that supports chmod ( a unix command for changing permissions on a file or directory ) and set the permissions on the selected folder or file with 755 or 777 etc.

When doing it via php things can become a little more tricky. This depends on your servers hosting company, most of the time the “safe_mode” is turned on by default. This will in most cases disable the chmod() function within php. The same mode is a feature in php ( no longer exists in php 6 ) that protects against unauthorized system changes like changing permissions on folders to allow anyone to write to them.

With safe mode on you cannot use the function and the script its contained in can fail. There are a number of ways to get around this.

  1. You can disable safe mode. Do this by editing your php config file.
  2. You can set the owner on the script executing the chmod() function to the same owner as the directory you are preforming the chmod on

I suggest first trying to change the owner of the script that is executing the function, this is a more secure solution then shutting off the safe mode.



[contact-form 1 "Contact form 1"]