What is Composer?

In a simple word Composer is a package manager for PHP programming language which provides a smart way to manage dependencies and libraries of PHP software. It's the most popular and only way to manage PHP dependencies and libraries so far. Composer is connected it's one and only online library  https://packagist.org . Anyone can create his own libraries and publish them for free in  https://packagist.org for the PHP community. 

How to install Composer in Cpanel - Shared hosting

Cpanel doesn't allow to run Composer by default. To install Composer on Cpanel or to run Composer on shared hosting you need to follow a few easy steps. Let's get started.. 

At first glance, you need to enable your SSH access from your Cpanel. Let's see how to enable SSH or shell access in Cpanel:

Let me remind you enabling SSH access allows for:

  • Remote hosting control
  • The ability to add, remove, edit, backup and restore hosting files and directories
  • The easy import and export of your database
  • An established connection between 2 different servers

I'm going to show the screenshot from Cpanel basic theme.

Firstly, locate the Manage Shell plugin from your cPanel: cPanel » User section » Manage Shell:

manage shell

By default, SSH access is disabled for hosting accounts.

manage shell

To enable SSH, turn the toggle button on. After it has been enabled, you will then see how you can manage your SSH

manage shell

If you are using Windows, you need to download a SSH client to access the shell. I'm going to use putty. If you are using Unix-based OS like Linux or OSX, you can easily run the following command using your terming to connect to the server.

ssh username@servername -p PORT
  • ssh - command for logging into the remote server
  • username - your cPanel username
  • servername- name of the server where your hosting account is located
  • PORT - connection port - 21098 for a Shared Hosting servers, 22 - for a VPS/Dedicated server

I'm going to open SSH client, put domain name or the IP address of the server into the Host Name field, enter 21098 or 22 into the Port field, choose SSH as my connection type and press the Open button:

composer putty

If you receive PuTTY Security Alert, press Yes:

composer putty

Then enter your Cpanel username and password in SSH login section:

composer putty

Let's run command to check it's working..

php -v
composer putty

If you need to change PHP version, you can do it from your cPanel, navigate to Software and Services section » Select PHP Version menu:

composer putty

Select 5.5 to latest version from the drop-down menu and then click on the Set as current button:

composer putty

Composer requires allow_url_fopen. It is enabled by default for all php versions on our Shared servers. Still, you may check if it is On by going to Switch to PHP Settings in Select PHP version menu:

composer putty

If you need to enable any PHP extension you can do it from this section. For Laravel we need to enable fileinfo extension.

composer putty

I'm going to use Composer globally all over my server. So, I'm going to install it in bin folder

cd bin
composer putty

To begin downloading Composer installer file, enter following command.

wget https://getcomposer.org/installer
composer putty

To check the downloaded installer file, enter the following command with –check parameter.

php installer --check
composer putty

Now, let's install the Composer by running following command:

php installer
composer putty

Let's remove the installer file,

rm -rf installer
composer putty

Finally, let's check Composer is working and it's version

php composer.phar
composer putty

That's all for to install Composer in Cpanel. Now, we can access composer from anywhere of the current hosting.

How to install Laravel in Cpanel

To create Laravel in Composer project go to your desired folder and run create-project command.

I'm going to install Laravel in Adons domain's folder. So, first I'm going to that folder

cd proseooptimization.com

Then run following command

php composer.phar create-project laravel/laravel --prefer-dist
composer putty

After completion of the installation the following message will be displayed:

Application key set successfully..

composer putty

So, finally Laravel has been installed in our desired folder.

composer putty

If you visit your website you will be able to see Laravel default webpage.

That's all!!