Skip to content

Instantly share code, notes, and snippets.

@tored
Last active May 2, 2020 15:26
Show Gist options
  • Save tored/2cadac512f92d29b7b24da1af01104a3 to your computer and use it in GitHub Desktop.
Save tored/2cadac512f92d29b7b24da1af01104a3 to your computer and use it in GitHub Desktop.
Configurable execution of PHP scripts in Windows
@echo off
if "%PHP%"=="" (
echo %%PHP%% is NOT defined
exit /b
)
%PHP% %*
assoc .php=phpfile
ftype phpfile="C:\Tools\php.cmd" -f "%1" -- %~2
assoc .phar=pharfile
ftype pharfile="C:\Tools\php.cmd" -f "%1" -- %~2
setx /m PATHEXT %PATHEXT%;.PHP;.PHAR
@tored
Copy link
Author

tored commented Apr 21, 2020

Run register.cmd as administrator in a prompt to register php files to be executed with php.cmd. Change environment variable %PHP% to whatever php version you need to run, e.g. SET PHP=php-7.4. Now you can run php files as any other executable.

If you need access to php in your command line just put php.cmd somewhere in your %PATH%.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment