Windows 8: .phar files, how do you want to open

I am trying to run composer on windows using wamp. I installed the composer using the cmd prompt, and now I am trying to run a “composer update” for the SDK. However, when I type “update for composer.phar”, windows ask which application I want to use to run this program. I want the command line to handle this! How can I run it through cmd, without this “what application” window?

+10
php cmd wamp composer-php
source share
2 answers

You must install php.exe as the default application for phar files.

+15
source share

.phar stands for PHP Archive

Usually .phar takes some arguments, so they are intended to be run from the command line. Linux / BSD / OS X shell or Windows command line.

Linux use .phar assumes that .phar copied to some kind of / bin and renamed without the .phar extension, so you can use the php archive as if you were using any other linux command. Therefore, I recommend the following way to do the same with Windows:

  1. Put all your .phar files in one directory, e.g. C:\php\phars
  2. Add C:\php\phars to the system environment variables (right click on my Computer -> Properties -> Advanced System Settings -> Environment variables )
  3. Run the elevated command prompt (find the command prompt in the Start menu, then right-click and select Run as Administrator )
  4. Enter the following commands, replacing the path C:\phpdev\php\php542\php.exe with the full path to the PHP executable:
 ftype PHARFile=C:\phpdev\php\php542\php.exe "%1" %* assoc .phar=PHARFile set PATHEXT=%PATHEXT%;.PHAR 

The next time you can start the Windows console ( Win + R keyboard and type cmd.exe ) and type any of your .phar , for example apigen.phar , and then any command, and it will work

 C:\Users\acosonic>apigen.phar help Usage: ... Arguments: command The command to execute command_name The command name (default: "help") Options: --xml To output help as XML --format To output help in other formats (default: "txt") --raw To output raw command help --help (-h) Display this help message. --quiet (-q) Do not output any message. --version (-V) Display this application version. Help: The help command displays help for a given command: php C:\phpdev\phars\apigen.phar help list You can also output the help in other formats by using the --format option: php C:\phpdev\phars\apigen.phar help --format=xml list To display the list of available commands, please use the list command. C:\Users\acosonic> 

Thus, this method allows you to run .phar archives in the directory where you need to work, for example, when creating documentation in C:\myproject\controller without specifying the full path to .phar , as if it were executed without adding it to the Windows path.

To explain what the teams did in step 4:

  1. Display created HKCR.phar → HKCR \ PHARFile
  2. Created by HKCR \ PHARFile \ shell \ open \ command = 'php.exe "% 1"% *' [REG_EXPAND_SZ]
  3. Extended HKCU \ Environment \ PATHEXT = '% PATHEXT%;. PHAR '[REG_EXPAND_SZ]

*.phar processed as a binary file / script, and *.phar works while the *.phar file is somewhere in %PATH% .

+2
source share

All Articles