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:
By default, SSH access is disabled for hosting accounts.
To enable SSH, turn the toggle button on. After it has been enabled, you will then see how you can manage your SSH
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:
If you receive PuTTY Security Alert, press Yes:
Then enter your Cpanel username and password in SSH login section:
Let's run command to check it's working..
If you need to change PHP version, you can do it from your cPanel, navigate to Software and Services section » Select PHP Version menu:
Select 5.5 to latest version from the drop-down menu and then click on the Set as current button:
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:
If you need to enable any PHP extension you can do it from this section. For Laravel we need to enable fileinfo extension.
I'm going to use Composer globally all over my server. So, I'm going to install it in bin folder
To begin downloading Composer installer file, enter following command.
To check the downloaded installer file, enter the following command with –check parameter.
php installer --check
Now, let's install the Composer by running following command:
Let's remove the installer file,
rm -rf installer
Finally, let's check Composer is working and it's version
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
Then run following command
php composer.phar create-project laravel/laravel --prefer-dist
After completion of the installation the following message will be displayed:
Application key set successfully..
So, finally Laravel has been installed in our desired folder.
If you visit your website you will be able to see Laravel default webpage.