What is PHIVE and how it can help us with phar file installation?

Adding all the required tools like PHPUnit, PHPMD and phpDox in their matching versions to a project used to be a lot of repetitive work: Started by finding the download URL, figuring out what the actually correct and matching version is followed by verifying the SHA1 and GPG signatures and making the archive executable. And of course you’d have to repeat this very thing for every tool needed.

Why not just use composer to install phar?

You could have used composer to manage your phar tools installation. Only to clutter your project’s dependencies with the ones of your tools. And fight their potential dependency conflicts. But this is not ideal and should not be necessary for you tu use phar files.

Best way to install phar files

Use PHIVE to install and manage your project’s tooling needs without all the hassle and without cluttered dependencies!

PHIVE supported tools (.phar installation):

Many famous PHP tools can already be installed via PhiVE. Among them the following well known projects:

…. and many more!

Windows installation

To install PHIVE on windows you need to download a phar file and place it in a directory linked in your Windows environment folder. Such as C:/bin. If a directory does not exist, create it and add it to your windows path.

Now make phar file executable so you dont have to type phive.phar and you can use it only as phive from your CMD (see next section).

How to run .phar file without typing extension from CMD in Windows 10 PowerShell

Assuming that you have placed your phive.phar file in a directory listed in your Windows env. Create phive.cmd a file with in the same directory and add the fallowing content:

@php "%~dp0phive.phar" %* 
  • note that there is a space on the end of the line!

Alternatively, you could try to create phive.bat in the same directory (In my case, that will be C:/bin). Add space on the end of the line.

@ECHO OFF
php "c:/bin/phive.phar" %* 

https://stackoverflow.com/questions/22297546/how-to-run-phar-from-anywhere-on-windows

Make phive.phar cmd run as alias phive in bash terminal.

If you use gitbash or cmder with gitbash selected, you will need to create alias for phive.phar command. In git bash alias can be written to ~/.bashrc file.

vim ~/.bashrc

Add the fallowing line alias phive='phive.phar' to the file like in the example below:

alias phive='phive.phar' 
alias wp='wp-cli.phar'      
   
alias phpunit='phpunit.phar'

Install phar tools using PHIVE

phive install phpunit
phive install phpDocumentor

If your CURL has certificate issue: fix it fallowing this tutorial php-curl-issue-with-certificate-solved.

Last thing:
All files are installed to user/tools directory as .bat files, so on Windows you might want to add this path to your ENV variables:

%USERPROFILE%\tools

Because PHIVE auto generate .bat files which will work in PowerShell without extension but will not trigger in git bash, we need to alias .bat file like .phar files, presented in previous section. So we need to add to ~/.bashrc

vim ~/.bashrc

alias phive='phive.phar'  
alias wp='wp-cli.phar'           
alias phpunit='phpunit.bat'
alias phpDoc='phpDocumentor.bat'

Remember to restart your terminal, so it can load the above modification. We can also try to load modification by running:

source ~/.bashrc

If for some reason this will not work, you can always try to define a full path to a .bat file, like this: alias phpunit='/c/Users/USERNAME/tools/phpunit.bat'

You are done! Now you know how to install phar file in Windows10 and in Git Bash terminal.
0
Would love your thoughts, please comment.x
()
x