How to upgrade php version from 7.2 to php 7.3 in Ubuntu 16.04?

May 10, 2019 2.6k views
WordPress PHP LEMP PHP Frameworks DigitalOcean Nginx Ubuntu 16.04

I have a LEMP stack (Linux, Nginx, MySQL, and PHP) droplet in which i am running a wordpress website. I have got recommendation to upgrade my php version to php 7.3. So, how can i do it in the right way? Also i want to install bcmath and imagick module.
It will be very helpful if you describe it in detail step by step.
** Thanks in advance! :)**

2 Answers

Hi there @iamhimanshusrivastava,

You should be able to install Php 7.3 by running the following commands:

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt install php7.3

Installing most of the common Php packages can be achieved by using:

sudo apt-get install php7.3-fpm php7.3-cli php7.3-mysql php7.3-gd php7.3-imagick php7.3-recode php7.3-tidy php7.3-xmlrpc

You can then restart Php & Nginx with the following:

sudo systemctl restart nginx.service
sudo systemctl restart php7.3-fpm

Once that is done, nginx should be using php 7.3 - You can verify this by creating a new php file at the root of your website with the following contents:

<?php
phpinfo();

You can then access this file in a browser to confirm that the correct version of php is running.

Hope that helps!
- Matt.

Upgrade to php7.3

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y php7.3

Check php version

php -v

I hope this helps

Have another answer? Share your knowledge.