Table of Contents

If you have written code in PHP language, you may have found that you have to perform common tasks repeatedly from scratch, such as request routing and database management. Of course, we have different frameworks such as Laravel, Zend, and Symfony to solve this problem, but what if you want to pick and choose the pieces from each framework?

To achieve that, you require many dependencies for each framework which makes things very difficult. This is where Composer comes to the rescue.

By default, all new Cloudways servers have Composer 2 installed. In this article, you will learn how to use and install Composer 1 simultaneously.

What is Composer?

Composer is an open-source and cross-platform dependency manager for PHP. It is a tool used to automate the download of packages, manage and integrate external packages and libraries into PHP-based projects. For example, Composer will pull in all the required dependencies and libraries and manage them all in one place.

How to Install and Use Composer 1

To reiterate, Composer 2 comes pre-installed with your new Cloudways server. However, if you also want to use Composer 1 simultaneously, you can install it with the help of the following steps.

Step #1 — Connect to Your Server Remotely

  1. First, connect to your server by building an SSH connection using Master credentials.

  2. Next, navigate to the folder where you want to install Composer. We are installing it in the "/home/master/" directory in our example. With Master credentials, you will automatically land in the "/home/master/" directory.

Step #2 — Download Composer 1

  1. Download the latest version of Composer 1 from the official website using the following command:

    wget https://getcomposer.org/download/1.10.23/composer.phar

  2. Now, you have a composer.phar file in this directory. Next, allow the execute permissions using the following command.

    chmod +x  composer.phar

  3. Next, rename the file from composer.phar to composer.

    mv composer.phar composer

Step #3 — Use Composer

Here's how you can test Composer 1 and Composer 2.

Composer 1:

You can test Composer 1 and its installed version name using the following command.

/home/master/composer -v

Here, "/home/master/composer" represents the Composer 1 installation directory which you need to include in every command when you want to use Composer 1.

Composer 2:

Composer 2 comes pre-installed with your new Cloudways server, so you can start using it without any installation. For example, an easy command to test Composer 2 and its installed version name is:

composer -v

Optional — Update Dependencies

Finally, you need to know how to update your packages in Composer. There are two methods to update your packages; the first method is Universal update, and the second method is Package-specific update.

  1. Universal update: It checks and installs updates for all of your dependencies and packages at once.

  2. Package-specific update: It checks and installs updates for one or more packages you specifically define.

Composer 1:

Universal update:

/home/master/composer update

Package-specific update:

/home/master/composer update vendor/package

#Be sure to replace the "vendor/package" with the actual package name you wish to update.

Composer 2:

Universal update:

composer update

Package-specific update:

composer update vendor/package

#Be sure to replace the "vendor/package" with the actual package name you wish to update.

Now you are all set to create projects in PHP using Composer. Composer has become the de facto standard for managing PHP project dependencies. As a result, developers can easily integrate and manage open source packages in a single place.

That’s it! We hope this tutorial was helpful. If you need any help, then feel free to search your query on Cloudways Support Center or contact us via chat (Need a Hand > Send us a Message). Alternatively, you can also create a support ticket.

Did this answer your question?