How to Set Up Composer
What Is Composer?
Composer is a PHP package manager used to install specific modules or extensions within a specific directory, which may be required if these modules or extensions are not present in the global PHP installation on a server. Composer is installed by default on our Shared, VPS, and Dedicated hosting servers.
- Online documentation about Composer is available. Here is one of them: https://getcomposer.org/doc/
- You can also view available PHP packages here: https://packagist.org/
How to Set up Composer
Composer is typically used by advanced users who are familiar with the particulars of Composer and are comfortable running commands in SSH. As always, generating a website backup before making any changes or running any commands is best. Bluehost is not responsible for the aftereffects these commands may cause on your website.
Here are the general guidelines you can use in setting up Composer:
- Enable your SSH Access
Make sure your jail shell access (SSH) is enabled.- For Shared hosting, please check out the article, How to enable SSH/Shell from cPanel, for details.
- To enable SSH access for individual cPanels in your VPS/Dedicated hosting, please refer to the following instructions: VPS and Dedicated Servers SSH Access.
- Run the PHP version required by your application
The minimum PHP version on our Shared hosting servers is 8.1.Example:
The PHP version executed in the sample command line above is 8.1 (ea-php81). Depending on the needs of your application, specify the PHP version in your command line together with the full path to the php binary. The recommended method is to cd into the directory where you want to run Composer, then execute the full path to the php binary you want to use./opt/cpanel/ea-php81/root/usr/bin/php
Example:-
cd /home/user/public_html -
/opt/cpanel/ea-php81/root/usr/bin/php /opt/cpanel/composer/bin/composer diagnose
-
- (Optional) Run any additional INI settings required by your application
Example:
The sample single command line above invokes the memory limit to be set to 512M (-d memory_limit=512M). Modifying the memory limit is not required, but it can be modified if the default 256M is not sufficient for your application./opt/cpanel/ea-php81/root/usr/bin/php -d memory_limit=512M
- Run your "composer" command together with the "argument"
Example:
In the single command line above, "composer require" is executed. For the list of composer commands and arguments, you may visit the online documentation: https://getcomposer.org/doc/03-cli.md./opt/cpanel/composer/bin/composer require spatie/laravel-tags
- Run the module or extension you want to install
Example:
In the single command line above, the package "spatie/laravel-tags" is executed./opt/cpanel/composer/bin/composer require spatie/laravel-tagsNotice that the commands were executed in a single line.Example (entire command in a single command line):/opt/cpanel/ea-php81/root/usr/bin/php -d memory_limit=512M /opt/cpanel/composer/bin/composer require spatie/laravel-tags
Summary
Composer is a tool for managing PHP packages. When modules or extensions are not present in the global PHP installation on a server, it installs them in a specific directory.
Outlines in this article are the essential steps and guidelines for how to set up Composer, a PHP package manager, on Shared, VPS, and Dedicated hosting hosting servers. It emphasizes the importance of enabling SSH access, running the correct PHP version, and possibly adjusting INI settings to meet an application's requirements. The text also suggests running the Composer commands per the application's needs and warns about the potential impact of these commands on websites or applications. It underscores the importance of creating backups before making any changes. It reminds users that the Bluehost support team cannot assist with Composer-related queries beyond the provided information. Users are encouraged to consult Composer's online documentation and available PHP package resources or engage with online forums for further assistance.
If you need further assistance, feel free to contact us via Chat or Phone:
- Chat Support - While on our website, you should see a CHAT bubble in the bottom right-hand corner of the page. Click anywhere on the bubble to begin a chat session.
- Phone Support -
- US: 888-401-4678
- International: +1 801-765-9400
You may also refer to our Knowledge Base articles to help answer common questions and guide you through various setup, configuration, and troubleshooting steps.