Upgrading to PHP 7.3
The awaited latest version of the PHP 7.3 was released on 6th December 2018. Along with 7.3 release, 4 other PHP versions were updated.
- 5.6.39
- 7.0.33
- 7.1.25
- 7.2.13
- 7.3.0
PHP 5.6.39 and PHP 7.0.33 are both security releases considered to be the last release in their respective branches.
PHP 7.1 is now security only.
Users of these are required to immediately switch to 7.2 or 7.3.
To update your version of PHP to 7.3:
1. Add the ondrej/php PPA
Ubuntu:
sudo add-apt-repository ppa:ondrej/php # Press enter to confirm.
sudo apt-get update
Debian:
sudo apt install apt-transport-https lsb-release
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg # Download the signing key
sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list' # Add Ondrej's repo to sources list.
sudo apt update
2. Install PHP 7.3 and required extensions
To install PHP 7.3 core:
sudo apt install php7.3 php7.3-common php7.3-cli
Install required extensions:
Simply prefix php7.3-
with an extension that's required.
For example to get the php-curl extension use php7.3-curl
sudo apt install php7.3-curl php7.3-json php7.3-gd php7.3-mbstring php7.3-intl php7.3-bcmath php7.3-bz2 php7.3-readline php7.3-zip
PHP 7.3 for web server:
To integrate PHP with your web server, If you are using Nginx, or Apache with mod_event, you will need to install php7.3-fpm
package. If you are using PHP as an embedded Apache module, you will need the packagelibapache2-mod-php7.3
. For Apache, you can use apachectl -V
to see your current MPM, whether it'sprefork
or event
.
Nginx and Apache with event
MPM:
sudo apt install php7.3-fpm
Apache with prefork
MPM:
sudo apt install libapache2-mod-php7.3
3. Uninstall old PHP versions:
sudo apt purge php7.2 libapache2-mod-php7.2 # For removing PHP 7.2
sudo apt purge php7.1 libapache2-mod-php7.1 # For removing PHP 7.1
sudo apt purge php7.0 libapache2-mod-php7.0 # For removing PHP 7.0
4. Enable php7.3 for Apache
sudo a2enmod php7.3
5. Verify PHP 7.3 installation:
To verify the installation of PHP 7.3
From CLI:
php -v
From web server:
Create a file info.php
. It must be saved to a very specific directory, which is called the "web root". In Ubuntu and Debian this is located at /var/www/html/
.
sudo nano /var/www/html/info.php<?php
phpinfo();
?>
When you are finished, save and close the file.
Now visit this script in your browser.
http://your_server_IP_address/info.php
You should see something similar to this.
This page basically gives you information about your server from the perspective of PHP. It is useful for debugging and to ensure that your settings are being applied correctly.
You should remove this file after this test because it could actually give information about your server to unauthorized users. To do this, you can type this:
sudo rm /var/www/html/info.php
So now you have PHP 7.3 up and running. See the migration guide for PHP 7.3 at php.net
Originally published at A coder’s words.