Chat with us, powered by LiveChat
PHP safe_mode

PHP safe_mode

The PHP safe mode is an attempt to solve the shared-server security problem. When safe_mode is on, PHP checks to see if the owner of the current script matches the owner of the file to be operated on by a file function or its directory.

It is necessary that PHP safe_mode is On by default on a Server running in a shared environment. There are many scripts which are not compatible with safe_mode On need it Off. Following guide will show you PHP safe_mode customization.

After installing & compiling PHP with Apache we have to enable PHP safe_mode. To activate safe_mode globally on the server:

1) Find the path for PHP configuration file .i.e. ‘php.ini

# php -i | grep php.ini

The above commaned will shoe the location of php.ini, it generally located at /usr/local/Zend/etc/php.ini.

2) Edit the php.ini file.

vi /usr/local/Zend/etc/php.ini

3) Search for line safe_mode.

4) Enable safe_mode set it to On.

safe_mode = On

5) Save the file & restart apache service.

Enable/disable safe_mode for a particular account.

PHP safe_mode can be enabled/disabled for a particular account by adding the php value in the .htaccess file of the particular account.

php_flag safe_mode On OR php_value safe_mode On

Many times due PHPSuExec enabled on the server, adding php value to the .htaccess file of the account give Internal Server Error on the site. The following steps will show you how to use Apache configuration file ‘httpd.conf’ to enable/disable safe_mode.
Using PHP as an Apache module, the configuration settings can be changed using Apache configuration file ‘httpd.conf’.

1) Once your SSH to your server as root, go the httpd.conf file which is generally located at /usr/local/apache/conf or its symlink /etc/httpd/conf.

2) Open the httpd.conf file in an editor.

vi /usr/local/apache/conf/httpd.conf

3) Find the VirtualHost entry of the domain for which you have to enable/disable safe_mode. The VirtualHost entry will look like:

ServerAlias www.eukhost.com eukhost.com
ServerAdmin [email protected]
DocumentRoot /home/euk/public_html
BytesLog domlogs/eukhost.com-bytes_log
ServerName www.eukhost.com
User euk
Group euk
CustomLog domlogs/eukhost.com combined
ScriptAlias /cgi-bin/ /home/euk/public_html/cgi-bin/

4) Add these line:

php_admin_flag safe_mode Off

OR

php_admin_flag safe_mode 0

5) After adding the above line, the VirtualHost entry will look like:

ServerAlias www.eukhost.com eukhost.com
ServerAdmin [email protected]
DocumentRoot /home/euk/public_html
BytesLog domlogs/eukhost.com-bytes_log
ServerName www.eukhost.com

php_admin_flag safe_mode Off

User euk
Group euk
CustomLog domlogs/eukhost.com combined
ScriptAlias /cgi-bin/ /home/euk/public_html/cgi-bin/

6) Save the file & restart apache.

Latest posts by Sam (see all)

Sharing

Leave your comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.