How to Run .phar Files

Couple days ago, when I working on a web project for some developer company. They ask me if I can tell them how to create API documentation like the one I use in my own framework. By API documentation, I mean like this one

MangaReadDocs
My personal project 🙂

They know that I use apigen to generate the documentation but they don’t know how to use it since it not an executable file like exe or bat which you can just run on click.

I know there is a documentation on how to use it. In the documentation, it says that there is 2 way to run which you can do with an ease, one with composer and one with .phar. But it seems that they are not clear enough for a people that aren’t familiar with it.

In this post, I will only write about how to use .phar since it mostly pretty simple. And it’s not specifically only for apigen but you can do this with other .phar file too.

What is .phar file?

PHAR (PHP Archive) as the name suggest is an archive file which contains PHP application in single file. Usually, PHP application always has multiple files which you must copy all of them if you want to run the application.

This can be inconvenient since missing one file mean your application can’t work properly or even won’t run at all. To fix this, we can use PHAR file to combine all our PHP files into one file with extension .phar.

Different from general archive file like .rar, .zip or .7z which you must extract the file first before you can run the file inside it, you can just run your PHP application without extracting the phar file.

So, in short it will make your life easier.

Requirements

PHP

First, you must have PHP installed on your PC. If you are on windows, you can use web server package like xampp or wamp. Either way, you must have it installed and it can be used to run a PHP website.

But be careful, some people tell me that some web server can’t work or can’t recognize a .phar file.

And that all the requirement as far as I’m aware. You don’t even need the web server, as long as you can run PHP.

Running PHAR file

It’s simple, really. You just need to run your .phar file using PHP. Like this:

Yeah, just like that. Easy right?

That it for now. If you have any question or suggestion, you can ask me in the comment bellow. Have a good day!

Want more like this one?

htaccess for Friendly URL on Web Have you ever wonder how to change your website URL to be more friendly and pretty one? Like for example, you can see at this site, I use URL like thi...
Avoiding SQL Injection in PHP Recently, I'm reviewing some web project that made using PHP. It nice website, responsive and can support both PC and mobile display. But, it seems th...
Regular Expression Online Tester If you are working on your own Regular Expression or Regex/Regexp in short, you may often found that it pretty confusing to make one by yourself. You ...
Is IFTTT Useful? IFTTTT or "If This Then That" is web base service application that allow you to create conditional action automatically called recipe that will do an ...