How to Enable or Disable PHP Safe Mode Globally or Locally

May 6, 2024 / How-to Guide

This guide explains how to enable or disable PHP safe mode globally or locally. It allows users to control the level of security restrictions applied to PHP scripts on their server environment.

Let us follow the steps:

  1. Globally
    1. Find the php.ini configuration file on your server.
    2. Search for the safe_mode directive in the php.ini file.
    3. Change the value of safe_mode to either On or Off as per your necessity.
    4. Save the php.ini file.
    5. Restart your web server for the changes to take effect.
  2. Locally
    1. Access your website’s root directory and find the .htaccess file.
    2. Insert the following code to enable or disable safe mode-
      1. To enable-
        php_flag safe_mode On
      2. To disable-
        php_flag safe_mode Off
    3. Save the .htaccess file.
    4. Authenticate the changes by opening your website and testing its functionality.


  1. Altering PHP settings globally may require administrative access to the server.
  2. Constantly backup configuration files before making changes.
  3. PHP safe mode has been deprecated in newer PHP versions and is no longer supported. It is suggested to use alternative security methods.

This way you can enable or disable PHP safe mode globally or locally. Should you encounter any difficulties, get direct help from our support specialists.

Spread the love