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/binfolder. 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
- cd ~
- curl -sS https://getcomposer.org/installer | php
- Composer is installed. Now let’s try to user it. For example I am trying to install
- cd public_html/
- 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/binwe 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
- php ~/composer.phar require doctrine/dbal
That’s all guys. The only difference is you need to add
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.
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.
You can make the steps easy by using
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. ?
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.