How to Use Composer on FastComet Shared Hosting (2022 Updated)

Everyone loves saving time when possible. That goes especially for the likes of web developers. Well, using Composer on shared hosting gives you just that. You save a lot of time while doing exactly what you need when managing your web applications via this exceptional tool. Yes, you may need some Command-Line knowledge, but that’s not as hard to get as some may think.

In this post, we go over what exactly Composer is, as well as all the reasons you should use it on a daily basis.

Table of Contents:

What is Composer?

Composer is a tool for dependencies management. It enables the user to easily download all the required packages/libraries that their PHP project can use. The tool is dependent on the PHP service. You can run Composer on shared hosting—it is available on all FastComet Shared Hosting plans. Composer’s main idea is to be the most used dependencies management tool – same as Node’s npm and Ruby’s Bundler, but for one of the most used backend programming languages – PHP., that enables you to easily download all the required packages/libraries your PHP project can use.

Composer System Requirements

Composer requires PHP 5.3.2+ to run. Currently, the latest PHP version has on all Shared Hosting servers is PHP 8.1. Additionally, you can choose from PHP 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, and 8.0. However, we always recommend that all our clients use the latest PHP version because it’s the most secure option. 

If you decide to install Composer on your local machine for testing purposes, you should know that there are a few sensitive PHP settings and compile flags required. That said, when using the installer, you will be warned about any incompatibilities.

Composer is multi-platform, and the goal is for it to run equally well on Windows, Linux, and macOS.

When using Composer, it’s preferable that you are familiar with the Command Line Basics. It’s much better than copy-pasting commands from the Internet, just hoping for them to work.

Who Uses Composer?

Composer is the de-facto dependency management tool for the entire PHP community. It is widely used across the world of PHP. According to Packagist statistics, as of 2022, there are more than 330,000 packages available via Composer, and they have cumulatively been installed over seven billion times.

Composer is an invaluable tool for developers, site builders, and site architects.

If you need to download and install PHP libraries (core, modules, themes, libraries, etc.), then you should be using Composer!

Composer Makes Your Project a Fine-Tuned Orchestra

The most common reference to Composer is an actual orchestra. Think of your web hosting account as one big orchestra and all of your PHP projects as different musicians. Every composer needs to show the tempo to all these musicians so they can all perform their best when a concert is underway.

Composer actually installs for you packages/libraries defined by your project. If you have, for example, 20 projects in 20 different folders, you can use Composer in each folder to download and install the requirements of your projects with a few simple commands, which you will find below.

Why We Use Composer

You probably wonder what you will need this tool for. With the increasing demand from Backend PHP Developers for an easy dependencies management tool, the requirements for the Shared Hosting environment are also growing to a point where the hosting companies cannot afford to miss this feature.

First and most important, you will need SSH access to your account. If you are not quite sure how to get that, please submit a support ticket, and our technical support team will gladly provide you with such.

Secondly, you will need to have a good knowledge of the file system of Linux and, most importantly—where your projects are stored.

Finally, to use composer, you will need to type the composer command.

$ composer

Pretty easy, isn’t it?

A Quick Example

Let’s cut down the theory and see how Composer actually performs when it comes to the installation process for one of the most used PHP Frameworks – Symfony 2.

First, let’s begin with the creation of our project:

$ composer create-project Symfony/framework-standard-edition test_project

Replace “test_project” with the actual name of your project, and keep in mind that the process will create a folder with the same name.

After a brief installation log for the dependencies required by Symfony 2, you will be prompted with the question if you would like to install the Acme Demo bundle, which is the default one for Symfony:

Generating autoload files Would you like to install Acme demo bundle? [y/N]

Next, you will be asked for the database details your Symfony application should be using. If you are not familiar with the cPanel service and you have not a glimpse of how to create a database/username and a password, we got your back as we have a detailed tutorial on How to create a cPanel database.

Creating the "app/config/parameters.yml" file Some parameters are missing. Please provide them. database_driver (pdo_mysql):

Here you should press Enter as this is the default database driver.

database_host (127.0.0.1):

Enter again, as this is the address for the database server available for your hosting account with us.

database_port (null): 3306

The default port for the MySQL service – 3306 on all our packages.

database_name (symfony): database_name database_user (root): database_user database_password (null): password

Please replace the database_name with the actual database name you have created earlier, the database_user with the user having privileges to operate with the created database, and finally, the “password” with the actual password for that user.

Next, you will be prompted with the settings for the SMTP protocol, but you should set that up only if you will need to use it.

Finally, Composer will ask you for the “Locale” that should be used by your application and, of course, the “secret” token which will be used for encoding.

locale (en): secret (ThisTokenIsNotSoSecretChangeIt):

After a few seconds, you will get a message that the assets are installed for the used bundles, and with that, the installation is finished.

Now, if you access yourdomain.com/test_project/web/app_dev.php (where yourdomain.com should be replaced with your actual domain and test_project with the actual name of your project), you will be able to access the Symfony installation.

Keep in mind that if you have not allowed your IP address, you should do so by editing the code of the app_dev.php file located in the project folder under the web/ subfolder. When editing the file, you will need to find the following line:

|| !(in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1','YOUR_IP_ADDRESS' , 'fe80::1', '::1')) || php_sapi_name() === 'cli-server')

This should be on line 14, and there you will need to edit “YOUR_IP_ADDRESS” with your actual IP address which you should be able to check via some IP checking tool.

Acknowledgment of Limitations

Let’s be clear—nothing is perfect. Using Composer may have many advantages, but it is not without its drawbacks. The tool has gotten a bad rap in some parts of the dev community, and that’s not without cause.

Let us briefly go over the top two types of Composer “problems” that users most frequently encounter.

Resolving conflicts

Composer is great at finding interoperable versions of dependencies, but sometimes that’s just not a possibility.

Your application’s declared dependencies, or the subsidiary dependencies declared by your dependencies, may simply not be interoperable in the requested versions. Typically, this can be resolved by tweaking the version constraint of one or more of your application’s dependencies.

However, the process of discovering exactly which dependencies are in conflict and finding a suitable tweak can be frustrating, and Composer is poor at explaining the root cause clearly.

CLI only

Composer is a Command Line tool. For many users, this alone can be intimidating. However, if you love GUIs, then you’re free to explore some of the unofficial GUIs for Composer:

Final Words

Composer is a must-have tool for all the folks who need to build their projects with the speed of light, skipping the process of deploying multiple packages, plugins, configurations, and so on. We hope this post gave you a general idea of how to use composer on shared hosting. Thanks to our well-experienced System Administrators, we are able to provide Composer on all our packages.

Do you have any other suggestions for tools you would like us to implement in our Shared Hosting Environment? Use the comment section to let us know what you think about the Composer use and how beneficial it is for your PHP projects.

Joseph

Joseph is part of the FastComet Marketing team. With years of content writing experience behind him, it's one of his favorite activities. Joseph takes part in the SEO of the FastComet website and blog. His goal is to write comprehensive posts and guides, always aiming to help our clients with essential information. Joseph also has a thirst for knowledge and improvement, which makes the hosting environment a perfect place for him.