PHP Composer Basics

Published on Edited on visitante

Install Composer

On all platforms, you can download and use composer.phar directly. Go to the downloads page and scroll to the "Manual Download" section. The latest version at the time of writing is 1.10.0. You will of course need PHP installed also.

php composer.phar --help

To help with the setup process, you can use a composer setup script. Download this file and name it composer-setup.php:

# You can delete `composer-setup.php` after running
php composer-setup.php
composer --help

In MacOS, you can also use Homebrew to install:

brew install composer
composer --help

In Windows, you have a couple additional options. There is a Windows installer that will setup composer on your PATH. Another Windows option is to use Chocolatey to install:

choco install composer
composer --help

Start a new project

To start a new project, you simply need a composer.json file. You can generate one using the command:

composer init

This will create a composer.json with your project information like name and dependencies. As long as you have a name entry in your composer.json then you can import your project in to other composer projects as a dependency.

1 comment

That's all we have

Nothing yet. Be the first!