How To Install Or Upgrade To PHP 7.4 On GCE Ubuntu 18.04 Nginx

The PHP 7.4 release has been made available to public and for use in Production environments.

PHP is a popular server scripting language known for creating dynamic and interactive Web pages. PHP is widely-used programming language in the Web like popular CMS such as WordPress, Joomla, Drupal and many more.

You can upgrade your PHP to the latest release PHP 7.4 on your Google Cloud Compute Engine. But if you haven’t and want to setup your host on Google Cloud Compute Engine, see this How to host WordPress with Google Cloud Platform for FREE

Here is a brief guide to show you how to install and upgrade to PHP 7.4 on Ubuntu 18.04 with Nginx on Google Cloud, using LINUX command line interface.

Step 1 : Update To Latest Packages

Make sure your Ubuntu server is having the latest packages by running the following command.

sudo apt update
sudo apt upgrade 

Step 2 : Add PHP PPA Repository

We’ll add ppa:ondrej/php PPA repository which has the latest build packages of PHP.

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update 

Step 3 : Install PHP 7.4 And Extensions For Nginx

Execute the following command to install PHP 7.4 and extensions for our Nginx server

sudo apt install php7.4 php7.4-fpm 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 

After the installation has completed, you can check php version using the following command

php -v 

Output of successful installation PHP 7.4

PHP 7.4.5 (cli) (built: Apr 19 2020 07:36:30) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.5, Copyright (c), by Zend Technologies 

Check php-fpm version

php-fpm7.4 -v 

Output of successful installation PHP-fpm 7.4

PHP 7.4.5 (fpm-fcgi) (built: Apr 19 2020 07:36:30)
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.5, Copyright (c), by Zend Technologies 

Step 4 : Configure PHP 7.4

Now we configure PHP for Web Applications by changing some values in php.ini file.

sudo nano /etc/php/7.4/fpm/php.ini 

Hit F6 for search inside the editor and update the following values for better performance.

upload_max_filesize = 256M
post_max_size = 256M
max_execution_time = 600
max_input_time = 400
max_input_vars = 10000
memory_limit = 256M  

Step 5 : Update Nginx Configuration For Upgrade

Once installed and configured PHP 7.4, we can update the Nginx configuration to use PHP 7.4 for our website. You can skip this step if you are not upgrading from old PHP version.

sudo nano /etc/nginx/sites-availabale/yourdomainname.com 

Find your old version of php-fpm, for example 

fastcgi_pass unix:/run/php/php7.3-fpm.sock 

and change it to

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

Check your Nginx configuration

sudo nginx -t 

Output of successful Nginx configuration

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful 

Now we will restart PHP and Nginx for the changes to take effect.

sudo service php7.4-fpm restart
sudo service nginx restart 

Conclusion

Now you have learned how to install/upgrade to PHP 7.4 on your Ubuntu server.

Thanks for your time. If you face any problem or have any feedback, please leave a comment below.

Leave a Comment

Scroll to Top