How To Install COMPOSER in Amazon Linux 2023( Fedora-based )

Composer is an essential dependency manager for PHP, making it easy to manage and install libraries and packages. If you’re using Amazon Linux 2023, which is Fedora-based, here’s a step-by-step guide to get Composer up and running on your system.

Step 1: Update Your Package Manager

Before installing Composer, ensure your package manager is up-to-date. Open your terminal and run:

sudo dnf update -y


This command updates your system to the latest package versions, ensuring you have access to the most recent software and security updates.

Step 2: Install PHP and Dependencies

Composer requires PHP and a few additional extensions. Install them with the following command:

sudo dnf install -y php-cli php-json php-zip curl unzip


This command installs PHP’s command-line interface, JSON and ZIP extensions, and essential utilities like curl and unzip.

Step 3: Download the Composer Installer

Next, download the Composer installer script using curl:

curl -sS https://getcomposer.org/installer -o composer-setup.php


This command fetches the installer script and saves it as composer-setup.php.

Step 4: Verify the Installer’s SHA-384

To ensure the integrity and authenticity of the installer, verify its SHA-384 hash. Fetch the latest hash from Composer’s official website:


HASH="$(curl -sS https://composer.github.io/installer.sig)"
php -r "if (hash_file('sha384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"


If the installer is verified, you’ll see Installer verified. If it’s corrupt, delete the downloaded script and try downloading it again.

Step 5: Install Composer Globally

Run the installer script to install Composer globally:

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


This command installs Composer in /usr/local/bin and names the executable composer, making it accessible system-wide.

Step 6: Clean Up

Remove the installer script as it’s no longer needed:

rm composer-setup.php


Step 7: Verify Installation

Finally, confirm that Composer is installed correctly by checking its version:

composer --version


You should see an output displaying the installed Composer version, indicating a successful installation.

Troubleshooting

If you encounter issues, consider the following:

PHP Installation: Ensure PHP and required extensions are correctly installed.
Network Connectivity: Verify your internet connection for downloading the installer and dependencies.
Permissions: Ensure you have sufficient permissions to write to /usr/local/bin.


Conclusion

Installing Composer on Amazon Linux 2023 is straightforward if you follow these steps. Updating your development environment with tools like Composer enhances productivity and ensures you can manage PHP dependencies efficiently. Happy coding!

Atiqur Rahman

I am MD. Atiqur Rahman graduated from BUET and is an AWS-certified solutions architect. I have successfully achieved 6 certifications from AWS including Cloud Practitioner, Solutions Architect, SysOps Administrator, and Developer Associate. I have more than 8 years of working experience as a DevOps engineer designing complex SAAS applications.

Leave a Reply