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.
Note:
If your application uses a different PHP version than the server default (Cloudways Flexible with application-level PHP versions), Composer may run on the wrong PHP version when you connect as the master user. Connect as the application user or use the full PHP path. See Running Composer and Other CLI Commands Over SSH.
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
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
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
Now, you have a composer.phar file in this directory. Next, allow the execute permissions using the following command.
chmod +x composer.phar
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
Using a different PHP version for your application? Run Composer with the full PHP path, replacing 8.4 with your application’s version:
/usr/bin/php8.4 /usr/local/bin/composer install
To find your application’s PHP version, see Running Composer and Other CLI Commands Over SSH. The full-path form also works with Composer 1 (/home/master/composer) in the same way.
If your application uses a different PHP version than the server default, see “Run Composer with Your Application’s PHP Version” below.
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.
Universal update: It checks and installs updates for all of your dependencies and packages at once.
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.
Run Composer with Your Application’s PHP Version
Each application on your server can run its own PHP version, but commands run over SSH use the server-level PHP CLI version, which is PHP 8.2 by default and cannot be changed. If your application requires a different PHP version, Composer may fail to install dependencies or report version-compatibility errors.
To avoid this, run Composer with the PHP binary that matches your application’s PHP version.
Step #1 — Check your application’s PHP version
In the Cloudways Platform, go to Applications > select your application > Application Settings > PHP Settings, and note the PHP version.
Step #2 — Run Composer with the matching PHP binary
Connect to your server via SSH, go to your application folder, and call the versioned PHP binary explicitly:
cd /home/master/applications/APP_FOLDER/public_html php8.3 $(which composer) install
Replace php8.3 with your application’s PHP version (for example, php8.4) and APP_FOLDER with your application folder name.
Alternative methods
Use the full Composer path (run
which composerto confirm it):
php8.3 /usr/local/bin/composer install
Use the application-specific PHP wrapper:
/home/master/applications/<your_app_user>/.cw/bin/php /usr/local/bin/composer install
Replace <your_app_user> with your application username.
If you installed Composer 1 as described above, run it the same way:
php8.3 /home/master/composer install
The same approach works for update and other Composer commands.
Note: If you recently changed your application’s PHP version or created new application credentials, close your SSH session and open a new one.
Common issues
Composer still fails or uses the wrong PHP version: Make sure you are using the versioned binary (such as
php8.3), not plainphp, and that the version matches your application setting.$(which composer)returns empty or the command isn’t recognized: Type the command exactly as shown, including$( ). Alternatively, runwhich composeron its own and use the returned path directly.
Troubleshooting
Composer reports that dependencies require a different PHP version?
Composer is probably running on the server’s default PHP version instead of your application’s.
This happens when you connect as the master user. Connect as the application user or run Composer with the full PHP path, as shown in Step #3.
See Running Composer and Other CLI Commands Over SSH for the full steps.
FAQs
Why does php -v show a different version than my application settings?
php -v shows the server-level CLI version (PHP 8.2 by default). Application PHP versions are managed separately, so SSH commands use the server version unless you specify a binary.
What does $(which composer) do?
It finds the full path to the Composer binary and substitutes it into the command.
Can I change the server-level PHP version?
No. You can only set a PHP version per application in Application Settings.
Related articles
That's it! We hope this article was helpful.






