-1

I am on Linux Mint and had PHP 8.1 by default but I need to install PHP 8.3.

I removed the existing PHP 8.1 with apt-get remove php.

However, when I run the php command I still see PHP 8.1.

Shouldn't I get "command not found" if php was in fact removed?

5
  • Please don't post screenshots of text, post just the text. What's the output of type -a php? Did you install PHP via Homebrew or something like that by any chance? Commented Oct 27, 2024 at 22:48
  • type -a php returns "php is /usr/bin/php php is /bin/php". I don't recall exactly where the PHP 8.1 originally came from other than it was one of the default packages available for Linux Mint. Commented Oct 27, 2024 at 22:50
  • Try addressing 8.1 directly: sudo apt remove php8.1 Commented Oct 27, 2024 at 22:55
  • 2
    Look at the output of your apt remove command. It tells you that php isn't installed so the package you want to remove isn't php, it will have some other name. Try apt-cache search php. Commented Oct 27, 2024 at 22:58
  • dpkg -S `which php` Commented Oct 28, 2024 at 4:41

2 Answers 2

3

To answer the actual question: php on your system is most likely a metapackage (it's certainly a metapackage on Ubuntu - and it's most likely a metapackage on Linux Mint as well).

A metapackage is a package that basically only includes / installs dependencies. Which in a way means that the "actual" packages that are brought in by the metapackage are "hidden" behind the metapackage's generic name (in this case php).

If I was to inspect php's dependencies on Ubuntu, I would discover that sudo apt install php actually installs php8.3, as php depends on php8.3:

% apt-cache showpkg php | grep -A1 '^Dependencies:'
Dependencies: 
2:8.3+93ubuntu2 - php8.3 (0 (null))

Conversely (and this is why sudo apt remove php isn't removing PHP), sudo apt-remove php would remove nothing but the php metapackage, leaving php8.3 installed:

% sudo apt remove php
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  php
0 upgraded, 0 newly installed, 1 to remove and 3 not upgraded.
After this operation, 11.3 kB disk space will be freed.
Do you want to continue? [Y/n] 
(Reading database ... 229794 files and directories currently installed.)
Removing php (2:8.3+93ubuntu2) ...
% php -v
PHP 8.3.6 (cli) (built: Sep 30 2024 15:17:17) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.6, Copyright (c), by Zend Technologies

And to remove PHP 8.3, I should run sudo apt-remove php8.3 instead:

% sudo apt remove php8.3 
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  php8.3
0 upgraded, 0 newly installed, 1 to remove and 3 not upgraded.
After this operation, 62.5 kB disk space will be freed.
Do you want to continue? [Y/n] 
(Reading database ... 229791 files and directories currently installed.)
Removing php8.3 (8.3.6-0ubuntu0.24.04.2) ...

Right?

% php -v
PHP 8.3.6 (cli) (built: Sep 30 2024 15:17:17) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.6, Copyright (c), by Zend Technologies

Wrong! As php8.3 is also a metapackage that depends, transitively, on php8.3-cli, which is the package that actually provides the php executable.

I think you get the gist.

Every metapackage in the chain of dependencies creates a level of indirection, and makes it harder to get to "the real deal"; in this case, php8.3-cli would be the last on the chain (removing that would at least make php -v from the command line fail), however removing php8.3-cli would likely still leave some packages installed by sudo apt install php around.

Overall, sudo apt remove php8.3-cli followed by sudo apt autoremove will maybe get rid of everything (assuming nothing else depends on the leftover packages of course).

Some answers on the internet suggest running commands such as sudo apt remove 'php8.3*', which yes, essentially will remove at least most of what sudo apt install php installed.

However I've grown to dislike that method, because you need to be very careful in inspecting what packages are going to be removed as part of the removal process (anything depending on a package matched by the glob will be uninstalled), and since these days and age storage is usually not a problem, I usually play it safe and just don't bother.

Rather, if PHP 8.3 is not available on your installation, I'd just use a PPA as described in your answer and install PHP 8.3 alongside PHP 8.1. The installation process will manage alternatives and things will Just Work (mostly - the most glaring instance of what's not gonna work out of the box is PHP with Apache - if you're using PHP with Apache, Apache will need to be reconfigured to load the new version of mod_php via a2enmod / a2dismod, otherwise the older version of the module will still be loaded).

2
  • @StephenKitt Thanks! and yes while stranded in parsing the chain of dependencies I mistakenly read php8.3-cgi as php8.3-cli - turns out it kinda does depend on it anyways. :) Commented Oct 28, 2024 at 12:56
  • 1
    That’s right, libapache2-mod-php8.3 | php8.3-fpm | php8.3-cgi all depend on php8.3-cli. Commented Oct 28, 2024 at 12:57
-3

running apt update and apt upgrade after following https://medium.com/@nothanjack/how-to-run-php-8-3-on-linux-mint-21-a-comprehensive-tutorial-23df8b03e620 set my PHP to 8.3:

Step 1: Update the System

Before Steps To Run PHP 8.3 on Linux Mint 21 , it is crucial to update the system to ensure that all packages are current. Open the terminal and enter the following commands:

sudo apt update
sudo apt upgrade

Step 2: Add PHP Repository

Next, add the ondrej/php repository, which contains various PHP versions including PHP 8.3, by running the command:

sudo add-apt-repository ppa:ondrej/php
sudo apt update

Step 3: Install PHP 8.3

Once the repository is added, install PHP 8.3 with the following commands:

sudo apt install php8.3

Step 4: Configure PHP 8.3

After the installation, configure PHP 8.3 by updating the php.ini file and ensuring that necessary extensions are enabled. Use the following commands to achieve this:

sudo nano /etc/php/8.3/cli/php.ini
sudo nano /etc/php/8.3/apache2/php.ini

Step 5: Verify Installation

To verify the installation and check the PHP version, type the following command:

php -v

Step 6: Configure Web Server

If you are using a web server such as Apache or Nginx, make sure to configure it to work with PHP 8.3 by updating the necessary configuration files.

Step 7: Test PHP 8.3

Finally, create a PHP file containing and place it in the web server’s root directory. Access this file from a web browser to ensure PHP 8.3 is running correctly.

1
  • 2
    nah, if you uninstalled your mint version of php, it's gone. So, either you didn't uninstall php 8.1, or you had another installation of PHP 8.1 lying around. Generally not a great idea adding third-party PPAs for core functionality, my guess is that you did and that this whole article is more of a confounding factor. Commented Oct 28, 2024 at 11:23

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.