PHP Composer for Smart Dependency Management of Your Cloud Applications

PHP Composer logo

Composer is one of PHP’s most popular dependency management tools inspired by the node’s npm and ruby’s bundler. It will smartly manage all the required libraries and packages for your application. Running on a per-project basis, Composer determines which versions of which packages your project depends on and installs them in a working directory. Moreover, this tool provides the autoload feature to keep your packages up-to-date.

The Composer is integrated into all PHP application servers (Apache, NGINX, LiteSpeed, LEMP, and LSSMP) by default. It is installed to the /usr/local/bin folder, which is added to the PATH variable, making Composer operable from anywhere on the node via the composer shortcut (e.g. composer about). Additionally, if the project has a composer.json file, Composer can manage dependencies directly during the installation using the Post-Deploy hook script. All you need to do is move to your project directory and run the composer install command:

1
2
cd $WEBROOT/{project_name}
composer install

Composer Update

You are automatically provided with the latest version of Composer during the node creation. However, if a newer version of Composer is released, you can easily get it without the necessity of recreating a whole container. Follow the next steps to install the latest composer version into your PHP container:

1. Connect to the appropriate node via SSH. For example, using the built-in Web SSH.

Apache Web SSH access

2. Download Composer installer with the following command:

1
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

SSH download Composer installer

3. Install Composer into the current directory.

1
php composer-setup.php --install-dir=./ --filename=composer

SSH install PHP Composer

Tip: If needed, you can move to the required directory before the operation or adjust the path via the install-dir parameter. However, you cannot install to the /usr/local/bin/ directory with the initial Composer instance.

4. Let’s run this local version of the Composer (i.e. using relative or absolute path) to ensure that everything works as expected. For example:

1
./composer about

SSH PHP Composer about

Tip: If the dependency manager works fine, we recommend removing the installer (as it’s not needed anymore).

1
php -r "unlink('composer-setup.php');"

SSH remove Composer installer

That’s all! The latest version of the Composer is successfully installed and is ready for use.

What’s next?