How to Create And Use Phar Archive

| Last Updated: | In: Core php, 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.

Tags: , , , ,


About: Prem Tiwari

Prem Tiwari is the founder of freewebmentor.com and is a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby.


You may also like:

Follow us!

Get Free Access of 380+ Scripts

Don't worry you'll not be spammed!

Featured eBook

WordPress Security Guide

Free Guide: Learn how to implement security guideline in your WordPress site...

DOWNLOAD

Pincode Finder

pincode-finder tool

Online Pincode Finder

Best tool to locate post Office address and pincodes of all india...

SEARCH NOW
Copyright © 2013-2017