PHP CLI and Bash - change behaviour of PHP keyword

General Tech Bugs & Fixes 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

Our hosting providers have installed 3 versions of PHP onto our linux box and when I SSH into it the command php points to use/bin/php which is version 5.2, the command php-5.4 points to usr/bin/php-5.4 which is version 5.4 of course.

This isn't a problem when I just need to run a single script that needs a newer version of php, I can just specify php-5.4, however when I try to run the Laravel installer or try to install Laravel using Composer it is throwing errors that are caused by php 5.2 being used.

Is there a way to change where the php keyword points? Or do I need to remove bin/php and rename bin/php-5.4?

profilepic.png
manpreet 2 years ago

You can s://forum.tuteehub.com/tag/attack">attack this in a variety of ways.

Method #1 - alias

You can make an alias, php=php-5.4, and then attempt to run your script. Assuming that it relies on the current shells ability to locate how to run things, then it should pickup the alias for php instead of the php that's located under /usr/bin.

Method #2 - $PATH

You can override the precendence of where shells locate executables by manipulating the $PATHenvironment variable. Simply add the location of some other directory to the front of the $PATH.

export PATH=/path/to/newdir:$PATH

Now put a shell script or link in this directory named php. Here's the script:

#!/bin/bash

php-5.4 $*

Here's the link:

$ cd /path/to/newdir
$ ln -s /usr/bin/php-5.4 php

0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.