PHP Safe Mode, problems and work-arounds
This article is about PHP Safe Mode, security, and Safe Mode workarounds.
Safe Mode is off by default.
Safe Mode does a user check on files that are opened by a process. By default, the users of the file and the process need to match. For more information, see:
Safe Mode user restrictions can interfere with the intended functioning of your PHP files. If you are using a third-party script or application, you should check its technical requirements for the necessary Safe Mode setting.
Some of the major limitations of Safe Mode:
PHP file uploads:
By default, PHP runs as FastCGI on the (gs) Grid-Service. File uploads are always as the Server Administrator. Generally, errors only occur in regards to file size and possibly directory permissions. Ensuring directory permissions are set to 755 will avoid these errors.
PHP file uploads:
On the (dv) Dedicated-Virtual Server, the webserver runs as the Apache user. So, all files that are uploaded via PHP are owned by Apache. This may cause ownership problems for many users.
Disabling Safe Mode may not be enough to get around this problem - also try Running Apache as FastCGI on your (dv), resolving Apache permission errors).
- File modifications: Moving, copying and changing ownership and permissions of files can only be done when they are owned by the administrative user.
- System commands: PHP scripts cannot use the exec( ) and system( ) functions, which means that shell commands cannot be run from within a PHP script.
Many "ready-made" PHP scripts, such as Gallery or ***NUKE, use the system() function to copy files. If your script does not work as anticipated, it is possible that it uses an unsupported safe mode command.
Enabling Safe Mode and workarounds
You can add the following line to your php.ini file:
safe_mode = On
Safe Mode can be turned on globally using the php.ini as described above, or on a per-site basis:
- On the (gs) Grid-Service, you can turn on safe mode per domain using the .htacess file. More info on this can be found at http://www.askapache.com/htaccess/php-htaccess-tips-and-tricks.html.
- See How can I turn off safe_mode on an (dv) Dedicated-Virtual Server with Plesk? for details.
You can verify that safe mode is off/on by viewing your phpinfo.php page.