fbpx

How to update PHP version to PHP 7.4 on Ubuntu

· >

In my previous post, i had Installed LEMP stack on Ubuntu server and then in another post installed wordpress on that server. But that WordPress site health recommendations were to update PHP version to PHP 7.4 for better performance and security.

So, in this post we will learn to update PHP version to PHP 7.4 on our Ubuntu server. These configuration has been tested on live environment, here is step by step procedure which i followed.

Add Ondrej/ppa Repository to Ubuntu Server

Login in your ubuntu server with sudo privileges. We need to update our repository by adding Ondrej/ppa respository.

Then perform an update & upgrade to download all required stuff.

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

Install Missing PHP Extensions

Once repositories are upgraded, if any extension is missing, you can proceed for manual installation.

sudo apt install php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring php7.4-opcache php7.4-soap php7.4-zip php7.4-intl -y

Remove Old PHP Versions

As, you have upgraded your PHP version check this with php -v command it should show output like this.

PHP 7.4.8 (cli) (built: Jul 13 2020 16:45:47) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.8, Copyright (c), by Zend Technologies

Once PHP version has been updated, now we can delete previous versions of PHP. like if you want to remove php7.2 version from your server, change it accordingly in below command.

Example:

sudo apt purge php7.3-* libapache2-mod-php7.3 -y # For removing PHP 7.3
sudo apt purge php7.2-* libapache2-mod-php7.2 -y # For removing PHP 7.2

Modify Nginx Configurations

Now it is time to update your nginx configuration file to use PHP 7.4 version . Your website nginx configuration file might be placed at either of below mentioned location depending on how you setup the nginx.

/etc/nginx/sites-enabled/yoursite.conf

OR

/etc/nginx/conf.d/yoursite.conf

Edit the file with your favorite editor and look for below mentioned line.

fastcgi_pass unix:/run/php/php7.0-fpm.sock; 

Replace 7.0 with 7.4 and save the file.

fastcgi_pass unix:/run/php/php7.4-fpm.sock; 

Now test your nginx configuration file and restart the nginx service.

sudo nginx -t
sudo systemctl restart nginx

That’s it, you have successfully updated your PHP version on your ubuntu server.

ALSO READ:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments