Home / Guides

Server guide

PHP security settings every server should check – focus on disable_functions

This guide is for small‑business owners, agencies and hosting teams managing VPS, dedicated or cPanel servers. It shows what disable_functions does, how to audit it, and how to apply safe defaults.

8 min readUpdated November 2026 by the RootManage teamWorks on Ubuntu, Debian, AlmaLinux and Rocky unless noted

The short answer

The disable_functions directive lets you block risky PHP functions such as exec, system, and shell_exec. Setting it to a curated list removes a common attack vector while keeping needed functionality intact.

Why disable_functions matters for PHP security

PHP includes functions that can execute system commands, read or write arbitrary files, and modify server settings. If an attacker can inject PHP code that calls functions like exec, system, shell_exec, passthru, proc_open, or popen, they can run commands with the same privileges as the web server user. This can lead to data theft, defacement, or full server compromise, especially on shared hosting or VPS environments where multiple sites run under the same user. Limiting these capabilities is a core defense against code execution attacks.

The disable_functions directive in php.ini tells the interpreter to refuse calls to listed functions, returning a warning instead of executing them. By disabling high‑risk functions, you reduce the attack surface without affecting most legitimate applications, which typically rely on database access, string handling, and web APIs rather than direct OS interaction. After updating the directive, restart PHP-FPM or Apache to apply the changes, then verify that the functions are indeed blocked.

  • Identify high‑risk functions: exec, system, shell_exec, passthru, proc_open, popen, eval, assert, pcntl_exec.
  • Edit the global php.ini or a per‑pool configuration file.
  • Restart the PHP service to load the new settings.
  • Test with a simple script that calls a disabled function and checks for the warning.
terminal
sudo nano /etc/php/8.2/fpm/php.ini   # open the php.ini file
# Add or edit the line:
disable_functions = exec,system,shell_exec,passthru,proc_open,popen,eval,assert,pcntl_exec
sudo systemctl restart php8.2-fpm   # reload PHP-FPM

After restarting, create a test PHP file that calls one of the disabled functions. The script should produce a warning like "function exec() is disabled". If the warning appears, the configuration is active and the server is less exposed to code execution attacks.

How to check the current disable_functions value

To see which functions are disabled in PHP, start with the built‑in phpinfo() page. Create a temporary file called info.php in a web‑accessible directory with the single line <?php phpinfo(); ?>. Access it via a browser (for example http://yourdomain.com/info.php) and look for the *disable_functions* entry in the *Core* section. This shows the active list for the PHP version that serves your site.

On the server side you can also read the configuration directly. For a typical Linux VPS or dedicated server, the main php.ini file is located at /etc/php/7.4/apache2/php.ini (path may vary by distro and PHP version). Use a pager like less or grep to locate the directive. On a cPanel server, the effective php.ini for a specific account is often found under /home/username/public_html/php.ini or you can query the handler with php -i | grep disable_functions. These commands are read‑only and safe to run.

  • Use phpinfo() in a browser to view the live setting.
  • Run grep -i "disable_functions" /etc/php/*/apache2/php.ini on Linux.
  • On cPanel, check /home/username/public_html/php.ini or run php -i as the account user.
terminal
grep -i "disable_functions" /etc/php/*/apache2/php.ini
php -i | grep -i "disable_functions"

The output should list function names separated by commas. If the value is empty, no functions are disabled. If you see a long list, those functions are blocked and you may need to adjust the list based on your application requirements.

Choosing a safe baseline list of functions to disable

When configuring PHP on a shared or dedicated server, start by disabling functions that can execute external programs, manipulate the file system, or change runtime settings. These functions are rarely needed by typical web applications and they provide a direct route for attackers to run arbitrary code or read sensitive files. By removing them from the allowed list you reduce the attack surface without affecting most CMSs, frameworks, or custom scripts that rely on higher‑level APIs.

A safe baseline should include functions that allow command execution, file inclusion, and dynamic code evaluation. Most modern PHP codebases use database abstractions, templating engines, and built‑in file handling methods, so blocking these functions does not break normal operation. After applying the list, test critical pages and background jobs to confirm that essential functionality such as uploads, image processing, and email sending still works.

  • exec, system, shell_exec, passthru, proc_open, popen
  • eval, create_function, assert
  • include, include_once, require, require_once
  • phpinfo, dl, ini_set, ini_alter
  • posix_getpwuid, posix_getgrgid, pcntl_exec
terminal
grep -E '^disable_functions' /etc/php/*/apache2/php.ini || echo 'disable_functions = ' >> /etc/php/8.2/apache2/php.ini
sed -i 's/^disable_functions.*/disable_functions = exec,system,shell_exec,passthru,proc_open,popen,eval,create_function,assert,include,include_once,require,require_once,phpinfo,dl,ini_set,ini_alter,posix_getpwuid,posix_getgrgid,pcntl_exec/' /etc/php/8.2/apache2/php.ini
systemctl reload apache2   # example for Apache; reload your web server after editing

After reloading the web server, check phpinfo() or run php -i | grep disable_functions to confirm the functions are listed. Verify that your web applications still load pages and perform expected tasks; if a feature breaks, identify the required function and consider a more granular exception for that specific script.

Applying the disable_functions setting safely

To use the disable_functions directive without breaking existing applications, first list the functions that are truly unnecessary for your workload. Common candidates are exec, system, passthru, shell_exec, proc_open, and popen. Add them to the directive as a comma‑separated string, but keep the line within the existing php.ini or a per‑directory .user.ini file. Avoid removing functions that your scripts rely on; test changes on a staging copy before applying to production.

After editing, reload the PHP process manager so the new settings take effect. For PHP‑FPM, use the service command to restart the specific pool or the whole daemon. For Apache with mod_php, a graceful restart is sufficient. Verify that the configuration loads without errors by checking the PHP info page or the service logs. This ensures the server continues to serve requests while the new restrictions are active.

  • Identify functions to disable based on your application’s needs
  • Edit the appropriate php.ini or create a .user.ini in the web root
  • Add the functions to the disable_functions line, preserving existing entries
  • Reload PHP‑FPM (systemctl reload php-fpm) or Apache (systemctl reload httpd)
  • Test a PHP script that calls a disabled function to confirm it is blocked
terminal
# Example: edit php.ini safely
sudo cp /etc/php/8.2/fpm/php.ini /etc/php/8.2/fpm/php.ini.bak
sudo sed -i '/^disable_functions/ s/$/,exec,system,shell_exec,proc_open,popen/' /etc/php/8.2/fpm/php.ini
# Reload PHP‑FPM to apply changes
sudo systemctl reload php-fpm
# For Apache with mod_php
# sudo systemctl reload httpd

Check the PHP info page (phpinfo()) for the disable_functions entry. It should list the functions you added. Also review the service logs (journalctl -u php-fpm or journalctl -u httpd) for any syntax errors during the reload.

What not to disable without testing

Do not disable PHP functions blindly. Many popular content management systems and custom applications rely on functions such as file_get_contents, json_decode, preg_match, and hash_hmac. Turning these off without checking can break page rendering, form processing, or API integrations, leading to downtime and frustrated users. Before changing the disable_functions directive, review the codebase or documentation of the software you run. Identify which functions are essential and which are truly unnecessary for your environment.

Testing is essential before any change. Use a staging server that mirrors production to verify that core features work after you modify php.ini. If you must remove a function, document the reason and keep a backup of the original configuration. After applying the change, monitor error logs for warnings about undefined functions. This careful approach prevents unexpected failures and helps maintain a stable, secure hosting environment.

  • Check the CMS or framework documentation for required functions.
  • Search the codebase for usage of each function before disabling.
  • Create a backup of php.ini or take a snapshot before editing.
  • Test changes on a non‑production server first.
  • Review error logs after applying the new settings.
terminal
php -i | grep disable_functions

The command above lists the currently disabled functions. Verify that the output does not include any functions required by your applications before you edit php.ini.

Verifying the change works as expected

After editing the php.ini or creating a custom .user.ini file, restart the PHP service (for example, systemctl restart php-fpm). Then verify that the functions you disabled are indeed unavailable. A quick way is to create a small PHP script that calls each function and prints a message. If the function is blocked, PHP will emit a warning like "function is disabled" and the script will not execute the call. This confirms that the configuration change took effect without affecting other parts of the application.

Next, ensure the website continues to operate normally. Browse a few typical pages, submit a form, and check any scheduled jobs or background tasks. Look for PHP errors in the web server’s error log (/var/log/httpd/error_log or /var/log/nginx/error.log). If the site loads without fatal errors and the logs show no new warnings about missing functions, the change is safe. Performing these checks on a staging copy before applying to production is recommended.

  • Create a test script that calls each disabled function.
  • Run the script via the web server and via CLI.
  • Check the web server error log for warnings.
  • Verify normal page loads and form submissions.
terminal
cat > /tmp/test_disabled.php <<'EOF'
<?php
$funcs = ['exec', 'shell_exec', 'system'];
foreach ($funcs as $f) {
    if (function_exists($f)) {
        echo "ERROR: $f is still enabled\n";
    } else {
        echo "$f is correctly disabled\n";

The output should list each function as "correctly disabled". Any "ERROR" lines indicate the function is still available and the configuration needs to be revisited. No PHP fatal errors should appear, and the site should behave as before.

Keeping the setting consistent over updates

When a server receives regular OS or PHP updates, custom php.ini directives can be overwritten by default files. To keep security settings consistent, store the required directives in a separate file, for example /etc/php.d/99-custom.ini, and include it from the main configuration. Use the include or scan_dir directive supported by the PHP version so that the file is always read after the package‑provided files. This approach isolates your changes and makes it easy to verify that they are still present after each update.

Automate the verification by adding a simple check to your monitoring or configuration‑management pipeline. A script can parse the effective PHP configuration (php -i) and compare the values of critical directives such as disable_functions, expose_php, and open_basedir against an approved list. If a mismatch is found, the monitoring tool should raise an alert and, optionally, trigger a configuration‑management run to re‑apply the missing settings.

  • Create a dedicated ini file for custom security directives.
  • Add the file to version control and reference it in the main php.ini.
  • Include a health‑check script in monitoring that runs php -i and validates key settings.
  • Use your configuration‑management tool (Ansible, Chef, Puppet) to enforce the file’s presence after each update.
terminal
php -i | grep -E 'disable_functions|expose_php|open_basedir'

The command should list the current values of the security directives. Verify that they match the expected configuration; any deviation indicates that an update may have overwritten your custom settings.

If you would rather have engineers do this for you, see Linux server management, Windows server management or emergency malware cleanup.

Questions people ask

Which PHP functions should I always disable on a shared hosting server?

Commonly disabled functions on shared hosting include `exec`, `shell_exec`, `system`, `passthru`, ``proc_open``, ``popen``, ``eval``, ``assert``, ``preg_replace` with the `/e` modifier, ``show_source``, ``ini_set``, and ``mail`` when not needed. Disabling them reduces the risk of arbitrary code execution and system command abuse.

How does disable_functions differ from open_basedir?

`disable_functions` is a PHP ini directive that prevents listed functions from being called in any script, regardless of file location. `open_basedir` restricts the filesystem paths that PHP scripts can access. The former blocks code execution; the latter limits file system visibility.

Will disabling functions affect WordPress or other popular CMS platforms?

Most popular CMSs, including WordPress, Joomla and Drupal, work with the typical disabled list. They rarely need functions like `exec` or `shell_exec`. However, plugins that rely on those functions will fail. Test critical plugins after changes and keep a list of required functions per site.

Can I set disable_functions per virtual host in cPanel?

cPanel allows per‑account PHP configuration via the “Select PHP Version” or “PHP Options” interface, which can set `disable_functions` for that account. For individual virtual hosts you can use a custom `php.ini` or `.user.ini` file in the site’s root, provided the PHP handler respects per‑directory overrides.

Want a person to look at it?

Tell us what you see. We reply with what we think is wrong and what it would take to fix it.