How to Install and use PHP Composer on Debian 13
Composer is a dependency manager for the programming language, PHP. It functions as some sort of project manager that helps the programmer manage dependencies that will be used on a project-to-project basis.
Installing Composer on Debian 13
First, need to check for any pending system updates,
apt update
apt upgrade
Install the required packages.
apt install wget php-cli php-zip unzip
Download the composer installer file.
wget -O composer-setup.php https://getcomposer.org/installer
Output:
root@server:~# wget -O composer-setup.php https://getcomposer.org/installer
--2025-07-31 01:21:11-- https://getcomposer.org/installer
Resolving getcomposer.org (getcomposer.org)... 57.128.19.244, 2001:41d0:304:300::18ef
Connecting to getcomposer.org (getcomposer.org)|57.128.19.244|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 58444 (57K) [application/octet-stream]
Saving to: ‘composer-setup.php’
composer-setup.php 100%[===================>] 57.07K --.-KB/s in 0.01s
2025-07-31 01:21:12 (5.18 MB/s) - ‘composer-setup.php’ saved [58444/58444]
To install Composer globally inside the /usr/local/bin directory by running the following command.
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
Output:
root@server:~# php composer-setup.php --install-dir=/usr/local/bin --filename=composer
All settings correct for using Composer
Downloading...
Composer (version 2.8.10) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer
If a new Composer version is available, update the package by running the following command.
composer self-update
Use Composer in PHP Project
mkdir ~/my-first-composer-project
cd ~/my-first-composer-project
Initialize a new composer.json and install the carbon package by running the following command.
composer require nesbot/carbon
Output:
root@server:~/my-first-composer-project# composer require nesbot/carbon
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? yes
./composer.json has been created
Running composer update nesbot/carbon
Loading composer repositories with package information
Updating dependencies
Lock file operations: 9 installs, 0 updates, 0 removals
- Locking carbonphp/carbon-doctrine-types (3.2.0)
- Locking nesbot/carbon (3.10.1)
- Locking psr/clock (1.0.0)
- Locking symfony/clock (v7.3.0)
- Locking symfony/deprecation-contracts (v3.6.0)
- Locking symfony/polyfill-mbstring (v1.32.0)
After the installation is complete, you can see that Composer created two files composer.json and composer.lock along with a vendor directory.
ls -l
Output:
root@server:~/my-first-composer-project# ls -l
total 36
-rw-rw-r-- 1 root root 60 Jul 31 01:22 composer.json
-rw-rw-r-- 1 root root 25226 Jul 31 01:22 composer.lock
drwxrwxr-x 8 root root 4096 Jul 31 01:22 vendor
Create a new file named testing.php and paste the following content.
<?php
require __DIR__ . '/vendor/autoload.php';
use Carbon\Carbon;
printf("Now: %s", Carbon::now());
Run the script by running the following command.
php testing.php
Output:
root@server:~/my-first-composer-project# php testing.php
Now: 2025-07-31 05:24:34root@server:~/my-first-composer-project#
Next, if you want to update the package then you can use the following command.
composer update
Output:
root@server:~/my-first-composer-project# composer update
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? yes
Composer is operating significantly slower than normal because you do not have the PHP curl extension enabled.
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Writing lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Generating autoload files
8 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found.
Done!
CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME for 10% off!
1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month
Available Locations: LAX | MIA | ATL | FRA | AMS