Page 1 of 1

How to configure PHP command execution path?

PostPosted: 18. December 2009 16:07
by gmi
I have a command line application connected to my PHP site using proc_open(). The command runs in c:/Xampp/. I checked this by proc_open('dir'). I want it to run at c:/Xampp/htdocs/apps/mysite/.

I want to be able to run my site in IIS and Apache. IIS runs the command at the base path of the site by default. IIS has been configured to use php.exe from Xampp, so I reckoned I should look in httpd.conf. But I could not find anything there. I checked php.ini too and I did some greps on "xampp\\"". Does anybody have a clue where to configure this?

Re: How to configure PHP command execution path?

PostPosted: 18. December 2009 16:18
by Wiedmann
Does anybody have a clue where to configure this?

Hm, I did not understand what you want to configure there exactly.

And of course, how is a command line application related to something configured in Apache or IIS?

I have a command line application connected to my PHP site using proc_open(). The command runs in c:/Xampp/. .... I want it to run at c:/Xampp/htdocs/apps/mysite/.

So you have to run the program/command in "c:/Xampp/htdocs/apps/mysite" or you have to do a "change dir" to "c:/Xampp/htdocs/apps/mysite" in your program.

Re: How to configure PHP command execution path?

PostPosted: 18. December 2009 16:55
by gmi
Thanks for your reply.

I guess open_proc() uses some global PHP variable set by IIS or Apache to run the command passed to it. A "change dir" would be overwriting this global variable. If you can give me the name of this variable I would be happy. I would be even more happy if I could configure Apache to set this global variable. (N.B. IIS sets it the way I want by default)

Re: How to configure PHP command execution path?

PostPosted: 18. December 2009 17:20
by Wiedmann
I guess open_proc() uses some global PHP variable set by IIS or Apache to run the command passed to it.

Once more, how is a command line application related to Apache or IIS?
--> If you open a command shell and executing a PHP script, there is no Apache or IIS involved.

Maybe you want explain more detailed what you are doing.

Re: How to configure PHP command execution path?

PostPosted: 18. December 2009 17:38
by gmi
I have read http://php.net/manual/en/function.proc-open.php again and noticed the optional $cwd in

proc_open ( string $cmd , array $descriptorspec , array &$pipes [, string $cwd [, array $env [, array $other_options ]]] )
described as
The initial working dir for the command. This must be an absolute directory path, or NULL if you want to use the default value (the working dir of the current PHP process)

When running under IIS the default equals getcwd(). When running under Xampp/Apache it is c:/Xampp. So in my perception there is a relation with the web server I am running my script in.

Anyhow, setting this parameter solves my problem: proc_open($cmd, $descriptorspec, $pipes, getcwd())
Thanks Wiedmann for your replies

Re: How to configure PHP command execution path?

PostPosted: 18. December 2009 19:37
by Wiedmann
So in my perception there is a relation with the web server I am running my script in.

Ah, ok, sorry. I totally misunderstood you. I thought you are executing a command line PHP script (CLI). (and proc_open is just something you are using to execute "dir", and not your main problem).


When running under IIS the default equals getcwd(). When running under Xampp/Apache it is c:/Xampp.

Good question, because for popen() and all other program execution functions (exec, system...) it's also getcwd(), only proc_open() is working differently. Without anything in the docu why.

Re: How to configure PHP command execution path?

PostPosted: 23. December 2009 23:40
by Wiedmann
When running under IIS the default equals getcwd(). When running under Xampp/Apache it is c:/Xampp.

I had had to persuade the PHP makers a little, but PHP accepted that now as a bug.

Just a question, how have you configured PHP in IIS: FastCGI, CGI, or ISAPI? Because with FastCGI or CGI it's also wrong with XAMPP/Apache (not only with the php5module).