How to Create composer.json File For PHP Project

Composer is a package dependency management tool. In Composer you can declare the libraries you need them in your project and it will install them. In this post i’ll talk about how to create composer.json file for your project.

In my previous post, i have written what is composer, how to manage package dependency through composer.

How to Create composer.json File

I assume you have composer install on your system. Before creating composer.json file, let’s check it’s schema. Open your terminal and type

It will show you following options.

But don’t worry in composer.json file the key element is require. In which we mention what package we need to install for current project.

You can create composer.json file manually or through command line. Better way is to create composer.json file through command line.

Subscribe Our Tutorials

Get Latest Updates on Facebook

To create composer.json file through command line. Write

Composer.json file is created,now open composer.json file.

I define the package twig and it’s version which i require. After that i run

It will download and install the package mentioned in composer.json file.

To create composer using all the options simply type.

This command will guide you through creating your composer.json config.

Where to Find The Packages

In this article we talk about how to define and install the packages which you want to pull for your project. But where to find these packages. By default composer will look for defined packages on Packagist, it’s online repository. Go on packagist.org , browser the package you need for your project and you will find the require, include this into your composer.json file.

composer.json

WebRewrite

About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.
Tagged , , . Bookmark the permalink.