How To Install Composer on Rocky Linux 8

Published on  

15 min read

Looking for other version?

Choose a different version or distribution.

How To Install Composer on Rocky Linux

Learn how to install Composer on Rocky Linux 8 in this comprehensive guide. Composer is a powerful dependency management tool for PHP projects. Follow our step-by-step instructions to set up Composer, configure optional settings, and verify the installation.

Introduction

Are you a PHP developer looking for an efficient way to manage your project's dependencies? Look no further! Composer is here to save the day. Composer is a powerful dependency manager for PHP that simplifies the process of handling external libraries and packages. In this step-by-step guide, we will walk you through the process of installing Composer on Rocky Linux 8, enabling you to streamline your PHP development workflow.

At its core, Composer serves as the backbone for PHP projects, allowing developers to easily integrate third-party libraries, frameworks, and tools into their applications. With Composer, you can effortlessly manage and resolve dependencies, ensuring that your project has the required packages and versions it needs to run smoothly.

This comprehensive guide will equip you with the knowledge and instructions needed to install Composer on Rocky Linux 8. Whether you're a seasoned developer or just starting with PHP, this guide will provide you with a solid foundation to leverage the power of Composer.

So, let's dive into the installation process and unlock the potential of Composer for your PHP projects on Rocky Linux 8.

But before we get started, let's ensure that you have everything you need to proceed smoothly.

Prerequisites

Before we jump into the installation process, let's take a moment to ensure that you have met the necessary prerequisites:

  • Rocky Linux 8: Ensure that you have a clean installation of Rocky Linux 8. If you haven't installed it yet, you can follow the official Rocky Linux installation guide to get up and running.
  • PHP 5.3.2 or later installed
  • User privileges: root or non-root user with sudo privileges

Now that you have the required prerequisites in place, let's move on to the first step: updating your system packages.

Updating System Packages

To ensure a smooth installation process and compatibility with the latest software, it's essential to update your system packages before installing new software. Updating your system packages ensures that you have the latest security patches, bug fixes, and improvements.

To update your system packages on Rocky Linux 8, follow these simple steps:

  1. Open a terminal or connect to your Rocky Linux 8 instance via SSH.
  2. Run the following command to update the system packages using the package manager:
sudo dnf update -y

The -y flag ensures that any prompts during the update process are automatically confirmed.This command will fetch the latest updates from the Rocky Linux repositories and install them on your system.

With your system packages updated, you're now ready to proceed with the installation of Composer on Rocky Linux 8. The next step is to install the necessary dependencies.

Installing Dependencies

Before we can install Composer on Rocky Linux 8, there are a few dependencies that need to be installed. These dependencies ensure that Composer functions properly and can manage your project's dependencies effectively.

To install the required dependencies, follow these steps:

  1. Open a terminal on your Rocky Linux 8 system.
  2. Execute the following command to install the necessary dependencies using the package manager:
sudo dnf install -y wget php-cli php-zip php-json

This command instructs the package manager to install the dependencies wgetphp-cli, php-zip, and php-json. These dependencies are essential for Composer to operate smoothly.

  • wget: Wget is a command-line utility for downloading files from the web. We need it to retrieve the Composer installation script.
  • php-cli: Php-cli is the command-line interface for PHP. Composer relies on PHP to execute its commands.
  • php-zip: Php-zip provides the necessary functionality to manage ZIP files, which Composer uses to handle package archives.
  • php-json: Php-json enables the manipulation and processing of JSON data, a common format used in Composer configuration files.

By installing these dependencies, you're ensuring that Composer has all the tools it needs to manage your PHP project's dependencies effectively.

With the dependencies successfully installed, we can now move on to the next step: downloading the Composer installation script.

Downloading Composer

In order to install Composer on Rocky Linux 8, we need to download the Composer installation script. This script will set up Composer on your system and make it ready to use.

To download the Composer installation script, follow these steps:

  1. Open a terminal on your Rocky Linux 8 system.
  2. Execute the following command to download the Composer installation script:
sudo wget -O /usr/local/bin/composer https://getcomposer.org/download/latest-stable/composer.phar

This command uses wget to fetch the Composer installation script from the official Composer website. It saves the script as composer.phar in the /usr/local/bin directory.

  • /usr/local/bin: This directory is commonly used to store executable files that are accessible system-wide. By placing the Composer script here, we ensure that it can be executed from anywhere in the system.

Now that the Composer installation script is downloaded, we need to make it executable so that we can install Composer on Rocky Linux 8. Let's proceed to the next step: making the Composer installation script executable.

Verifying the Download

Before we proceed with installing Composer on Rocky Linux 8, it's important to verify the integrity of the downloaded installation script. Verifying the download ensures that the Composer installation script hasn't been tampered with and is safe to use.

To verify the integrity of the Composer installation script using SHA-384 checksums, follow these steps:

  1. Open a terminal on your Rocky Linux 8 system.
  2. Execute the following command to download the Composer installation script checksums:
sudo wget -O /tmp/composer-installer.sig https://composer.github.io/installer.sig

This command downloads the checksum file installer.sig from the official Composer GitHub page and saves it as /tmp/composer-installer.sig.

Then, verify the checksum of the downloaded installation script by running the following command:

sudo sha384sum -c /tmp/composer-installer.sig --ignore-missing

This command calculates the SHA-384 checksum of the downloaded Composer installation script and compares it with the checksum provided in the installer.sig file. The --ignore-missing flag is used to suppress any warnings for missing checksum files.

If the checksum verification is successful, you will see a message indicating that the installation script is valid and hasn't been tampered with.

Note: If the checksum verification fails, it's advisable to re-download the Composer installation script and repeat the verification process.

By verifying the integrity of the Composer installation script, you can ensure the authenticity and reliability of the file. Once the script's integrity is confirmed, you can proceed with the installation process in the next section.

Installing Composer

Now that we have the Composer installation script downloaded and verified, we can proceed with installing Composer on Rocky Linux 8. This step will make Composer available as a command-line tool on your system.

To install Composer on Rocky Linux 8, follow these steps:

  1. Open a terminal on your Rocky Linux 8 system.
  2. Execute the following command to make the Composer installation script executable:
sudo chmod +x /usr/local/bin/composer

This command grants the necessary execution permissions to the Composer installation script.

Next, run the following command to install Composer:

sudo composer

The installation process will start, and Composer will be installed on your system. The script will automatically download and set up the required files and directories.

After the installation completes, you should see output similar to the following:

   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/

Composer version 2.5.7 2023-05-25 16:31:20

This output confirms that Composer has been successfully installed on Rocky Linux 8.

To ensure that Composer is globally accessible, run the following command:

sudo ln -s /usr/local/bin/composer /usr/bin/composer

This command creates a symbolic link from /usr/local/bin/composer to /usr/bin/composer. It allows you to run Composer from any directory in the system.

Congratulations! You have now successfully installed Composer on Rocky Linux 8. In the next section, we will explore optional configurations that can be useful for customizing Composer according to your preferences and requirements.

Configuring Composer

After successfully installing Composer on Rocky Linux 8, you have the option to configure it based on your specific needs and preferences. Configuring Composer can enhance your workflow and optimize package management for your PHP projects.

Here are a few optional configurations you can consider:

Environment Variables

Setting up environment variables for Composer can provide additional flexibility and customization options. Environment variables allow you to define specific values that Composer will use during its execution.

To configure environment variables for Composer, follow these steps:

  1. Open a terminal on your Rocky Linux 8 system.
  2. Execute the following command to open the .bashrc file in a text editor:
nano ~/.bashrc

In the .bashrc file, add the following line at the end:

export COMPOSER_HOME="$HOME/.composer"

This line sets the COMPOSER_HOME environment variable, specifying the location where Composer will store its files and cache.

Save and exit the text editor. To do so in Nano, press Ctrl + X, then press Y to save the changes, and finally press Enter to confirm the file name.

To apply the changes, run the following command:

source ~/.bashrc

This command reloads the .bashrc file, making the environment variable available for the current session.

Proxy Configuration

If you are behind a proxy server, you may need to configure Composer to use the proxy settings to access external resources and packages. To set up proxy configuration for Composer, follow these steps:

  1. Open a terminal on your Rocky Linux 8 system.
  2. Execute the following command to set the proxy configuration:
composer config -g --unset repos.packagist
composer config -g repositories.packagist composer https://packagist.org
composer config -g --unset http-proxy
composer config -g --unset https-proxy
composer config -g --unset github-domains
composer config -g --unset gitlab-domains
composer config -g --unset bitbucket-oauth
composer config -g --unset gitlab-token
composer config -g --unset http-basic
composer config -g --unset repos.packagist.org
composer config -g --unset repos.php.net
composer config -g --unset repos.drupal.org
composer config -g --unset repos.wordpress.org

These commands remove any existing proxy configurations for Composer, ensuring a clean setup.

Note: Replace https://packagist.org with the appropriate URL if you are using a different package repository.

If your proxy requires authentication, run the following command to configure the username and password:

composer config -g http-basic.proxy_username your_proxy_username
composer config -g http-basic.proxy_password your_proxy_password

Replace your_proxy_username and your_proxy_password with your actual proxy credentials.

With the optional configurations in place, you can now enjoy a customized and personalized experience with Composer. In the next section, we will verify that Composer has been successfully installed on Rocky Linux 8.

Verifying the Installation

Once you have installed and configured Composer on Rocky Linux 8, it's crucial to verify that the installation was successful. Verifying the installation ensures that Composer is fully functional and ready to manage your PHP project dependencies.

To verify the Composer installation, follow these steps:

  1. Open a terminal on your Rocky Linux 8 system.
  2. Run the following command to display the version of Composer installed:
composer --version

This command will output the Composer version installed on your system, confirming that the installation was successful. The output should be similar to the following:

Composer version 2.5.7 2023-05-25 16:31:20

If you see the Composer version along with the installation timestamp, it means that Composer is correctly installed on your Rocky Linux 8 system.

Congratulations! You have successfully installed and verified Composer on Rocky Linux 8. In the final section of this guide, let's recap the steps covered and highlight the importance of Composer in managing PHP project dependencies.

Updating Composer

Keeping Composer up-to-date is essential to ensure you have access to the latest features, bug fixes, and security patches. Regularly updating Composer will enhance your PHP project management experience and ensure compatibility with the latest package versions.

To update Composer on Rocky Linux 8, follow these steps:

  1. Open a terminal on your Rocky Linux 8 system.
  2. Execute the following command to update Composer to the latest version:
sudo composer self-update

This command instructs Composer to check for updates and install the latest version if available. The self-update command ensures that Composer updates itself to the newest release.

After the update process completes, you should see output similar to the following:

Updating to version <latest_version> (stable channel).
Downloading (100%)...

The output will display the version of Composer you have updated to.

By regularly updating Composer, you can take advantage of new features, improvements, and bug fixes, ensuring the smooth operation of your PHP projects.

Conclusion

In this comprehensive guide, we have covered the step-by-step process of installing Composer on Rocky Linux 8. Composer is a powerful dependency management tool that streamlines PHP project development by handling package installations and dependencies effortlessly.

We started by discussing the importance of Composer in PHP development and provided an overview of the purpose of this guide. We then covered the prerequisites, ensuring that your system meets the requirements for installing Composer.

Next, we explained the process of updating system packages to ensure a clean installation. We then proceeded to install the necessary dependencies for Composer to function properly.

Moving forward, we covered the steps to download the Composer installation script from the official website and verified its integrity using SHA-384 checksums. We then installed Composer on Rocky Linux 8, making it accessible as a command-line tool.

We explored optional configurations such as setting environment variables and configuring proxy settings, allowing you to customize Composer based on your preferences and requirements.

Finally, we verified the installation to confirm that Composer was successfully installed and discussed the importance of keeping Composer up-to-date. We emphasized the significance of Composer in managing PHP project dependencies and encouraged you to explore the vast ecosystem of Composer packages and resources.

About the Author

Rexposed Staff

Was this helpful?