开发者

Different content of the System PATH variable for PHP-CLI and PHP via Apache Webserver? How to fix?

开发者 https://www.devze.com 2023-02-09 23:28 出处:网络
I\'m a little bit confused about the Windows System %PATH% variable. When I ran the following script with both, php-cli and as a webpage delivered by apache, I get different output for the path variab

I'm a little bit confused about the Windows System %PATH% variable. When I ran the following script with both, php-cli and as a webpage delivered by apache, I get different output for the path variable.

// different output for php-cli and php executed by apache webserver
<?php
system('echo %PATH%');
?>

Where can I change the PATH variable that is in use with the apache webserver?

My system:

  • Win7 64bit
  • Zend Server Community Edition 5.0.4 (with Apache, not IIS)

Edit: Sorry, I had to give you an example to understand the problem:

I wanted to exec the system('mysqldump .....') command or something like that. The point is, running the script from the command line works, because the MySQL bin path is in the system's path but running the script via webbrowser doesn't include the MySQL bin path in the system's path.

The web system's path is:

C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;D:\Programme\Sysinternals;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Zend\ZendServer\bin 

Bit the original system's path is much longer. My question is now, where is the system's path limited or where can I find the system's 开发者_如何学Cpath settings for the web executed php script?


Try using the following instead,

echo getenv('PATH')


See at C:\Path\To\Zend\ZendServer\ZendEnablerConf.xml.

There is a path variable definied.


Environment variables are per-process in Windows; they are (usually) inherited from the parent process, with the top process setting PATH to the system-wide path plus the per-user path. Therefore, if you are running CLI version of PHP under your user account, the path will contain your user-defined path, while the Apache process running under a service account will get only the system-wide path.

You can set the system-wide path in System Properties (Control Panel\System and Maintenance\System), Advanced, Environment Variables. Or, I believe you can set the environment variable in Apache, e.g. using mod_env and the SetEnv directive.

0

精彩评论

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