How to properly install lower PHP versions on AUR

Hello, I am new to endeavorOS. I am planning to make this my daily driver for web development because it’s cool lol. Now, I am scratching my head since I can’t properly install a lower version of PHP which is 7.2. Anyone can help me?

Try looking through this list to see which package you might need and installing it with yay

https://aur.archlinux.org/packages?O=0&K=php72

For example to install the php72 package on page 2, you would do:

yay -S php72

Thank you for your reply. That exactly what I did several minutes ago and still patiently waiting for the random text appearing on the console to end. Just curious, why is it taking so long to install a single package?

It’s the AUR so these aren’t pre-built packages like you have in the Official Arch repos, you’re basically gathering everything you need from the package build and doing it all from scratch, so depending on your internet speed and how many dependencies get pulled it and what all needs to be complied it could take anywhere from 1 minute to 20 minutes to download, compile, and install. As long as it’s running and text is flowing, it’s doing it’s job.

1 Like

Makes sense. I appreciate the clarification.

1 Like

there’s a problem though… a lot of packages you use during development depend on package php. which pulls PHP 8.x on Arch (EOS). Which means you will have both PHP 7.2 and PHP 8 on your system.
On arch if you install package php the command php is bound to version 8 which will cause a lot of problems if what you expect is to have PHP 7.2 running for your scripts.

Here’s how I deal with this, I have both packages php and php7 (the last one from AUR and installs PHP 7.6x) installed and I run this script every time the package php gets an update:

#!/bin/bash
#Change default php from php8 to php7
cd /bin
if [[ -f php ]] ; then
    if [[ -f php8 ]] ; then 
    #if we have already created php8 before, delete it as it is obsolete now
        sudo rm php8
    fi
    sudo mv php php8 #make a backup just in case
    sudo ln -s php7 php
fi

Note 1: I would not do this on a production server. This is a solution for my development machine.

Note 2: It’s generally not a good idea to change files inside the /bin folder, but then again if you know what you’re doing and it gets your stuff working… you own the system in the end, that’s the good thing about Linux: you are responsible for what you do on your system. with the script above all you have to do to roll back the changes done by the script is to delete the symlink /bin/php and mv /bin/php8 /bin/php.

That being said, you might get away with not installing package php at all, and only rely on php72 if your tools don’t pull php as a dependency.

2 Likes

Indeed :slight_smile:
Simply create a symlink /usr/local/bin/php instead…

2 Likes

Yup.

There are other options too, like adding something like $HOME/.local/bin or $HOME/bin to your $PATH and using that to override the executable in /usr/bin (plus that way you don’t need sudo).

3 Likes

Update: Got the system working now guys and it’s been fine for days now. I have installed 7.2 from AUR, 7.4 and 8.1 from official repo. I just aliased each version along with the composer to keep “isolated” and separated for each project that need that specific version.

1 Like

I had no idea you can override /bin files like this. That’s great, and makes my script obsolete.

Thanks for the input.

1 Like