Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

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:

  • "Questions must be relevant to professional system administration. Server Fault is a site dedicated to professionals; novice questions are off-topic. Please see the Help Center for more information on topicality. The best advice we can give you is to hire a professional to help you out." – Tom O'Connor
If this question can be reworded to fit the rules in the help center, please edit the question.

You want your script name not to start with PHP? Why would that be a problem? – TessellatingHeckler Oct 4 '11 at 22:37
@TessellatingHeckler: He likely wants to start the script just with scriptname.php instead of php scriptname.php. – Sven Oct 4 '11 at 22:45
SvenW is correct – Rob Oct 4 '11 at 22:53

No, a php file cannot be directly executable in Windows. You would need a workaround like wrapping the php filename.php command in a batch file.

share|improve this answer

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 php-cli.exe the default program to open .php files.

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.

However, assoc .php (at least in my case), returned the filetype as corresponding to the editor I use (and checking this filetype with ftype gave the path to the same editor).

To fix this, run something similar to the following (as administrator):

ASSOC .php=PHPScript && FTYPE PHPScript="C:\Program Files (x86)\Xampp\php\php.exe" %1 %* 

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):

echo exec('test1.php');

test1.php (in same folder):

echo date('r');

(Tested on Windows 7 with XAMPP 1.7.7/PHP 5.3.8)

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.