开发者

shell_execute doesn't run tar on apache in windows

开发者 https://www.devze.com 2023-03-25 02:26 出处:网络
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:

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.

  1. 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.

  2. The filename is 'tar.exe', not 'tar'. Change that.

  3. 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'))

0

精彩评论

暂无评论...
验证码 换一张
取 消