Composer
How to use composer in shared server. Easy way.

How to use composer in shared server. Easy way.

Trying to install composer in shared server? Well, you are in the right place. I have very simple approach for this. Here are the steps for you.

  • Access to your server using SSH. I hope you at least know how to access your server using SSH. If not let me know.
  • Let’s first install composer. In tutorials you searched, you might have seen to install composer in /usr/local/bin folder. But in shared server, you cannot write files and folders in that location. So, we will first install composer in root directory. For each steps below, press return /enter button.
    1. cd ~
    2. curl -sS https://getcomposer.org/installer | php
  • Composer is installed. Now let’s try to user it. For example I am trying to install doctrine/dbal
    1. cd public_html/
    2. php composer.phar require doctrine/dbal
  • Could not open input file: composer.phar. Did it show this error to you too? Well, yes this is obvious. If we could have install composer in usr/local/bin we would have able to use this way. Since, we install composer in our root direction, we need to use difference approach to use it. So, here are the further steps to use composer from public_html folder.
    1. php ~/composer.phar require doctrine/dbal

That’s all guys. The only difference is you need to add ~/ before composer.phar command. This is because we have install composer in root direction. And to access composer.phar, we first need to go to root direction itself. So, determining ~/ will help terminal to navigate composer library and the rest of the command code is same as usual. Apart from this, if you want to user composer for other purpose, you just need to write php ~/composer.phar library_name_goes_here and you will be able to use it to install other stuffs as well.

Moving Further

Isn’t it boring to type php ~/composer.phar every time to use composer. What if we can simply type composer and start using it. Well, there is a way to do this as well.

Alias

You can make the steps easy by using alias. Alias is for creating a shortcuts instead of typing bulky commands ?. Here is one simple step to make it work.

alias composer="php ~/composer.phar"

Once, you type above command, you will be to use composer as follow.

composer require doctrine/dbal

Wow ? Quite easy right? It must be. ?

Conclusion

There you go. You found easiest way to use composer?. I found out to be easy and works in shared server so, I shared with you. I hope this was helpful. If so, don’t forget to share this article and there is a like button as well. You can like it. That would be highly appreciated.

Thank you

Leave a Reply