W3docs

How do I install Composer on a shared hosting?

To install Composer on a shared hosting, you can use the following steps:

To install Composer on a shared hosting, you can use the following steps:

  1. Connect to your shared hosting account using a file transfer protocol (FTP) client or the file manager provided by your hosting provider.
  2. Download the Composer installer script by running the following command in your terminal:

Example of downloading the Composer installer script

curl -sS https://getcomposer.org/installer > composer-setup.php
  1. If you ran the command locally, upload composer-setup.php to your shared hosting account.

  2. Run the installer script via command line with the following command:

Example of running the Composer installer script

php composer-setup.php --install-dir=bin --filename=composer
  1. Set permissions on the bin/composer file to allow it to be executed:

Example of setting permissions on the composer executable

chmod +x bin/composer
  1. Move the Composer executable to a directory that is in your system's PATH, such as ~/bin:

Example of moving the Composer executable to a user PATH directory

mv bin/composer ~/bin/composer
  1. Test your installation by running the following command:

Example of testing the Composer installation

composer --version

Note: Many shared hosting providers already include Composer or offer one-click installers via control panels like cPanel or Plesk. Check with your host first to avoid duplicate installations. If ~/bin is not automatically in your PATH, add export PATH=~/bin:$PATH to your ~/.bashrc or ~/.profile file, then run source ~/.bashrc (or source ~/.profile) to apply the changes immediately.

You should now have Composer installed and ready to use on your shared hosting account.