Installing Composer
A complete guide to getting Composer up and running on your server.
Composer is the de facto dependency manager for PHP. It takes the pain out of managing third-party libraries — whether you're working with Symfony, Laravel, PHPUnit, Guzzle, or any of the thousands of packages available on Packagist. If you're building a modern PHP application, Composer is non-negotiable.
Prerequisites
- Connect to your server via SSH (PuTTY on Windows, or your terminal on Linux/macOS).
- Make sure PHP is installed and up to date (version 7.2.5 or higher):
php -v
- Install
curlandgitif they aren't already present:
sudo apt update
sudo apt install curl git -y # Ubuntu/Debian
# or
sudo yum install curl git -y # CentOS/Rocky/AlmaLinux
Installation
- Navigate to a directory on your system's PATH —
/usr/local/binis a solid choice:
cd /usr/local/bin
- Download and run the Composer installer in one go:
sudo curl -sS https://getcomposer.org/installer | php
If curl isn't cooperating, you can do this the manual way:
sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
sudo php composer-setup.php
sudo rm composer-setup.php
- Rename the file and make it executable so you can call it from anywhere:
sudo mv composer.phar composer
sudo chmod +x composer
Getting started with a project
- Head to your project root:
cd /var/www/my-project
- Scaffold a new
composer.jsonby running the interactive initializer:
composer init
- Install all declared dependencies:
composer install
- Pull in a package — here's an example with the Guzzle HTTP client:
composer require guzzlehttp/guzzle
- Upgrade everything to the latest compatible versions:
composer update
Handy commands to know
| What you want to do | Command |
|---|---|
| List installed packages | composer show |
| Update a single package | composer update vendor/package |
| Remove a package | composer remove vendor/package |
| Clear the cache | composer clear-cache |
| Install without cache (great for debugging) | composer install --no-cache |
Help
If you have any questions or need assistance, please contact us through the ticket system — we're always here to help!