shell_execute doesn't run tar on apache in windows
My environment is php5.3+apache+windows xp+bsdtar.exe(renamed to tar.exe) in my system path
I have this code in my extract.php: shell_exec('tar --no-same-permissions -xjf "C:\Documents and Settings\abcxyz.tar.bz2"');
I can run extract.php using php client in cmdline, like: php开发者_运维技巧 extract.php
But whenever I try to run on the local server, the tar is not executed. My php and apache path both have tar.exe folder included.
not sure why it's not working?
if you run directly from php, you will run that command on behalf of your user, Apache instead is another account witch doesn't have privileges.
Execute services.msc and find the apache service, right button > Log On tab and change from Local System Account to a user created account, enter the username and the password and restart the service.
A few issues.
I am not sure how your apache is configured, but most likely the CWD is the same as the script. Therefore, provide the full path to tar.
The filename is 'tar.exe', not 'tar'. Change that.
Make sure PHP on your dev box is not running in safe mode.
shell_exec()
does not work when PHP runs in safe mode.
If you want your code to run on both your linux box as well as your windows dev box, create a host- or platform-specific configuration file (using PHP_OS
or php_uname('n')
)
精彩评论