You are not logged in.

#1 2021-02-19 21:37:53

karcher
Member
Registered: 2018-01-09
Posts: 140

Multiple php versions possible?

Hi all,

Currently I have installed the latest php version (v.8.0.2) installed on my system, but I need php 7  too.

Is there any way to have multiple php versions installed and switch easily?

Offline

#2 2021-02-19 21:44:55

frostschutz
Member
Registered: 2013-11-15
Posts: 1,417

Re: Multiple php versions possible?

there is the separate php7 package https://archlinux.org/news/php-80-and-p … available/

for other versions you have to resort to AUR

Offline

#3 2021-02-19 21:49:14

karcher
Member
Registered: 2018-01-09
Posts: 140

Re: Multiple php versions possible?

Thanks!
So I can have multiple versions installed. Any idea how can I switch from one version to another?

Offline

#4 2021-02-19 21:51:04

loqs
Member
Registered: 2014-03-06
Posts: 17,321

Re: Multiple php versions possible?

Define switch.  Have you read php-80-and-php-7-legacy-packages-are-available?

Offline

#5 2021-02-19 22:00:10

frostschutz
Member
Registered: 2013-11-15
Posts: 1,417

Re: Multiple php versions possible?

depends on webserver configuration

Offline

#6 2021-02-19 22:17:13

karcher
Member
Registered: 2018-01-09
Posts: 140

Re: Multiple php versions possible?

Define switch.  Have you read php-80-and-php-7-legacy-packages-are-available?

switch PHP versions like pyenv does with python versions. Yes.

depends on webserver configuration

I need it for composer. I've modified its config according to this:
https://stackoverflow.com/questions/262 … -version-y

Last edited by karcher (2021-02-19 22:17:35)

Offline

#7 2021-03-08 17:38:45

markhadman
Member
Registered: 2010-10-09
Posts: 39

Re: Multiple php versions possible?

Hi karcher,

I've run into this problem too.

Both my intended servers (friendica and ampache) are unready for php v8, so I've installed php7 instead. Ampache uses composer for dependency setup, but composer depends on php, which is not 'provided' by the php7 package.

I'm not sure whether I should force the composer installation without allowing php (8) to be installed, or install both versions of php, or whether it'll even work with php7 anyway. Perhaps you could give us an update - have you managed to maintain stability?

Offline

#8 2021-03-29 15:12:27

jost21
Member
Registered: 2021-03-29
Posts: 6

Re: Multiple php versions possible?

Hey karcher,

have you found a solution? I have the same problem.

Offline

#9 2021-05-07 19:25:30

dklymenk
Member
Registered: 2021-05-07
Posts: 7

Re: Multiple php versions possible?

I can suggest a few solutions:

1. Just replace "/usr/bin/php" with a symlink to the version you need.
If you have installed packages php (8.0), php7(7.4) from main repo and let's say 7.2 from AUR, to get started you would need to do the following

cd /usr/bin
sudo mv php php8

After this you would just create symlink:

sudo ln -sf php72 php # for 7.2
sudo ln -sf php7 php # for 7.4
sudo ln -sf php8 php # for 8.0

And every time you need to change version, you cd back and rerun one of these command or create an alias for it and run that.
This is not recommended as, I assume, every time the php package gets updated. you would get some error or your symlink would be overwritten.
However, if you don't need to use php 8.0 in your development environment, just uninstall that package and there shouldn't be any problems with this approach.

2. Use phpenv to manage all your php versions. There is an AUR package that pulls some fork that's behind master by 3 commits, I would ignore that one.
Allows you to do everything you would expect: set global php version, set local (project-wide) version, set version for current shell only.
There is a major annoyance with this approach regarding version management. It doesn't allow you to just install latest 7.4 or 8.0 release, you need to select specific patch version (e.g. 8.0.5).
One big advantage of phpenv is you can use it as a team since you can version the .php-version file created by `phpenv local` command.

3. It's not documented anywhere on phpenv README, but you can use any php version installed on your system by creating a folder structure for that version.

# example for 7.4
mkdir -p ~/.phpenv/versions/7.4/bin
ln -s /usr/bin/php7 ~/.phpenv/versions/7.4/bin/php
phpenv versions # should report 7.4 as available

This solution is slightly more superior as it allows you to update the binary with pacman and not rebuilding it manually.
The only drawback is if you plan to use this tool as a team, because phpenv is very specific with versions. (If project has `.php-version` file with `7.4` inside and your teammate has 7.4.18 installed via phpenv, it'll throw an error for him "phpenv: version `7.4' is not installed").
So either everyone on your team needs to manually create these folders you can't normally create with phpenv, or you have to create symlinks like this one on your machine ` ln -s  ~/.phpenv/versions/7.4 ~/.phpenv/versions/7.4.18`.

Offline

Board footer

Powered by FluxBB