Need to run 'composer update' on ssh on hostgator, but php -v to low
Asked Answered
C

7

11

Need Help πŸ›¬

Framework - Laravel

Hosting - Hostgator

Problem Statement :- I need to run the 'composer update'. All dependencies required minimun php -v of 5.5.9. I have manualy Upgrade the php version of Project directory to 5.6 from cpanel using 'Php configration' plugin. But when i logged in using ssh, then i got the php -v of 5.4.45. Ofcourse It targeting the deafult php version of the server. Is there any way to update php to 5.6 or above on ssh also. No root user access. No help from support team also. 🎭

Communicative answered 22/9, 2016 at 16:2 Comment(6)
If you've tried to update PHP via cPanel but it's not updated on the server, you'll definitely need to talk to HostGator. Try their forums or open a ticket. You say there's no help, but they should be able to do something to update it. – Smoothie
This is because the command line (CLI) and the webserver are not running the same version of PHP. When executing functions over SSH, it's looking at the CLI. They should be the same version. – Gubernatorial
hi @aynber, Thanks but I have already talked to hostgator, but they replied that they can't update the default php -v for shared hosting. – Communicative
@Ohgodwhy, yeah I know that, thats why i have mentioned that "It targeting the deafult php version of the server". Thanks for your reply. – Communicative
Indeed. I'm pointing out why you'll never be able to do this on a shared hosting environment. Not gonna happen. Pay $20 a month for Laravel Forge to manage your server, or buy a cheap VPS and build one out if you're feeling up to it. – Gubernatorial
Great, Nice suggestion. Thanks – Communicative
P
36

Use this command in ssh

$ nano ~/.bashrc

then paste these lines, you can change php version after opt/php55 is 5.5, 71 is 7.1 accordingly

alias php='/opt/php71/bin/php'
alias composer='/opt/php71/bin/php ~/bin/composer'
export DRUSH_PHP='/opt/php71/bin/php'

Now, re-source the file so the command line gets the new aliases

 $ . ~/.bashrc

now check version

$ php --version

simple easy trick is if you want to run artisan commands using php7.1 then use this command

   $ /opt/php71/bin/php artisan
Pickens answered 9/2, 2018 at 21:16 Comment(7)
Nice! i did not know this was possible. To get the php path : composer diagnose. For the php path i use the error message in composer slef-update commande – Astyanax
@Pickens - Great Job!! – Stillness
i followed the instructions but I got the message Could not open input file: /home1/username/bin/composer. What should I do? – Hyonhyoscine
Please upload "composer.phar" file in bin/composer folder and then try it. You can download file from getcomposer.org/download – Pickens
alias composer='/opt/php71/bin/php /opt/cpanel/composer/bin/composer' – Intersex
@HeliPerez your version works on my HG account.. thanks! – Suzansuzann
You are great @Adnan. Thanks for the help – Stewart
P
3

Using a PRO/Shared Host (tested in Hostgator.com.br) you can do this in SSH (change the usercpanel to your own):

vim /home/usercpanel/.bashrc

In the next page, if it's blank, insert the values:

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
 . /etc/bashrc
fi

# User specific aliases and functions

Right after, you will put (you can change the php version: 71, 72, 73 or 74):

alias php='/opt/cpanel/ea-php74/root/usr/bin/php'
export PATH="/opt/cpanel/ea-php74/root/usr/bin:$PATH"

Will be like this

Save the changes and exit.

Now, insert this code to load the new config (change the usercpanel to your own):

source /home/usercpanel/.bashrc

And, insert this code to verify if the alias has been loaded.

alias | egrep 'php'

And then, check if the path is being displayed in the PATH variable:

echo $PATH | egrep '/opt/cpanel/ea-php74/root/usr/bin'

DONE! Tested and working fine for me.

Paralyse answered 12/6, 2020 at 19:29 Comment(0)
T
1

Recently i update composer and also php in my mac_system
And used these commands by terminal

-Local php update in Mac os curl -s http://php-osx.liip.ch/install.sh | bash -s 7.0

-export PATH=/usr/local/php5/bin:$PATH (change php version to create project)

php update

This above link.. i Used.. So try with command or the link. I think you will get some knowledge on it.

Taxeme answered 23/9, 2016 at 10:7 Comment(1)
Thanks for your help man, but I think OS X version is not updated on the server, got this message on terminal "Your version of OS X () is not supported, you need at least 10.6" – Communicative
S
1

There is actually a workaround to get newer versions of php and composer working via ssh on shared hosting env such as hostgator.

Try to add the following lines to your .bash_profile or .bashrc and resource your bash shell. The default version of PHP should now be changed to whatever version you specified.

alias php='/opt/php{VERSION_NUMBER}/bin/php'
alias composer='/opt/php{VERSION_NUMBER}/bin/php ~/bin/composer'
export DRUSH_PHP='/opt/php{VERSION_NUMBER}/bin/php'

Use php -v to check the version of php and test if composer works. If composer still doesn't work install it in the ~/bin/composer folder following the instructions First install composer using the instruction https://getcomposer.org/download/.

At least thats what I did!

Scoter answered 15/9, 2017 at 13:32 Comment(0)
F
1

Just for others who are suffering like me.

You can use my trick in Hostgator command line (CLI). It works for me every time when I want to use CLI with Laravel 5.6 (required PHP 7.1) on Hostgator shared hosting.

$ /opt/php71/bin/php /home/{your_directory}/composer.phar update

I have a few Laravel projects on the same shared hosting so {your_directory} can be change depending on your project directory path.

Fellini answered 29/5, 2018 at 0:34 Comment(1)
on share hostings if you don't want to mess with the default path, this is a good way also /opt/php71/bin/php /opt/cpanel/composer/bin/composer install – Griggs
K
0

Using aliases did not work for me. Actually composer did work, but when it called ran artisan, errors such as "Parse error: syntax error, unexpected 'class'" appeared (php5 was used instead of php7)

Instead I had to copy /opt/php71/bin/php to ~/home/bin then modify ~/.bash_profile to use my local bin path first

PATH=~/bin:$PATH

(and I ran . ~/.bash_profile afterwards to apply changes)

Would have prefered a symbolic link with ln -s /opt/php71/bin/php ~/bin but it did not work (permission denied).

Kuehnel answered 7/10, 2019 at 14:31 Comment(0)
L
0

If you're using Hostinger and need to set the correct paths for PHP and Composer, follow these steps. These configurations will ensure that you're targeting PHP 8.2 when using commands like php, composer, or drush.

Step-by-step instructions:

  1. From terminal open the .bashrc file: You’ll need to edit the .bashrc file to make these changes permanent. Open it with the nano text editor by running:

    nano ~/.bashrc

  2. Add the following lines to your .bashrc file:

alias php='/opt/alt/php82/usr/bin/php'
alias composer='/opt/alt/php82/usr/bin/php ~/bin/composer'
export DRUSH_PHP='/opt/alt/php82/usr/bin/php'
  1. Save and exit: After adding the lines, save the file by pressing CTRL + O, then press Enter. Exit by pressing CTRL + X.

  2. Reload the .bashrc file: For the changes to take effect immediately, reload the .bashrc file by running:

    source ~/.bashrc

Letrice answered 6/9 at 19:3 Comment(0)

© 2022 - 2024 β€” McMap. All rights reserved.