Don't use centos but finding a guide was easy https://green.cloud/docs/how-to-instructions-for-installing-php-8-1-on-centos7/
change php version 7.4.32 to 8.1.0 on CentOS7?
Hi so my version of Laravel requires php version 8.1.0 on my centOS7 server, Can someone please help me switch php version so I can run migrations etc
I think it installed but when I do php -v it’s still showing 7.4
@boyjarv try
sudo update-alternatives --set php
@Sinnbeck I tried that and got
alternatives version 1.7.6 - Copyright (C) 2001 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.
usage: alternatives --install <link> <name> <path> <priority>
[--initscript <service>]
[--family <family>]
[--slave <link> <name> <path>]*
alternatives --remove <name> <path>
alternatives --auto <name>
alternatives --config <name>
alternatives --display <name>
alternatives --set <name> <path>
alternatives --list
common options: --verbose --test --help --usage --version --keep-missing
--altdir <directory> --admindir <directory>
@boyjarv ok. On Ubuntu it let's you pick from a list. You need to give it the path as well. Time to Google the path to where php is installed on centos
It could be
sudo update-alternatives --set php /usr/bin/php8.1
Try running
which php
The use the result to do <result>/php --version if that gives you 8.1
use the sudo update-alternatives --set php <result>/php
Not sure if you need /php on the update-alternatives command.
Hopefully it will fix it for you.
which php
alias php='/opt/plesk/php/7.4/bin/php'
/opt/plesk/php/7.4/bin/php
@boyjarv do perhaps
sudo update-alternatives --set php /opt/plesk/php/8.1/bin/php
But you never mentioned that you were running plesk. That might change things 🤷♂️
The plesk server you have installed on the same centOS box is aliasing php to its local PHP install. The alias will override any other alternative such as using update-alternatives
- Does it need that to be aliased?
- Can you try removing that alias, and see if it works?
@rodrigo.pedra ah ha! I think you are right, I think it is aliased, how can I turn off aliasing?
Thanks
You need to find where plesk defines this alias and comment it.
It might be a reference on your user's .profile or .bash_profile files that are loaded every time you login to a shell.
The hard part is that sometimes a program just add something like
source /etc/plesk/config
/etc/plesk/config is a made-up file name
Which will run this other file when your profile files are run, so it may be trick to find it.
Try running
grep -rn ~ -e "alias php="
It will search all files that have the string alias php= from your home folder. If you find it, try commenting out that line and see if it affects plesk.
@rodrigo.pedra ok thanks I grepped it and got back:
/root/.bashrc:8:alias php='/opt/plesk/php/7.3/bin/php'
/root/.bashrc:14:alias php='/opt/plesk/php/7.4/bin/php'
/root/.bash_history:503:echo "alias php='/opt/plesk/php/7.4/bin/php'" >> ~/.bashrc
/root/.bash_history:856:alias php="/usr/bin/php81"
don't mind .bash_history
Try commenting out lines 8 and 14 on your /root/.bashrc file.
Or just add your alias to PHP 8 after it.
ok my /root/.bashrc file now looks like this:
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
#alias php='/opt/plesk/php/8.1/bin/php'
#
# Source global definitions
#if [ -f /etc/bashrc ]; then
# . /etc/bashrc
#fi
#alias php='/opt/plesk/php/8.1/bin/php'
alias php='/opt/plesk/php/8.1/bin/php'
when I php -v I get:
-bash: /opt/plesk/php/8.1.1/bin/php: No such file or directory
when I go to /opt/plesk/php I can see version 8.1 (not 8.1.1)
what is the output for each of the following commands?
ls -la /opt/plesk/php/8.1
ls -la /opt/plesk/php/8.1.1
ls -la /opt/plesk/php/8.1.1/bin
@rodrigo.pedra ls -la /opt/plesk/php/8.1
drwxr-xr-x 8 root root 77 Sep 30 15:39 .
drwxr-xr-x 6 root root 50 Sep 30 15:43 ..
drwxr-xr-x 2 root root 127 Oct 13 15:29 bin
drwxr-xr-x 4 root root 88 Sep 30 15:36 etc
drwxr-xr-x 3 root root 17 Sep 30 15:36 lib64
drwxr-xr-x 2 root root 21 Oct 13 15:29 sbin
drwxr-xr-x 7 root root 70 Oct 13 15:29 share
drwxr-xr-x 4 root root 28 Oct 13 15:29 var
the other two don't exist
So double-check your alias definition.
It is very weird the additional .1 just when executing the alias.
I am sorry, but these kind of infra-structure issues are a bit tricky to solve at distance.
I guess you already have the probable causes, symptoms, and remedies to check against your installation.
You might need to double check any environment variable, alias definition, and installation paths.
It is also a good idea to check Plesk's documentation to see if there is a straightforward way to change its PHP version. Maybe we are fighting against something that solvable by changing a configuration file.
Good luck =)
in my usr/bin folder I can see: php80 php80-cgi php80-pear php80-phar php81 php81-cgi php81-phar
when I run: sudo update-alternatives --set php /usr/bin/php81
I get: cannot access /var/lib/alternatives/php: No such file or directory
Ok so maybe I should downgrade my Laravel version to be compatible with php 7.4 hmm
YES!!! Thank you @rodrigo.pedra I just ran: alias php="/usr/bin/php81"
now when I do php -v I get:
PHP 8.1.11 (cli) (built: Sep 28 2022 09:08:05) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.1.11, Copyright (c) Zend Technologies
Although saying that... I can now run php artisan, great!
when I try and run composer install, I get a load of problems:
requires php >=8.1 -> your php version (7.4.32) does not satisfy that requirement
composer is essentially a PHP script, you can try running it like this:
First, discover composer's binary full path:
$ which composer
/usr/local/sbin/composer
/usr/local/sbin/composer above is just a sample, your output may be different.
Second run composer like this:
cd /path/to/your/project
/usr/bin/php81 /usr/local/sbin/composer install
@rodrigo.pedra this doesn't work
@rodrigo.pedra composer works but I get :
Root composer.json requires php ^8.0.2 but your php version (7.4.32) does not satisfy that requirement.
@boyjarv Try this:
$ composer install --ignore-platform-reqs
This is far from ideal. But may work in your case.
@rodrigo.pedra tried that, that didn't work
@rodrigo.pedra ok so I was using path sbin, should've been bin
now I get:
# Copyright 1999-2020. Plesk International GmbH. All Rights Reserved.
COMPOSER_BIN="/usr/local/psa/var/modules/composer/composer.phar"
[ -e "$COMPOSER_BIN" ] || { echo "'$COMPOSER_BIN' not found" >&2; exit 1; }
[ -x "$COMPOSER_BIN" ] || { echo "'$COMPOSER_BIN' is not executable" >&2; exit 1; }
"$COMPOSER_BIN" "$@"
@boyjarv so even the composer version you have installed is provided by plesk...
If this is a modified script by them, maybe running with PHP 8 will never work properly.
Maybe it is better to use Laravel 8 on this server so you can use PHP 7.4?
Or have a separate server without Plesk installed?
sudo php -v
PHP 8.1.11 (cli) (built: Sep 28 2022 09:08:05) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.1.11, Copyright (c) Zend Technologies
php -v
PHP 7.4.32 (cli) (built: Sep 30 2022 13:22:27) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with the ionCube PHP Loader + ionCube24 v11.0.1, Copyright (c) 2002-2022, by ionCube Ltd.
with Zend OPcache v7.4.32, Copyright (c), by Zend Technologies
Please help?
@Tray2 ooh sounds a bit drastic... anyone else help?
I uninstalled php version 7.4 in PLESK and when I run php -v form the server's command line now I get:
-bash: /opt/plesk/php/7.4/bin/php: No such file or directory
@boyjarv The php command is most likely a dynamic link, and probable placed in /usr/local/bin or /usr/bin.
If you do ls -la in one of those directories you will probably see something like this
php -> /opt/plesk/php/7.4/bin/php
Then do a rm php and then ln -s <path to php 8.1 > php
Then you should be good.
I've done it!, I got it working using 8.1 alias
Please or to participate in this conversation.