How to Create And Use Phar Archive

Prem Tiwari - - PHP Tutorial, php7

In this tutorial, I will explain how to create and use a Phar archive file in PHP your application. Phar archives are similar as JAR archives in JAVA. It is tailored to the flexibility of PHP applications.

The Phar archive is used to create a library from a bundle of PHP codes and it is also used to distribute a complete application or library in a single file.

php phar tutrial

How to create Phar archive

If you have a bundle of PHP codes or PHP library and you want to create a Phar archive, then follow the below steps:

Step 1) Open php.ini file and search the “;phar.readonly” directive, and replace it with “phar.readonly = 0”. After this restart your web server. Now you are ready to create a Phar file of your application OR Library folders.

Step 2) Create a folder named “sample” and create an index.php file inside that folder. Now copy paste below code in index.php file and open your web browser to create a project.Phar archive.

How to use Phar archive

Now you can use your Phar archive in any application. Phar archive supports read and writes operations on both files and directories/subdirectories. Below is the example how to use Phar archive in your PHP page.

Over to You

The Phar archive will save you from lots of hassle in packaging and deploy your web applications. I recommend you to using it in your web applications. Do you like & share this article with your friends, and don’t forget to follow us on Facebook and Twitter to learn cool tutorials.

Prem Tiwari

Prem Tiwari is the founder of and also a professional developer and a blogger by hobby.

Tags: , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.