PHP.INI settings: Disable exec, shell_exec, system, popen and Other Functions To Improve Security

by Vivek Gite [Last updated: July 30, 2008]

Q. I run a small Apache based webserver for my personal use and it is shared with friends and family. However, most script kiddie try to exploit php application such as wordpress using exec() , passthru() , shell_exec() , system() etc functions. How do I disable these functions to improve my php script security?

A. PHP has a lot of functions which can be used to crack your server if not used properly. You can set list of functions in php.ini using disable_functions directive. This directive allows you to disable certain functions for security reasons. It takes on a comma-delimited list of function names. disable_functions is not affected by Safe Mode. This directive must be set in php.ini For example, you cannot set this in httpd.conf.

Open php.ini file:
# vi /etc/php.ini
Find disable_functions and set new list as follows:
disable_functions =exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source
Save and close the file. Restart httpd:
# service httpd restart

Further readings:

  1. php.ini directives
  2. PHP Security
Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 3 comments… read them below or add one }

1 Davide 07.30.08 at 2:59 pm

This is not enought because you can always use “`” that will bypass these limitation.

2 Eric Lin 08.03.08 at 10:24 pm

I guess if you really need those functions, you can overwrite the configuration using ini_set function in your script to enable them for a particular site.

3 Experts 11.10.08 at 12:21 pm

Davide you are wrong “`” using shell_exec function so if we disable shell_exec then “`” will be disabled too

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Tagged as: , , , , , , , , ,

Previous post: Red Hat / CentOS Linux: Explain Use of Network Interface virbr0

Next post: Linux Error: curses.h: No such file or directory Problem Solution