# How to make new PHP version a system default?

**URL:** <https://forum.virtualmin.com/t/how-to-make-new-php-version-a-system-default/123280>\
**Category:** Help! (Home for newbies)\
**Created:** [October 31, 2023, 2:56pm UTC](https://forum.virtualmin.com/t/how-to-make-new-php-version-a-system-default/123280 "2023-10-31T14:56:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![MoreKoo](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/morekoo/32/11580_2.png) [@MoreKoo](https://forum.virtualmin.com/u/MoreKoo)\
**Post date:** [October 31, 2023, 2:56pm UTC](https://forum.virtualmin.com/t/how-to-make-new-php-version-a-system-default/123280/1 "2023-10-31T14:56:42Z")

</div>

| SYSTEM INFORMATION | |
| --- | --- |
| OS type and version | AlmaLinux 9.2 |
| Webmin version | 2.101 |
| Virtualmin version | 7.8.2 |

This question has been asked here couple of times, but I can’t find a decent answer.

I got PHP 8.0 with AlmaLinux 9.2 package. I’m running Laravel 10, which requires PHP 8.2. I installed it following this instructions: [Multiple PHP Versions – Virtualmin](https://www.virtualmin.com/documentation/web/multiplephp/).

Laravel works, no problems, even _php --version_ on the CLI shows 8.2 version. But PHP 8.0 “ghost” is giving headeache.

For example, when I run _composer update_ to get new libraries, it automatically takes PHP 8.0, which then generates errors (since Laravel is expecting 8.2). Yes, I know, I can use syntax “/usr/bin/php82 /usr/local/bin/composer update”, but I’d rather not.

The other problem is to use “su root” and running php commands. Root is using the system default version 8.0, and usually I need 8.2.

This can’t be that difficult? I just want to get rid of PHP 8.0, entirely, and use only 8.2 - for all virtual servers in the system. Or, alternatively, change the system default to PHP 8.2 and forget 8.0 for good.

I know someone here knows how to do that. Please, share your wishdom. And please, no workarounds, I think I know them all, and they won’t make me happy 🙂

Thanks in advance, More / Helsinki

---

<div class="post-metadata">

**Author:** ![MoreKoo](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/morekoo/32/11580_2.png) [@MoreKoo](https://forum.virtualmin.com/u/MoreKoo)\
**Post date:** [November 1, 2023, 4:46pm UTC](https://forum.virtualmin.com/t/how-to-make-new-php-version-a-system-default/123280/2 "2023-11-01T16:46:30Z")

</div>

…and to continue, this workaround is not perfect either:

1. Go to /usr/bin
2. rename **php** → **php80**
3. create symbolick link, which points from /usr/bin/php → /opt/remi/php82/root/usr/bin/php

It works for a while. All php commands, anywhere, with any account, run the 8.2 version. **Until** there’s an update for the 8.0 PHP package, which will recreate /usr/bin/php

**Still waiting for pointers or the solution** , thanks!

---

<div class="post-metadata">

**Author:** ![shoulders](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/shoulders/32/10086_2.png) [@shoulders](https://forum.virtualmin.com/u/shoulders)\
**Post date:** [November 22, 2023, 9:23am UTC](https://forum.virtualmin.com/t/how-to-make-new-php-version-a-system-default/123280/3 "2023-11-22T09:23:47Z")

</div>

I have seen this mentioned before, the **update-alternative** command for changing your default PHP version. I have not tried this and I do not know if it breaks virtualmin.

> **[How To Install PHP (8.2, 8.1, 7.4) on Ubuntu 22.04 – TecAdmin](https://tecadmin.net/how-to-install-php-on-ubuntu-22-04/)**
>
> PHP is a programming language used for developing web applications. You must install PHP packages on a Ubuntu system to run the application written on it. Generally, it is used to create e-commerce websites, blogs, and API applications. If you’re...

---

<div class="post-metadata">

**Author:** ![villasweb](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/villasweb/32/12402_2.png) [@villasweb](https://forum.virtualmin.com/u/villasweb)\
**Post date:** [December 26, 2023, 2:09pm UTC](https://forum.virtualmin.com/t/how-to-make-new-php-version-a-system-default/123280/4 "2023-12-26T14:09:31Z")

</div>

Same question. Any ideas how to change php version? I use 8.1.2 but I wanto to change to 8.2. Thank’s

---

<div class="post-metadata">

**Author:** ![Ilia](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/ilia/32/10185_2.png) [@Ilia](https://forum.virtualmin.com/u/Ilia)\
**Post date:** [December 26, 2023, 4:01pm UTC](https://forum.virtualmin.com/t/how-to-make-new-php-version-a-system-default/123280/5 "2023-12-26T16:01:27Z")

</div>

> [@villasweb](#):
>
> Same question. Any ideas how to change php version? I use 8.1.2 but I wanto to change to 8.2.

This is the right way to install and setup additional PHP version:

> **[Configuring Multiple PHP Versions](https://www.virtualmin.com/docs/server-components/configuring-multiple-php-versions/)**
>
> Virtualmin allows the selection of different PHP versions and execution modes for each domain. The recommended execution mode is FPM, but CGI/FCGId is also available, enabling per-directory PHP version settings.
> Installing additional PHP versions On...

---

<div class="post-metadata">

**Author:** ![Joe](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/joe/32/9_2.png) [@Joe](https://forum.virtualmin.com/u/Joe)\
**Post date:** [December 26, 2023, 9:58pm UTC](https://forum.virtualmin.com/t/how-to-make-new-php-version-a-system-default/123280/6 "2023-12-26T21:58:49Z")

</div>

> [@shoulders](#):
>
> I do not know if it breaks virtualmin.

It definitely does not break Virtualmin. Virtualmin is not written in PHP and doesn’t use PHP for anything.

It might break your apps if they have CLI/cronjobs that depend on `php` pointing to a specific version other than what you change it to. You can solve that by changing those usages to explicitly include a version, e.g. `php82`.

Note `alternatives` does not change what Virtualmin considers the default. For that, you can choose it in Server Templates-\>PHP Options. Nearly any “how do I change the default X that is configurable on a per-domain basis” in Virtualmin is answered by looking in Server Templates. I’d encourage y’all to poke around in there, just for the overview of the system it’ll give you. (Note that since it is a template option, you can have many “defaults”. i.e. you could make a “Old PHP” template for your customers that are running some cranky old application and need PHP 7.x, while everybody else gets a normal template with a new PHP version.)

 ![image](https://cdn.forum.virtualmin.com/uploads/default/original/2X/6/68e50ecdb3bf06176545241e538c34a0296d0b38.png)

Edit: I’ll also mention that I don’t use `alternatives` for this. I just make sure I explicitly call the version of PHP I need for CLI and cron stuff, so that it can’t be broken by some distant action later (like changing links or whatever that `alternatives` might do).

---

<div class="post-metadata">

**Author:** ![Ilia](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/ilia/32/10185_2.png) [@Ilia](https://forum.virtualmin.com/u/Ilia)\
**Post date:** [December 27, 2023, 6:10pm UTC](https://forum.virtualmin.com/t/how-to-make-new-php-version-a-system-default/123280/7 "2023-12-27T18:10:39Z")

</div>

> [@Joe](#):
>
> I just make sure I explicitly call the version of PHP I need for CLI and cron stuff, so that it can’t be broken by some distant action later (like changing links or whatever that `alternatives` might do).

Yeah, I also wouldn’t rely on `alternatives`. However, if the default shell is called, for example when a user logs in via SSH, the PHP version used by default, i.e. when called `php`, would be extracted based on `/etc/profile.d/virtualmin-phpalias.sh` profile.

That said, probably the better way to call PHP directly in CLI would be using `~/bin/php` or `$HOME/bin/php`, so if the PHP version change at some point in **PHP Options** page, then the expected PHP version would still be called.

---

<div class="post-metadata">

**Author:** ![system](https://cdn.forum.virtualmin.com/uploads/default/original/2X/c/cd96d761e326db4b2bef94886a639109bd7a8e76.svg) [@system](https://forum.virtualmin.com/u/system)\
**Post date:** [February 25, 2024, 6:11pm UTC](https://forum.virtualmin.com/t/how-to-make-new-php-version-a-system-default/123280/8 "2024-02-25T18:11:27Z")

</div>

Closed on February 25, 2024, 6:11pm UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
