I have PHP version 8and i also have PHP 7, but the php -v
command only show version 8how can i change environment variable to php 7
my php7 installation directory is usr/bin/php7
I have PHP version 8and i also have PHP 7, but the php -v
command only show version 8how can i change environment variable to php 7
my php7 installation directory is usr/bin/php7
Whatâs the output of:
alias php
if the output is:
bash: alias: php: not found
type:
alias php=/usr/bin/php7
Please test that extensively and if that is indeed what you want, report back and weâll make that command permanent.
if the output is anything else than:
bash: alias: php: not found
please report back with the output.
Iâve tried alias php but nothing print out in the console. Please help, I need to switch version PHP based on different projects
Hello @ziat,
the âaliasâ command didnt generate any output. It assign the left term to the right.
It means when you âalias php=/usr/bin/php7â you then can run â/usr/bin/php7â by typing âphpâ in your console.
This is not permanent, after a reboot this âaliasâ is gone. If you want this permanent you have to write the âaliasâ in this file: ~/.bashrc
I would suggest to alias the older to an extra name like php7:
alias php7=/usr/bin/php7
So you can run your scripts with both versions:
php your-script.php
runs your script with actual php version, and
php7 your-script.php
runs your script with php7.
Which versions?
if php7 and 8:
With:
alias php=/usr/bin/php7
executing
php myPHP
will run it in 7
With:
alias php=/usr/bin/php8
executing
php myPHP
will run it in 8
@Fabby
I mean when your run âphpâ without any aliases it runs â/usr/bin/phpâ which is assigned to the newest version which comes with the rolling releases. At this time version 8.
So I would suggest for older versions an âaliasâ that he can use both if wanted.
terminal or web project ?
alias is only for terminal and for user (so not useful), for web: change server config (apacheâŚnginx) or (best for me) use docker
if not web project, linux use shebang (shebang âenvâ not use alias !)
less /usr/bin/composer
#!/usr/bin/env php
<?php
/*
* This file is part of Composer.
*
[patrick@tower ~]$ alias
alias cp='cp -i'
...
alias php='/usr/bin/python'
ok
[patrick@tower ~]$ php -V
Python 3.9.7
but
[patrick@tower ~]$ env php -v
PHP 8.0.11 (cli) (built: Sep 25 2021 07:52:29) ( NTS )