03 December, 2020

Upgrade to PHP 8.0 (On Linux, and Windows)

LINUX:

1. List existing PHP packages with:
$ dpkg -l | grep php | tee packages.txt
2. Add ondrej/php PPA with:
$ sudo add-apt-repository ppa:ondrej/php
# Press enter when prompted.
$ sudo apt-get update

3. Install PHP 8.0 and extensions with:
$ sudo apt install php8.0-common php8.0-cli -y
# Check with:
$ php -v
# Add additional extensions:
$ sudo apt install php8.0-{bz2,curl,intl,mysql,readline,xml}
Install Server APIs:
Depending on the web server you use, you will need to install additional packages to integrate with the web server.
For Apache using mpm_event, Nginx, Litespeed, etc., php8.0-fpm package provides integration with PHP 8.0 via FPM.
$ sudo apt install php8.0-fpm
For Apache using mod_php, install libapache2-mod-php8.0.
$ sudo apt install libapache2-mod-php8.0
4. Test PHP 8.0 installation with:
$ php -v
$ php -m
5. Purge old PHP versions:
If the new installation is working as expected, you can remove the old PHP packages from the system.
$ sudo apt purge '^php7.4.*'
6. What's new and changed in PHP 8.0:
For a complete list of changes in PHP 8.0, see What's new and changed in PHP 8.0 https://php.watch/versions/8.0

** For Valet on Linux, re-config it with the command :
"valet use" to choose php8.0 by default by Velet.

WINDOWS:

Download the php8 for windows from windows.php.net/download and extract it in a directory like "C:\laragon\bin\php" Then add this path to the windows Env variable, and remove previous php one (if you have any). Then Go to your apache directory like "C:\laragon\etc\apache2" and open the mode_php.conf file as Administrator, then change the line
LoadModule php8_module "C:/laragon/bin/php/php-8.0.0-Win32-vs16-x64/php8apache2_4.dll"
with
LoadModule php_module "C:/laragon/bin/php/php-8.0.0-Win32-vs16-x64/php8apache2_4.dll"
That means you write php_module instead of php8_module there.
Then go to "C:\laragon\bin\php\php-8.0.0-Win32-vs16-x64" directory and rename php.ini-development as php.ini or just edit existing php.ini file as your need (Extensions you need). Just simply uncomment (remove semicolons ";" from lines ) to doing so.
Then restart the apache, and you will good to go.