Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

boyjarv's avatar

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

0 likes
39 replies
Sinnbeck's avatar

@boyjarv and that means? I mean it can mean so many things

  1. The installation failed
  2. Your server broke completely
  3. It installed fine but cli is still running 7.4
  4. It installed fine but nginx is still running 7.4
  5. ...
boyjarv's avatar

I think it installed but when I do php -v it’s still showing 7.4

boyjarv's avatar

@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>
Sinnbeck's avatar

@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
Tray2's avatar

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.

boyjarv's avatar

which php

alias php='/opt/plesk/php/7.4/bin/php'
	/opt/plesk/php/7.4/bin/php
Sinnbeck's avatar

@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 🤷‍♂️

rodrigo.pedra's avatar

@boyjarv

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?
boyjarv's avatar

@rodrigo.pedra ah ha! I think you are right, I think it is aliased, how can I turn off aliasing?

Thanks

1 like
rodrigo.pedra's avatar

@boyjarv

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.

boyjarv's avatar

@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"
rodrigo.pedra's avatar

@boyjarv

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.

boyjarv's avatar

@rodrigo.pedra

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)

rodrigo.pedra's avatar

@boyjarv

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
boyjarv's avatar

@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

rodrigo.pedra's avatar

@boyjarv

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

boyjarv's avatar

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

boyjarv's avatar

Ok so maybe I should downgrade my Laravel version to be compatible with php 7.4 hmm

Sinnbeck's avatar

@boyjarv 7.4 will get no more security updates after November. So I recommend figuring it out

1 like
boyjarv's avatar

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
1 like
boyjarv's avatar

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
rodrigo.pedra's avatar

@boyjarv

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
boyjarv's avatar

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

rodrigo.pedra's avatar

@boyjarv Try this:

$ composer install --ignore-platform-reqs

This is far from ideal. But may work in your case.

boyjarv's avatar

@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" "$@"
1 like
rodrigo.pedra's avatar

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

boyjarv's avatar

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's avatar

@boyjarv Simplest would be to run

yum remove plesk-server

Or whatever that package is called.

boyjarv's avatar

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
Tray2's avatar

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

boyjarv's avatar

I've done it!, I got it working using 8.1 alias

1 like

Please or to participate in this conversation.