I'm trying to create a script that runs from the webserver that will run a php file via
exec(), but I want it to do so without prepending the
php to it. Can this be done?
Using Windows 2008 and XAMPP
closed as off-topic by Tom O'Connor Aug 14 '13 at 21:21
This question appears to be off-topic. The users who voted to close gave this specific reason:
No, a php file cannot be directly executable in Windows. You would need a workaround like wrapping the
It can be done in Windows 7 - I don't know if the same idea applies to Windows 2008 - however, the effects of this approach may outweigh the benefits.
Essentially, all you need to do is make
I did this in two ways, I am not sure if both ways are required.
Firstly, make php-cli.exe (or php.exe I suppose) the default program for opening .php files.
In Windows that equates to: right click a .php file, select 'Open With...', browse for and select the php-cli.exe executable, and 'set as default'.
I believe that in Windows 2008, this functionality can be reached via Control Panel > Default Programs > Associate a file type or protocol with a program
Once the php-cli.exe executable is set as the default application for .php files you should have achieved your objective, with a few side effects.
At this point, if you run scriptname.php from command prompt, it will be executed by php-cli.exe, and the output displayed below the prompt - which may be what you want; however, if you double click the file, it will also be executed by php-cli.exe (instead of your preferred editor) - which is probably something you don't want.
To fix this, run something similar to the following (as administrator):
After this, accessing my test PHP file in the browser, executed the second test script (without using the php prefix) and displayed the result.
For interest sake, my test scripts were: test2.php (run in browser):
test1.php (in same folder):
(Tested on Windows 7 with XAMPP 1.7.7/PHP 5.3.8)