Blog · WebJi® India

How to Install Composer on Shared Hosting

Quick answer: On shared hosting, Composer runs as a local composer.phar file inside your project directory. Open cPanel Terminal or SSH, run the installer with the account's PHP binary, then ./composer.phar --version. You need no root; a global install is usually impossible, and that does not matter if you call the local file or a wrapper script.
✓ In business since 2005✓ INR + GST billing✓ 24/7 Email Support — avg reply < 60 min
Indian trader monitoring candlestick charts on multiple screens in evening light — how to install composer on shared hosting

What Composer needs from a shared plan

Composer is a dependency manager for PHP. It reads composer.json, resolves versions, and writes a vendor folder your application loads. On shared hosting it runs as a single PHAR file, not as a system package.

  • PHP 7.2.5 or newer for Composer 2.x. PHP 8.1 to 8.3 is the practical range on current cPanel builds.
  • A shell: cPanel Terminal, or SSH if the plan enables it.
  • Outbound HTTPS to packagist.org and the package hosts, because downloads happen at install time.
  • 512 MB of memory for a normal project, and disk space for vendor plus the Composer cache.

You do not need root, and you should not expect a global composer command. A local PHAR inside the project is the supported pattern on a shared account.

Install Composer inside the project folder

Work in the directory that holds composer.json, usually public_html or one level above it. The installer is a PHP script, so it runs with the same binary your site uses.

  1. Open cPanel, then Terminal. On plans without it, connect over SSH with the account username and the server hostname.
  2. Change into the project: cd ~/public_html.
  3. Fetch the installer: php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');".
  4. Run it: php composer-setup.php --install-dir=. --filename=composer.phar.
  5. Remove the installer: php -r "unlink('composer-setup.php');".
  6. Check it: ./composer.phar --version. You know it worked when it prints Composer version 2.x and a PHP version line.

Use php -v first if the account runs more than one PHP version. The CLI default is not always the version the domain uses.

Run install and update for your project

With composer.phar in place, the two commands you need are install and update. Install reads composer.lock and reproduces it; update resolves new versions and rewrites the lock.

  1. Production install: php composer.phar install --no-dev --optimize-autoloader. This skips test packages and builds a faster autoloader.
  2. Add a package: php composer.phar require vendor/package, then commit both composer.json and composer.lock.
  3. Update deliberately: php composer.phar update vendor/package. Update everything only in development.
  4. Verify: the vendor folder exists, and the site loads without a missing class error.

If the plan has no shell at all, run Composer on your own machine and upload the vendor folder with the lock file. That is slower to iterate, but it is the same output.

Make composer callable without the path

Typing php composer.phar every time is noise. Pick one of two shortcuts, and remember that neither applies inside cron.

  • Alias: add alias composer='php ~/composer.phar' to ~/.bashrc, then run source ~/.bashrc. Aliases are per shell session.
  • Wrapper: create ~/bin/composer containing the php call, chmod +x it, and add ~/bin to PATH. This works in scripts and cron.

Keep the PHAR outside public_html if you can. A downloadable composer.phar in the web root is a file you did not mean to publish.

Match Composer's PHP version to the site

The most common shared-hosting Composer failure is a platform mismatch: Composer resolves packages for the CLI PHP version while the site runs another. The install succeeds and the site throws a fatal error.

  1. In cPanel open MultiPHP Manager and note the PHP version assigned to the domain.
  2. In Terminal run php -v and compare. If they differ, either switch the CLI or pin the platform.
  3. Pin it in composer.json with php composer.phar config platform.php 8.1.29, using the version the site runs.
  4. Re-run php composer.phar update --lock so the lock file matches the pinned platform.

Avoid --ignore-platform-reqs to get past a failing extension. It hides the missing extension until the site calls it in production.

Common Composer failures and fixes

These six cover almost every shared-hosting install that stalls.

SymptomCauseFix
composer: command not foundThere is no global binary on a shared planCall php composer.phar, or add the alias or wrapper
ext-zip or ext-json missingThe PHP build lacks an extension Composer needsEnable it under Select PHP Version, then re-run the install
Allowed memory size exhaustedDependency resolution needs more than the CLI limitPrefix the command with COMPOSER_MEMORY_LIMIT=-1
Could not resolve host: repo.packagist.orgOutbound HTTPS or DNS is blocked from the accountAsk the host to allow it, or build vendor locally and upload it
Your requirements could not be resolvedThe lock file or platform.php does not match the installed PHPSet platform.php to the site version, then update the lock
Permission denied writing vendorFiles were created by another user, often rootDelete vendor, re-run as the account user, never as root

When to build dependencies elsewhere

Shared hosting is fine for installing a small dependency tree. It is the wrong place to resolve a 200-package Laravel application that needs 1 GB of memory and ten minutes of CPU.

In that case build on your laptop or CI, commit the lock file and upload vendor, or move the application to a VPS where you control the PHP binary and the memory limit. cPanel hosting remains the right home for the site itself, and shared plans include Terminal on WebJi® accounts so the local PHAR method works out of the box.

Frequently Asked Questions

Can I install Composer globally on shared hosting?

Usually not. A global binary needs write access to a system path. Install composer.phar in your project or home directory and call it with php, or add a wrapper in ~/bin.

Do I need SSH to install Composer?

You need a shell. cPanel Terminal is enough on plans that include it. Without any shell, run Composer locally and upload vendor together with composer.lock.

Which PHP version does Composer 2 need?

PHP 7.2.5 or newer. On current cPanel builds the practical choice is 8.1 to 8.3, matched to the version the domain runs so the resolved packages work in the browser too.

Why does composer install fail with a memory error?

Dependency resolution can exceed the CLI memory limit on a big tree. Run COMPOSER_MEMORY_LIMIT=-1 php composer.phar install, or raise memory_limit for the CLI PHP version.

Is it safe to upload the vendor folder instead?

Yes, if you also upload composer.lock and build with the same PHP version and platform settings. The vendor folder is plain files, and no Composer run is needed on the server.

Where should composer.phar live?

In your home directory or the project root, not inside a public web folder. A PHAR reachable by URL is an unnecessary download and a small information leak.

Need help with this?

WebJi® support does it for you — free. Talk to our Jaipur team →