Composer helps in managing dependencies in PHP. You can declare the libraries your project depends on, and it helps in managing (install/update) them for you. Composer isn’t a package manager similar to Yum or Apt. It works with ‘packages’ or libraries, but manages them on a per-project basis, installing them in a directory (e.g., vendor) within your project. Nothing will be installed globally by default. Hence, it is a dependency manager.
Steps to Install Composer
1. You should enable the SSH access for your hosting account with us.
2. For accessing your account via SSH, download and install one of the available SSH clients. If you are using a Unix-based OS (Linux or OSX), the Terminal application can be easily run and connected to the server using the below command:
ssh username@servername -pPORT
ssh – command for logging into the remote server.
username – your cPanel username.
servername- name of the server on which your hosting account is located.
PORT – connection port – 21098 for a Shared Hosting servers, 22 – for a VPS/Dedicated server
3. Open your SSH client (here PuTTY), type your domain name or IP address in the Host Name field, your port number into the Port, select SSH as your Connection type and click on Open.
4. In case, you receive PuTTY Security Alert, click on Yes.
5. Then enter your cPanel username and password when you are asked for. Type the username and for password just right-click and enter or simply right-click.
6. You need to have PHP 5.5+ version installed on your server for composer, so check whether the needed version is set up. Type the php -v command in PuTTY (or in Terminal) for finding the version. You will get the below output:
7. For changing PHP version, log in to your cPanel, go to Software and Services section >> Select PHP Version menu:
8. From the dropdown menu, select any version from 5.5-7.3 versions and click on the Set as current link besides the menu:
Note: Composer needs allow_url_fopen. It is by default enabled for all PHP versions on our Shared servers. But you can still check if it is On by navigating to Options menu at the top in Select PHP Version window:
9. Then, go to the folder you want to install Composer in. Here, we will install Composer in public_html:
10. Now, find or create the php.ini file and add some values to it. Log in to cPanel and go to File Manager menu:
11. Go to the folder where your Composer will be installed and create a new file with the name php.ini with the help of +File button:
12. Right-click on the file and click on Edit to open it. A new Edit window will get displayed, click on Edit again.
13. Next, add the below values to the file and click on the Save Changes button.
max_execution_time = 300 max_input_time = 300 memory_limit = 512M suhosin.executor.include.whitelist = phar detect_unicode = Off
14. When you are done, get ready to install Composer. Open PuTTY window where you have logged in to your cPanel account and add the below command:
php -r "readfile('https://getcomposer.org/installer');" | php -c php.ini
This will start the installation of Composer.
15. If you want to run Composer, use the below commands:
p -c php.ini composer.phar
16. If you get a notification “Some settings on your machine make Composer unable to work properly”, check that the PHP version is 5.5 or higher and all the changes in the php.ini file are saved.
That’s it! You can now easily install Composer on your shared server by following the above steps.