How to Create composer.json File For PHP Project

How to create composer.json file for PHP project.

PHP Composer is a cross-platform package dependency manager that manages package dependency in a PHP project. In Composer file, we can mention the dependencies which we need for our project and it will download them. In this tutorial, You are going to learn how to create a composer.json file for your  PHP project.

How to Create Composer.json File for PHP Project

How to Create Composer.json File for PHP Project

If you are not familiar with composer then read my previous tutorial.  What is PHP Composer and how to manage package dependency through composer?

How to Create composer.json File

I assume you have already installed composer on your machine. Before creating a composer.json file, let’s check it’s schema. Open your terminal and type

How to install PHP composer on Mac

It will show you following options.

But don’t worry in a composer.json file the key element is require. In which we mention the package dependency which we need for our project.

Subscribe Our Tutorials

Get Latest Updates on Facebook

You can create a composer.json file manually or through a command line. Let’s create a composer.json file through the command line.

To create a composer.json file through the terminal we use composer init command.

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

In composer file, we have mentioned package dependency and it’s version. After that, run composer install and press enter.

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

To create a composer file using all the options simply type.

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

From Where to Find the Packages Name and Version for Composer

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

composer.json

About WebRewrite

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