GET A QUOTE

Composer in PHP: Installing on Ubuntu & Use case

Composer is an application package management tool which is used only for PHP language. It provides standard format of library structure with dependencies of PHP version. We can also called it library provider. It’s also used for dependencies manager for PHP.

Installation Steps:

First check composer is already installed on the system or not,

Steps to check:-

-> Go to command prompt

Type command “composer

=> You can find output like below. If you get the result like below it means composer is already installed in your system.

Composer is Not Installed:-

=> If your system has not installed composer, then output will be like below.

If the system doesn’t have Composer, then first install composer

Steps to install Composer:-

1) Update your system first, to update your system use below commands in terminal.

=> sudo apt-get update
=> sudo apt-get upgrade

2) Install composer using below command and check composer installed or not …

=> curl -sS https://getcomposer.org/installer | sudo php — –install-dir=/usr/local/bin –filename=composer

Once the command runs successfully, the composer is installed on the system.

3) Now, check again composer installed or not, using command => “composer”

Composer installation is done now. Now you can use composer for installation of your modules.

What is the Use of Composer?

 

What is the use of composer in any project?

-> Composer manage dependencies of PHP on it’s own, so the developer doesn’t have to worry about different version dependencies. This composer concept is not new, in fact it is inspired by NPM NodeJS. Composer is good for code reusability. Maintain dependencies of whole project.

How to use Composer in your project?

-> For composer use in your project. There are 2 main requirements

1) Composer should be installed on the system
2) In the project folder composer.json file must be available.

-> In the project folder in command prompt and run command “composer install”.

If composer.json file is not there, then you can directly install your library using command “composer require “{Package Name}”” Package name Like :” paypal/rest-api-sdk-php:*””. It will auto generate composer.json file in the system.

After installing the packages, check the project folder. It should have created one new folder, named with “vendor”. Folder name is permanent, and it will move all packages which were installed in the project to vendor folder. Inside the vendor folder you can see “autoload.php” file.

Autoload file will be helpful in the projects. You can include autoload.php file in your code file and get access to any package by class name to get it work.

In your project using below steps:

-> mkdir “Project name”
-> cd Project name
-> Run composer command “composer require “paypal/rest-api-sdk-php:*””

Note: This command will create new composer.json and composer.lock file and vendor folder that includes all the dependency and library files of the installed packages.

-> Autoload.php file is in vendor folder. Use the file name (autoload.php) in your regular file and get access with class name of the packages.

Please share your thoughts, questions on this article. If you need further assistance, in installing composer on Ubuntu, please don’t hesitate to contact us.

cmsMinds is a web development agency based in Raleigh, NC. Apart from helping on cms projects, we have expertise on custom web development using PHP. If you need help with one of your existing projects or architecting a new application one of our team members can definitely help you with the road map.

One thought on “Composer in PHP: Installing on Ubuntu & Use case

Leave a Reply

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

Quick Inquiry


captcha