Hosting PHP Spanish version

Support article

Composer on Hosting: How to Install PHP Dependencies

Learn to use Composer on your hosting to manage PHP dependencies: install Composer, composer.json, require and autoloader.

Published: 12/07/2026 Updated: 12/07/2026

Introduction

Composer is PHP’s dependency manager. If you develop in PHP, it’s an indispensable tool: it lets you install third-party (or your own) libraries with one command, manage their versions and keep them updated.

In this article you’ll see what Composer is, how to install it on your hosting, and how to use it in your PHP projects.

What Composer is and what it’s for

Composer is to PHP what npm is to Node.js or pip to Python: a package manager that downloads and installs the libraries your project needs.

Without Composer, to use a third-party library you had to:

  1. Find the library.
  2. Download it manually.
  3. Upload it to your project.
  4. Repeat with each dependency of that library.
  5. Repeat everything when there was an update.

With Composer:

composer require mailer/mailer

And Composer downloads the library and all its dependencies, in compatible versions.

[Imagen sugerida: diagram of how Composer manages dependencies]

Composer uses Packagist, a public repository with more than 300,000 free PHP libraries.

Does your hosting have Composer?

To use Composer you need SSH access. On miHosting’s cPanel plans, Composer is usually available.

To check, connect via SSH and type:

composer --version

If it shows the version, Composer is available. If it says “command not found”, you’ll have to install it (we’ll see below).

How to install Composer if you don’t have it

If your hosting doesn’t have Composer, you can install it yourself in your account (without being root):

cd ~
curl -sS https://getcomposer.org/installer | php

This downloads a composer.phar file. To be able to use composer from any folder, move it to a PATH location:

mkdir -p ~/bin
mv composer.phar ~/bin/composer
chmod +x ~/bin/composer

Make sure ~/bin is in your PATH. If not, add it to your ~/.bashrc:

echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Now test:

composer --version

Basic Composer concepts

ConceptWhat it is
composer.jsonFile that defines your project’s dependencies
composer.lockFile that pins the exact installed versions
vendor/Folder where Composer puts the installed libraries
requireCommand to add a dependency
installInstalls everything from composer.json
updateUpdates dependencies to newer versions
autoloaderComposer code that automatically loads classes

How to use Composer in your project

Step 1: Initialize Composer in your project

Connect via SSH and go to your project folder:

cd public_html/myproject
composer init

It will ask some questions (project name, author, etc.). At the end it creates the composer.json file.

Step 2: Add dependencies

composer require guzzlehttp/guzzle

This downloads the Guzzle library (a very popular HTTP client) and adds it to composer.json.

Step 3: Use the dependencies in your code

To be able to use the installed classes, include Composer’s autoloader at the top of your PHP:

<?php
require 'vendor/autoload.php';

use GuzzleHttp\Client;

$client = new Client();
$response = $client->get('https://api.example.com');
echo $response->getBody();

Step 4: Install existing dependencies

If you clone a project that already has composer.json:

composer install

This reads composer.lock and installs exactly the same versions. It’s what’s done when deploying to production.

Difference between install and update

CommandWhat it doesWhen to use it
composer installInstalls the exact versions from composer.lockIn production, when deploying
composer updateLooks for newer compatible versionsIn development, to update

In production, always use install. If you use update, you can end up with newer versions you haven’t tested and that break something.

Composer and Git

If you use Git for your project, there’s an important rule:

  • Upload to repository: composer.json and composer.lock.
  • Don’t upload to repository: the vendor/ folder.

Why? Because vendor/ can have thousands of files and can be regenerated with composer install at any time.

Therefore, your .gitignore should include:

/vendor/

And when you deploy to hosting, you run composer install to rebuild the vendor/ folder.

Composer and WordPress

Although WordPress doesn’t use Composer by default, many developers use it to:

  • Manage plugins with packages like WPackagist.
  • Develop themes and plugins with modern dependencies.
  • Install WordPress with Composer (for advanced development).

For most WordPress users, Composer isn’t necessary. But if you develop plugins or themes, it changes your life.

Useful tips

  • Use install in production, update in development. It’s the golden rule.
  • Upload composer.lock to Git. It’s what guarantees everyone has the same versions.
  • Don’t upload vendor/ to Git. It regenerates with install.
  • Run Composer with the same PHP version as the server. Avoids compatibility surprises.
  • Be careful with update. It can update to versions that break your code. Test them in development first.

Common problems

”composer: command not found”

Composer isn’t installed or isn’t in the PATH. Follow the steps above to install it.

Memory error when running Composer

Composer can consume a lot of memory when resolving dependencies. You can raise the limit like this:

php -d memory_limit=1G /path/to/composer install

Classes not found

Make sure to include the autoloader at the top of your code:

require 'vendor/autoload.php';

composer install fails due to PHP version

Some libraries require modern PHP versions. Check your version with php -v and update from cPanel if necessary.

I have an existing project without Composer

You can start using Composer at any time. Run composer init and start adding dependencies gradually.

Frequently asked questions

Is Composer installed on my hosting?

On miHosting’s cPanel plans, most likely yes. Check with composer --version.

Do I need Composer if I use WordPress?

For most users, no. But if you develop themes or plugins, yes it’s very useful.

Is Composer free?

Yes, Composer and Packagist are free and open source.

Can I use Composer without SSH?

Not comfortably. Composer runs from the command line. If you don’t have SSH, you can run Composer on your computer and then upload the vendor/ folder via FTP.

Does Composer affect my website’s performance?

No. Once dependencies are installed, Composer doesn’t run on each visit. It only runs when you launch it to install or update.

Manage your PHP dependencies like a professional

Composer is the standard of modern PHP development. It lets you manage libraries cleanly, securely and reproducibly. If you develop in PHP, using it saves you a lot of time and headaches.

If you need Composer on your miHosting hosting, open a ticket from your client panel and we’ll tell you how to enable it. And if your PHP project needs more resources or flexibility, our managed VPS are ideal for serious projects.