PHP Composer
About Composer
Composer is a tool for managing dependencies in PHP projects. The Composer module in ispmanager allows installing and updating libraries and packages automatically.
For example, you need the monolog/monolog logging library. You can specify the package name and version range (or just the package name), and the Composer module will:
- Check if dependencies for monolog/monolog are installed and download and install them if necessary.
- Download and install the monolog/monolog library.
- Add dependency information to the project configuration file.
- Generate an
autoload.phpfile to autoload classes from the library into your project. - Update the dependency if necessary when a new version is released.
Composer requirements
To install Composer
- Control panel plan: lite, pro, or host
To work with Composer
- The PHP Composer option is enabled for users in the Access section
- The Use PHP Composer option is enabled for websites
For the `install` and `update` commands to function
- The server must have access to a package repository (Packagist by default)
- Websites must be enabled
For the separate PHP Composer Update command
- Control panel version 6.157 or higher
Composer installation
Composer is installed in the root directory of the site for which it is enabled.
The version of Composer depends on the PHP version for the site:
- the latest version of Composer requires PHP 7.2 and higher
- for PHP 5.3–7.1, Composer 2.2.X are installed
To install Composer:
- Log in to the panel with superuser rights.
- Navigate to Software configuration → Web-server (WWW).
- Check the PHP Composer box.
- Click Save.
Composer will be installed in the background mode.
To make Composer available for use, enable it for users and sites.
Enabling Composer
For users
- Log in to the panel with an administrator-level account or above.
- Navigate to the Users section.
- Select a user and click
Edit. - In the form that opens, go to the Access block.
- Check the box PHP Composer to enable access.
Save the changes.

For sites
Composer must be enabled for the user that owns the site.
- Go to the Websites section.
- Select a site and click
Edit. - In the form that opens, go to the Handler (PHP) block.
- Check the Use PHP Composer box.
Save the changes.

Managing dependencies with Composer
Only one Composer operation can be performed at a time on a single site.
Dependency versions
When installing a dependency, you can specify either a particular version of it or a range of acceptable versions. For example:
- if the 1.2.3 version is specified, this version will be installed
- if the ^1.2.3 version is specified, the latest compatible version will be installed, but not lower than 1.2.3 and not higher than 2.0.0
For more information about dependency versions, see the official Composer documentation.
Installing dependencies
Dependencies and information about them are stored in the site directory. When installed:
- dependencies are installed in the
vendor/directory - dependency information is written into the
composer.jsonconfiguration file - information about the specific installed version is registered in the
composer.lockfile. Thecomposer.lockfile is used to lock the versions of dependencies
If the software you are installing depends on other software, it will also be installed automatically.
Select the desired installation method:
- Go to the Websites section.
- Select the desired site.
- Click
to open the context menu. - In the list, click View PHP Composer packages.
- Click
on the toolbar. - In the PHP package names field, enter the package names, placing each one on a new line. Specifying a version is optional.
- Click Install.
By default, dependencies are installed from the Packagist repository. If you need to install a dependency from a different repository, do so via the composer.json configuration file, specifying the required repository within it.
Installation is performed from a non-standard repository or from a custom configuration file in JSON format.
- Go to the Websites section.
- Select the desired site.
On the toolbar, click
Configuration files. This will open the composer.jsonconfiguration file.DetailsThe
composer.jsonfile is the main Composer configuration file which contains dependency settings: names, versions, repositories, etc.composer.jsonexample{ "require": { "monolog/monolog": ">=1.0.2 <2.1.2" }, "description": "This example", "keywords": ["testing", "example"], "type": "project", "version": "1.0.0", "homepage": "https://example.com", "readme": "readme.md", "license": "MIT", "authors": [{ "name": "User", "email": "user@example.com", "homepage": "https://www.example.com", "role": "Developer" }], "support": { "email": "support@example.org" } }Commentaryrequire— library name and version to be installed — required fielddescription— project descriptionkeywords— keywords for project search in the repositorytype— type:library,project,metapackageorcomposer-pluginversion— project versionhomepage— project home pagereadme— path to thereadmefilelicense— project license typeauthors— information about project authors:name— author nameemail— author email addresshomepage— author home pagerole— project role
support— support team email address
- Copy the contents of your file into the file in the panel.
- Save the changes.
If the file content has changed, the panel will validate it upon saving and execute the PHP Composer Update command (./composer.phar update). Composer will then update the dependencies and overwrite the composer.lock file. If the validation fails, the file will revert to its previous content. If the file content has not changed, Composer will not be triggered.
- Go to the Websites section.
- Select the desired site.
- Click
to open the context menu. - In the list, click PHP Composer install.
- In the Installing dependencies window, click Install.
The PHP Composer install command executes ./composer.phar install in the site's root directory, on behalf of the site owner.
If the composer.lock file exists, the dependency versions are installed based on it, and the file itself remains unchanged. If no composer.lock file exists, Composer determines the appropriate dependency versions and creates the file.
Installed dependencies are displayed on the Installed PHP packages page. To access it, select a site, click
to open the context menu, then click View PHP Composer packages.
Updating dependencies
The update will overwrite the composer.lock file. Please save a copy of the file before performing the update. To revert to previous versions of your dependencies, restore the file from your copy and run the PHP Composer install command.
After installing the dependencies, update their versions using one of the following methods:
- Go to the Websites section.
- Select the desired site.
- Click
to open the context menu. - In the list, click PHP Composer Update.
- In the Updating dependencies window, click Update.
- Go to the Websites section.
- Select the desired site.
- Click
to open the context menu. - In the list, click View PHP Composer packages.
- Click
Update on the toolbar.
Composer will install the latest available versions of dependencies that satisfy the version constraints in composer.json and will update composer.lock.
Shell client
The Shell client allows running additional Composer commands. The terminal is launched on behalf of the site owner. When the terminal opens:
- the working directory is changed to the site's home directory
- the path to the executable file of the PHP version selected for the site is added to the PATH environment variable
Shell commands must contain the path to the composer.phar executable:
./composer.phar COMMANDRemoving dependencies
To remove a dependency:
- Go to the Websites section.
- Select the desired site.
- Click
to open the context menu. - In the list, click View PHP Composer packages.
- Select the package you want to remove.
- Click
on the toolbar. - Confirm the removal of the dependency.
Notes on removal:
- an error will occur if you attempt to remove a dependency that is required by other dependencies
- an error will occur if you attempt to remove a dependency while packages are being installed or updated
- if one dependency has another dependency installed for it, both dependencies will be removed
Assume you have the following packages installed:
- intervention/image (a library for image manipulation)
- guzzlehttp/guzzle (a dependency of intervention/image used for HTTP requests)
If you attempt to remove intervention/image:
- Composer will remove intervention/image.
- It will then check whether any other packages still require guzzlehttp/guzzle.
- If they do not (i.e., guzzle was installed solely for intervention/image), Composer will remove it as well.
Using dependencies in a project
To use the installed dependencies in your project, specify the path to the autoload.php file in the php section:
require_once('vendor/autoload.php')<?php
require_once('vendor/autoload.php');
use Monolog\Level;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
$logger = new Logger('channel-name');
$logger->pushHandler(new StreamHandler('app.log', Logger::DEBUG));
$logger->info('This is log');
$logger->warning('This is log warning');
$logger->error('This is log error');
?>Backups
When you create a site backup, the site's Composer settings and installed libraries are backed up.
If Composer is disabled in the panel when you restore a user from a backup, the user and their site will be imported with dependencies already installed, but an error record will be added to the recovery log. For the user to continue using Composer, install it in the panel and enable it for the user and the site.
Composer logging
Operations with Composer are written to the logs:
/usr/local/mgr5/var/phpcomposerctl.log— contains command calls and errors.
To change the logging level, add the following line to the/usr/local/mgr5/etc/debug.confconfiguration file:phpcomposerctl.* 9/usr/local/mgr5/var/ispmgr.log— logs panel processes related to module operation.
To change the logging level of the Composer module in the panel log, navigate to the Logging settings → ispmanager - PHP (ispmgr.php) section.
Disabling Composer
After disabling Composer for a site or removing it in the Software configuration section, the installed dependencies are not removed.
Protecting Composer service data
When Composer is enabled, the following service files and directories are created in the site's home directory:
composer.phar— executable Composer file (only works with the CLI version of PHP)composer.json— file describing all project dependenciescomposer.lock— file with a list of all installed dependencies and their versionsvendor/— directory to which dependencies are installed.cache/— directory storing cache of downloaded dependencies.config/— directory containing configuration settings and public keys.local/— directory that may store additional Composer data
To prevent service files and directories from being accessed via a browser, special includes are added to the configuration files of web servers for sites. If both Nginx and Apache are installed, includes are added to the configuration files of both.
After disabling Composer, if dependencies were installed for the site, includes in the configuration files are preserved. This is necessary so that service files and directories do not become accessible from a browser after disabling. If you remove the vendor/ directory or the composer.json file from the site directory, the includes will be deleted the next time the site settings are saved.
Example of an include:
The phpcomposer.conf files are only accessible on the server to the root user.
Contents of the /etc/nginx/modules-includes/phpcomposer/phpcomposer.conf file:
location ~* ^/composer\.(json|lock|phar)$|^/(vendor|\.config|\.cache|\.local)/ {
deny all;
}- Debian-based OS —
/etc/apache2/modules-includes/phpcomposer/phpcomposer.conf - RHEL-based OS —
/etc/httpd/modules-includes/phpcomposer/phpcomposer.conf
File contents:
<LocationMatch "^/composer\.(json|lock|phar)$|^/(vendor|\.config|\.cache|\.local)/">
<IfModule mod_authz_core.c>
# Apache 2.4
<RequireAny>
Require all denied
</RequireAny>
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
</IfModule>
</LocationMatch>Contents of the /usr/local/lsws/conf/modules-includes/phpcomposer/phpcomposer.conf file:
context exp: ^/composer\.(json|lock|phar)$|^/(vendor|\.config|\.cache|\.local)/ {
allowBrowse 0
}