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 the following.
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 include the following.
- PHP File Uploads: By default, PHP runs as FastCGI on the Grid. 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 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. You may 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 Grid, 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 Edit PHP Safe Mode on a DV Server for details.
You can verify that safe mode is off/on by viewing your phpinfo.php page.