Resolving an unable to fork PHP warning in Windows
Symptoms
In Windows, when trying to execute a system call from a PHP script, you receive a warning like "Warning: system() [function.system]: Unable to fork". A related warning message is "Warning: shell_exec() [function.shell-exec]: Unable to execute"
Sample Code
<?php // print output of shell command executed with backtick operator print htmlentities(`dir`); ?>
Cause
The most likely cause is insufficient permissions to execute system calls in the web server environment.
Fix
You need to give the Internet Guest Account (a.k.a. IUSR_MachineName or simply IUSR) read and execute permission to the command shell program, cmd.exe
. Typically, permission to this file is explicitly denied as a security measure.
- Open Windows Explorer and browse to the
c:\windows\system32
orc:\winnt\system32
directory. - Right-click on
cmd.exe
, and select Properties.... - Click the Security tab. See image below.
- If Internet Guest Account is not already listed, then click Add, then Advanced..., then Find Now.
- Scroll down to and select IUSR_MachineName, where MachineName is the name of your computer.
- Click OK twice to return to the Security tab.
- Select Internet Guest Account and then click the box under Allow for Read & Execute.
- Click OK.
Notes
It is a very bad idea to allow unvalidated input to any system calls. Remember to use escapeshellcmd for any commands that will contain user input.
You will have to give IUSR appropriate permissions to any other files and folders that the PHP script will access.
Read the Program Execution Functions reference materials in the PHP manual for more information.
Applies To
Windows XP, 2000, 2003, PHP, IIS 5.1, fork, system, exec, passthru, shell_exec, backtick operator
Disclaimer: This content is provided as-is. The information may be incorrect.