Linux Commands and Scripts

Steps To Disable Unsafe PHP 7 Functions in CentOS

If you want to disable unsafe PHP 7 functions in CentOS, this tutorial will help you.

Some PHP functions can be potentially dangerous for your scripts or server in some scenarios. For security purposes, you can always disable them.

Follow below steps to disable it according your PHP configurations. We have covered this for PHP switcher, PHP-CGI selector and PHP_FPM selector.

For switcher, run following command:

# echo “disable_functions = exec, system, popen, proc_open, shell_exec, passthru, show_source” > /usr/local/php/php.d/disabled_function.ini

For PHP-CGI select, run following command:

# echo “disable_functions = exec, system, popen, proc_open, shell_exec, passthru, show_source” > /opt/alt/php73/usr/php/php.d/disabled_function.ini

Note: Above command is for PHP 7.3. You can use same command for different version, change php73 to your desire PHP version.

For PHP_FPM selector, run following command:

# echo “disable_functions = exec, system, popen, proc_open, shell_exec, passthru, show_source” > /opt/alt/php-fpm73/usr/php/php.d/disabled_function.ini

Note: Above command is for PHP 7.3. You can use same command for different version, change php73 to your desire PHP version.

Now, for PHP_FPM, you need restart the service using following command:

# systemctl restart php-fpm

If you want to enable the functions you disabled earlier, simply remove disabled_function.ini file and restart apache/php-fpm.

In this article, we have seen how to  disable unsafe PHP 7 functions in CentOS.

[Need assistance to fix this error or install tools? We’ll help you.]

Related Articles