Installing Composer in a XAMPP Environment on Linux

When you’re working with PHP locally, in an environment such as XAMPP on a Linux operating system, you might need to install Composer. Composer is a tool for dependency management in PHP, allowing you to declare and manage the libraries your project depends on.

The Quick Installation Method

Typically, the quickest way to install Composer on a Linux operating system is through the command line as follows:

sudo apt install composer

This approach might not be appropriate for those who already have XAMPP installed. This is because the command would install PHP system-wide, which is unnecessary here since XAMPP already bundles PHP with its package, making this method redundant in such cases.

The Manual Method

As an alternative, you can opt for a manual installation method, which is what we’ll be diving into for the rest of this article.

Step 1: Download the Composer Installer

First, let’s download the Composer installer using the curl command. curl is a command-line utility that allows you to transfer data over the network. Open a new terminal window and type this command:

curl -sS -o composer-setup.php

The above command downloads the Composer installer from saving it into a file named composer-setup.php.

Step 2: Install Composer

Now, you’ll aim to execute the Composer setup script using PHP and direct the installer to place the Composer executable in the ‘/usr/local/bin’ directory.

sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

But there’s a catch: since the PHP that comes bundled with XAMPP isn’t installed system-wide, this typical installation command would likely not work.

Don’t worry – we have a workaround. Simply replace the php command with the path of PHP that comes packaged with the XAMPP install, which is commonly ‘/opt/lampp/bin/php’:

sudo /opt/lampp/bin/php composer-setup.php --install-dir=/usr/local/bin --filename=composer

The above command tells the system to use PHP in XAMPP to execute the Composer setup script, install Composer to the /usr/local/bin directory, and name the executable as composer.

Step 3: Verify the Installation

Now you have the Composer installed in your XAMPP environment. To ensure everything was set up correctly, you can check the installed version of Composer by running the following command in your terminal:

composer -v

If the system returns the Composer version, congratulations! You’ve successfully installed Composer in a XAMPP environment on your Linux system.

By following these steps, you can bypass redundancy and ensure that your Composer installation appropriately meshes with your XAMPP setup.