POPOS: How to revert PHP to 8.0 - php

I use PopOs for work. PopOs has released version 22.4 but it comes with PHP 8.1 and our development project (Laravel) uses php_cs_fixer and it currently only supports PHP 8.0. I was tasked to test if we should upgrade to PopOs 22.4 yesterday. I tested phpbrew and homebrew. Neither of them worked well. phpbrew doesn't work once I upgrade to PHP 8.1 (it has a single deprecated function in it, everywhere). Homebrew didn't seem to work and recommended editing the apache2 httpd.conf file, but our project isn't using Apache. I currently have PHP 8.0 installed (found at /usr/bin/php8.0) but the cli still says I'm using PHP 8.1.7. I used update-alternatives --set php /usr/bin/php8.0 to try and change the version the cli is using but that doesn't seem to work although when I when I execute update-alternatives --display php it reports that my link is pointing to /usr/bin/php8.0. Yet, php -v returns:
PHP 8.1.7 (cli) (built: Jun 7 2022 18:21:38) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.7, Copyright (c) Zend Technologies with Zend OPcache v8.1.7, Copyright (c), by Zend Technologies
I'm desperate, this is my work computer and I need to get this working. How does one literally revert from PHP 8.1 back down to version 8.0?

You can uninstall the php 8.1 directly through the terminal.
sudo apt remove php8.1
sudo apt autoremove
Hope this help you.

Related

PECL fails to install Xdebug on PHP 8.1 because it thinks I'm on PHP version 7.4

I've searched far and wide, tried everything but I can't get to install Xdebug on PHP 8.1
I've got multiple PHP versions installed via homebrew, when I switch to PHP 8.1 and try to install Xdebug I get the following:
BE-C02CRC3FMD6N:~ treynaert$ php -v
PHP 8.1.14 (cli) (built: Jan 9 2023 16:02:41) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.14, Copyright (c) Zend Technologies
BE-C02CRC3FMD6N:~ treynaert$ pecl install xdebug
pecl/xdebug requires PHP (version >= 8.0.0, version <= 8.2.99), installed version is 7.4.33
No valid packages found
install failed
As you can see, php -v returns 8.1, phpinfo() in the browser gives me the same. Though for some reason pecl thinks I'm on 7.4.
I'm on Mac OSX Catalina BTW (10.15.7)
Anyone has a clue?

Can't update from PHP 7.1 to PHP 7.2 on Mac

To be more precise, I don't even see where PHP 7.1 is installed.
When I run php -v in the terminal, I get:
PHP 7.1.23 (cli) (built: Feb 22 2019 22:19:32) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
So I thought I would use Homebrew to unlink 7.1 and install 7.2. Should be straightforward. However, running brew unlink php71 returns an error saying:
No such keg: /usr/local/Cellar/php71
And, indeed, in /usr/local/Cellar there is nothing resembling a PHP version.
I tried running brew update and brew upgrade just in case, but it didn't help.
I also tried running a PHP application locally and did phpinfo() within the application, and I got the same version info I got in the console.
When I ran whereis php it gave me the result /usr/bin/php. When I ran whereis php71 it came up with nothing which, I suppose, is to be expected in this situation.
The question is, how do I replace PHP 7.1 with 7.2 in the least painful way? Ideally, I would like to get brew to do this so I can update future version through brew as well.
Mac OS has its own PHP version installed, which is complete independent from brew.
You need to force link your brew version.
brew link php#7.2 --force

Drupal 8 installation setup shows older PHP version than what the server is running

When installing Drupal 8, just before database setup, I get a few errors and warnings, but I also see the following:
PHP
7.1.14-1+ubuntu16.04.1+deb.sury.org+1
However, doing php -v I get:
PHP 7.2.2-3+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Feb 6 2018 16:11:23) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.2-3+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
Clearly, my web server is running 7.2 but Drupal thinks it's 7.1. This is causing a problem where I have gd installed on PHP 7.2, but Drupal doesn't see gd installed on PHP 7.1 (because it isn't, at least its php.ini file doesn't have the gd extension enabled). Same with a few of the other errors and warnings.
How can I get Drupal 8 to recognize the correct PHP version?
So I figured it out:
Runing sudo a2dismod php7.1 then sudo a2enmod php7.2 seems to work perfectly (after a restart of Apache).
Try To install using composer
This method creates a project in web folder and other files outside web folder
composer create-project drupal-composer/drupal-project:8.x-dev d8_test_project --stability dev --no-interaction
Or
This method creates a project in a normal folder structure
composer create-project drupal/drupal my_site_name 8.*#dev --no-dev
I don't think it's about "recognizing" version, but you most likely have 2 different versions, one for console and other for web server. Run phpinfo() and see what PHP version is used by web server.

Class Memcached Not Found Lumen 5.4

When trying to run artisan commands I get the following error
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'Memcached' not found
I had recently been been working on another project that used Lumen 5.3 and had no problem running artisan commands. Both projects are on the same virtual box and apart from the Lumen versions there is no differences in server setup.
I've checked that Memcached is running and there is no problems.
I've tried composer dump-autoload, deleting the vendor folder and re-installing but none of these have made a difference.
I'd prefer not to have to go back to 5.3 if possible.
Is there a way to solve this issue?
Had the same problem.
Check if you have the memcached extension installed for the php version that you're using, and check also if it is correctly configured in the php.ini file (it could be looking in the wrong directory).
looks like your memcahed is not installed or not properly configured.
for quick solution ,
use file cache driver instead of memcached
CACHE_DRIVER=file
Ubuntu 16.04 LTS, try this:
sudo apt-get install php-memcached
Just to add to the os specific responses. Here is the one using OS/X and homebrew.
First you have to determine which version of PHP you're using locally.
$ php -v
PHP 7.0.19 (cli) (built: May 21 2017 11:56:11) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
$ brew search memcached
homebrew/php/php53-memcached homebrew/php/php70-memcached
homebrew/php/php54-memcached homebrew/php/php71-memcached
homebrew/php/php55-memcached libmemcached ✔
homebrew/php/php56-memcached memcached ✔
Since I'm running PHP 7.0 I chose to install homebrew/php/php70-memcached
$ brew install homebrew/php/php70-memcached
If you don't have homebrew installed go to https://brew.sh/ and install it to use these instructions. This was the command last time I used it.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Once I was done with all that then I tested by clearing the cache.
$ php artisan cache:clear
Cache cleared successfully.
$
Cheers, this fixed it for me for local development.
If you are on Mac OSX, you will need to install Memcached and its PHP dependencies via Homebrew.
brew update
brew doctor
brew install memcached
Then check your PHP version and install your relevant PHP hooks for Memcached.
php -v
in my case...
PHP 7.1.4 (cli) (built: Apr 14 2017 15:02:16) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
So I used:
brew install php71-memcached
But you can lookup your required version using
brew search memcached
Once you have performed these steps you will probably get a new error
No Memcached servers added.
So fire it up with
brew services restart memcached
Done!

Laravel 5.1 with php 5.5 to update to php 7 issue on OSX

I'm currently running a Laravel 5.1 app with php 5.5 and nginx on my Mac OSX, I want to update php to php 7.0 so I typed the following in terminal:
brew unlink php55
brew uninstall php55
brew install --with-fpm --with-mysql php70
It works and after that,
php -v
gives me the following response:
PHP 7.0.0RC4 (cli) (built: Oct 5 2015 03:44:48)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0-dev, Copyright (c) 1998-2015 Zend Technologies
I then restarted nginx, but when I tried to echo phpinfo in my existing Laravel app, it still says current version of php is 5.5, what else do I need to setup for Laravel 5.1 to run on top of my newly installed php 7.0?
Well, turns out I didn't restart php-fpm, so after killed the old php-fpm and then
php70-fpm start
nginx -s reload
Everything worked out perfectly.

Categories