Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run .phar from anywhere on Windows?

Tags:

php

windows

I have .phar file and i want to run it from anywhere with this command.

php file.phar --options

where file.phar is in C:\my-php-cli\file

like image 218
vee Avatar asked Mar 10 '14 10:03

vee


3 Answers

That is not possible. For example, putting file.phar to C:\Windows\System32 and calling php file.phar --options from another directory like C:\Temp will produce

Could not open input file: file.phar

You have to create a small batch file next to your *.phar, e.g., run-file.bat with this contents:

@ECHO OFF
php %~dp0file.phar %*

Then, calling run-file will execute your file.phar.

like image 111
Borek Bernard Avatar answered Oct 06 '22 12:10

Borek Bernard


For Windows 10 I found that you need a your-file.cmd to run the .phar file.

I was trying to get php-cs-fixer running so in my PHP directory i had the following:

PHP\
    phpFixer\
        php-cs-fixer.phar
        php-cs-fixer.cmd

Contents of php-cs-fixer.cmd:

@php "%~dp0php-cs-fixer.phar" %* 

verified it works by entering this in command line:

php-cs-fixer --version
PHP CS Fixer 2.14.0 Sunrise by Fabien Potencier and Dariusz Ruminski (b788ea0)

Hope that helps

like image 45
modnarrandom Avatar answered Oct 06 '22 10:10

modnarrandom


You would need to add the folder containing file.phar to your path variable.

See this link for more information.

like image 35
Cjmarkham Avatar answered Oct 06 '22 11:10

Cjmarkham