10
votes

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. ????

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.aynber
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.Ohgodwhy
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.Ehtasham Malik
@Ohgodwhy, yeah I know that, thats why i have mentioned that "It targeting the deafult php version of the server". Thanks for your reply.Ehtasham Malik
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.Ohgodwhy

6 Answers

33
votes

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
3
votes

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.

1
votes

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.

1
votes

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!

1
votes

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.

0
votes

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).