Windows does not support the shebang syntax like Linux does.
To configure the .php file extension association to open with the PHP executable.
- right click a
.php file (or any file extension you want to associate with php.exe)
- click
Open With
- Select
More Apps
- scroll to the bottom
Choose another app
- Select
Look for another app on this PC
- Navigate to the
php.exe executable and select it
- Check the
Always use this app to open .php files
- click Ok
Afterward you can open up a command prompt (cmd) and have php execute .php files by path without needing to prefix php.
You can also execute a .php file by double clicking them (though the PHP terminal will not stay opened after executing unless you add sleep just like a .bat file functions).
I used .php3 as an example since I have .php configured to open
with my IDE.
d:\test.php3
<?php
echo 'Hello World';
To make the .php file extension an executable like in linux with chmod 0111. You would have to append ;.PHP to the PATHEXT Windows Environment Variable.
![PATHEXT]()
To make it the file globally accessible, append the directory the .php file is located in to your PATH Windows Environment Variable. Otherwise move the .php file to a directory already listed in your PATH Windows Environment Variable, such as C:\Windows or C:\Windows\System32
To initialize the new environment variable, either launch a new command prompt (cmd) as Administrator and close it or reboot.
![cmd php]()
Alternatively create a C:\Windows\Jimboo.bat file that contains.
@echo off
"X:\path\to\php.exe" "X:\path\to\index.php"
This will then execute the desired file in a command prompt by typing Jimboo.
![Batch File PHP]()