Composer is the standard dependency manager for PHP projects. It handles library installation, version resolution, and autoloading so you can pull in third-party packages without manually downloading files or managing include paths. Most PHP frameworks and applications, including Laravel, Symfony, and Drupal, rely on Composer for their dependency workflows. This guide covers how to install Composer on Arch Linux from the official repositories, create and manage a PHP project, configure global tooling, and troubleshoot common issues.
Update Arch Linux Before Composer Installation
Synchronize package databases and upgrade installed packages before installing new software. Arch Linux is a rolling release distribution, so regular updates prevent dependency conflicts:
sudo pacman -Syu
This guide uses
sudofor commands that need root privileges. If your user is not in the sudoers file yet, run the commands as root or follow the guide on how to add and manage sudo users on Arch Linux.
Install Composer on Arch Linux via pacman
Composer is available in the official Arch Linux extra repository. The package installs Composer along with its required dependencies, including PHP and unzip:
sudo pacman -S composer
Pacman resolves dependencies automatically. If PHP is not already installed, this command installs it alongside Composer.
Verify the installation by checking both Composer and PHP versions:
composer --version
Expected output:
Composer version 2.9.5 2026-01-29 11:40:53
Confirm the PHP version that Composer uses:
php --version
Expected output:
PHP 8.5.2 (cli) (built: Jan 14 2026 16:37:32) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.5.2, Copyright (c) Zend Technologies
with Zend OPcache v8.5.2, Copyright (c), by Zend Technologies
Configure Composer Global PATH on Arch Linux
Composer stores globally installed packages in ~/.config/composer/vendor/bin. Add this directory to your shell PATH so you can run global Composer tools without specifying the full path.
Open your shell configuration file:
nano ~/.bashrc
Add this line at the end of the file:
export PATH="$HOME/.config/composer/vendor/bin:$PATH"
Apply the change to your current session:
source ~/.bashrc
If you use Zsh instead of Bash, add the export line to
~/.zshrcand runsource ~/.zshrcto apply the change.
Create a PHP Project with Composer on Arch Linux
Composer manages dependencies on a per-project basis through a composer.json file. This section walks through initializing a new project, adding packages, and generating the autoloader.
Initialize a New Project
Create a project directory and initialize Composer inside it:
mkdir ~/my-php-project && cd ~/my-php-project
composer init --name="vendor/my-project" --description="A sample PHP project" --type=project --no-interaction
Expected output:
Writing ./composer.json
This creates a composer.json file that defines your project metadata and dependency requirements. View the generated file:
cat composer.json
Expected output:
{
"name": "vendor/my-project",
"description": "A sample PHP project",
"type": "project",
"require": {}
}
Add a Package Dependency
Use composer require to add a package from Packagist, the default Composer package repository. This example adds Monolog, a popular PHP logging library:
composer require monolog/monolog
Composer downloads the package and its dependencies into the vendor/ directory and updates composer.json and composer.lock automatically.
List installed packages to confirm:
composer show
Expected output:
monolog/monolog 3.10.0 Sends your logs to files, sockets, inboxes, databases and various web services psr/log 3.0.2 Common interface for logging libraries
Use the Composer Autoloader
Composer generates an autoloader that handles class loading for all installed packages. Include it at the top of your PHP scripts to access any installed library without manual require statements:
<?php
require 'vendor/autoload.php';
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
$log = new Logger('app');
$log->pushHandler(new StreamHandler('app.log', Logger::WARNING));
$log->warning('This is a test warning');
Save this as test.php in your project directory and run it:
php test.php && cat app.log
Expected output:
[2026-02-07T10:04:20.970664+00:00] app.WARNING: This is a test warning [] []
The log entry confirms that Composer autoloading and the Monolog package work correctly.
Manage Composer Dependencies on Arch Linux
After setting up a project, use these commands to keep dependencies current and manage your project lifecycle.
Update Composer Dependencies
Update all packages to their latest versions within the constraints defined in composer.json:
composer update
To update a single package without touching other dependencies:
composer update monolog/monolog
Commit
composer.lockto version control. When collaborators or deployment pipelines runcomposer install, they get the exact same dependency versions recorded in the lock file, ensuring consistent environments across machines.
Install Dependencies from composer.lock
When cloning an existing project or deploying to a new server, use composer install to install the exact versions recorded in composer.lock:
composer install
For production deployments, add the --no-dev flag to skip development dependencies and the --optimize-autoloader flag for faster class loading:
composer install --no-dev --optimize-autoloader
Remove a Package
Remove a package and its unused dependencies from your project:
composer remove monolog/monolog
This updates composer.json, composer.lock, and removes the package files from vendor/.
Install Global Composer Packages
Install development tools globally so they are available system-wide. For example, install the PHP CS Fixer code formatting tool:
composer global require friendsofphp/php-cs-fixer
With the global PATH configured in the previous section, run the tool directly:
php-cs-fixer --version
Arch Linux ships the latest PHP version, which some tools may not officially support yet. If
php-cs-fixerreports a PHP version error, setPHP_CS_FIXER_IGNORE_ENV=1before running the command. Check the tool’s GitHub repository for PHP version compatibility updates.
To list all globally installed packages:
composer global show
Expected output (packages vary based on what you installed):
friendsofphp/php-cs-fixer 3.x.x A tool to automatically fix PHP coding standards issues psr/log 3.0.2 Common interface for logging libraries symfony/console 7.x.x Eases the creation of beautiful and testable command line interfaces ...
Troubleshoot Composer on Arch Linux
PHP Memory Limit Exhausted During Composer Operations
Error: PHP Fatal error: Allowed memory size of XXXXX bytes exhausted
Cause: Large dependency trees can exceed PHP’s default memory limit, especially during composer update on complex projects.
Fix: Override the memory limit for the current Composer command:
COMPOSER_MEMORY_LIMIT=-1 composer update
The -1 value removes the memory limit for that single command. To set a permanent higher limit, edit /etc/php/php.ini and increase the memory_limit value:
sudo sed -i 's/memory_limit = .*/memory_limit = 512M/' /etc/php/php.ini
Composer SSL Certificate Error
Error: The "https://packagist.org/packages.json" file could not be downloaded: SSL operation failed
Cause: PHP cannot find or verify SSL certificates. This commonly occurs when the openssl extension is misconfigured or CA certificates are missing.
Fix: Verify that the ca-certificates package is installed and current:
sudo pacman -S ca-certificates
Check that PHP’s openssl.cafile points to the correct certificate bundle:
php -i | grep openssl.cafile
Expected output when configured correctly:
openssl.cafile => /etc/ssl/certs/ca-certificates.crt => /etc/ssl/certs/ca-certificates.crt
If the value is empty or shows no value, set it in /etc/php/php.ini:
openssl.cafile = /etc/ssl/certs/ca-certificates.crt
Run composer diagnose to confirm Composer can connect to Packagist:
composer diagnose
If the SSL issue is resolved, the output includes:
Checking http connectivity to packagist: OK Checking https connectivity to packagist: OK
Composer Command Not Found After Installation
Error: bash: composer: command not found
Cause: The composer binary is installed to /usr/bin/composer by pacman. If this error occurs, the /usr/bin directory may be missing from your PATH, or the package did not install correctly.
Fix: Verify the package is installed and check the binary location:
pacman -Qi composer
which composer
If the package is installed correctly, pacman -Qi displays package details and which returns /usr/bin/composer. If pacman reports the package is not found, reinstall it:
sudo pacman -S composer
Composer Dependency Conflict During Update
Error: Your requirements could not be resolved to an installable set of packages
Cause: Two or more packages require incompatible versions of the same dependency.
Fix: Identify the conflict using the why command to trace which packages depend on the conflicting library:
composer why psr/log
Expected output:
monolog/monolog 3.10.0 requires psr/log (^2.0 || ^3.0)
Review the version constraints in composer.json and adjust them to allow a compatible range. If the conflict stems from outdated packages, update them individually:
composer update --with-dependencies monolog/monolog
Remove Composer from Arch Linux
Remove Composer and its orphaned dependencies with pacman:
sudo pacman -Rns composer
The -Rns flags remove the package (-R), orphaned dependencies (-s), and configuration backup files (-n).
This command removes only the Composer package. If PHP was installed as a dependency and no other package requires it, pacman removes it as well. If PHP was installed explicitly before Composer, it remains on the system.
Verify removal:
pacman -Qi composer
error: package 'composer' was not found
Pacman does not remove Composer’s global configuration or cached files. Clean up the Composer directory in your home folder:
This permanently deletes all globally installed Composer packages, authentication tokens, and cached package archives. Back up
~/.config/composer/auth.jsonfirst if you use private repository credentials.
rm -rf ~/.config/composer
Project-level
vendor/directories andcomposer.jsonfiles remain in their respective project folders. Remove them individually if you no longer need those projects.
Frequently Asked Questions About Composer on Arch Linux
composer install reads the composer.lock file and installs the exact versions recorded there, ensuring consistent environments across machines. composer update resolves the latest versions allowed by the constraints in composer.json, downloads them, and rewrites composer.lock. Use install for deployments and CI pipelines, and update during development when you want newer package versions.
Yes. The Composer package in the Arch Linux extra repository lists php as a dependency. If PHP is not already installed, pacman installs it automatically when you run sudo pacman -S composer. The unzip package is also installed as a dependency for extracting package archives.
Since Composer is installed through pacman, it updates alongside other system packages when you run sudo pacman -Syu. Do not use composer self-update when Composer is managed by the system package manager, as it would conflict with pacman’s file tracking.
Composer stores global configuration and packages in ~/.config/composer on Arch Linux. Globally installed package binaries are placed in ~/.config/composer/vendor/bin. Add this directory to your shell PATH to run global tools directly from the command line.
The Composer package from the official repositories depends on the php package (latest branch). To use Composer with php-legacy, you can set the COMPOSER_PHP environment variable or create a project-level platform configuration in composer.json to target a specific PHP version for dependency resolution.
Conclusion: Composer on Arch Linux
You now have Composer installed on Arch Linux with PHP dependency management ready for project development. From here, explore the Composer documentation for advanced features like custom repositories and scripts. For PHP configuration, extensions, and PHP-FPM setup, refer to the guide on how to install PHP on Arch Linux. If your PHP projects require a database backend, see the guides on how to install MariaDB on Arch Linux or how to install PostgreSQL on Arch Linux.
Formatting tips for your comment
You can use basic HTML to format your comment. Useful tags currently allowed:
<code>command</code>command<strong>bold</strong><em>italic</em><a href="URL">link</a><blockquote>quote</blockquote>