
You can upgrade PHP version to PHP 7.4 using following commands. This is tested on many systems running Ubuntu 18.04 like virtual machine instance on Google Cloud Cumpute Engine.
Follow the guide to install and Upgrade to PHP 7.4 on Ubuntu 18.04 with Apache Server and PHP 7.4-fpm with Nginx:
STEP 1: Adding PPA for PHP 7.4
Add the ondrej/phpwhich has PHP 7.4 package and other required PHP extensions.
sudo apt install software-properties-common sudo add-apt-repository ppa:ondrej/php sudo apt update
After adding PPA you can install PHP 7.4.
STEP 2: Installing PHP 7.4 for Apache
Run following command to install PHP 7.4
sudo apt install php7.4
STEP 3: Install PHP 7.4 Extensions
To install PHP extensions are simple with the following command.
sudo apt install php7.4-extensionname
Install some commonly used extensions with the following command.
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
You can confirm the installation if it has been installed or not using the following command:
php -v
STEP 4: Enable PHP 7.4 for Apache
Use Following commands to disable previous installed version of PHP and enable new one. Add version of the PHP which is currentry used by Apache and follow the commands:
sudo a2dismod php 7.2 sudo a2enmod php 7.4
You have to restart Apache to take effect the changes. For that run following command:
sudo service apache2 restart
STEP 5: Install PHP 7.4 FPM for Nginx
Execute the following command to install PHP 7.4 FPM:
sudo apt install php7.4-fpm
Follow the previous method above mentioned to install the extensions
After the installation has completed, to confirm that PHP 7.4 FPM has installed correctly with the following command:
php-fpm7.4 -v
STEP 6: Modify Nginx configuration to use PHP 7.4
You need to update the PHP-FPM socket in your Nginx configration located inside the site-available directory for Nginx . This will be located inside the location block location ~ \.php$
Edit configuration
sudo nano /etc/nginx/sites-available/your-conf
The line you need to modify will look like this…
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
Replace the old PHP version with the new version.
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
Test configration.
sudo nginx -t
Save the file and exit the editor and restart Nginx for the changes to take effect.
sudo service nginx restart
STEP 7: Configure PHP 7.4
Configure PHP for Web Applications by changing some values in php.ini file.
For PHP 7.4 with Apache the php.ini location will be in following directory.
sudo nano /etc/php/7.4/apache2/php.ini
For PHP 7.4 FPM with Nginx the php.ini location will be in following directory.
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 = 32M post_max_size = 48M memory_limit = 256M max_execution_time = 600 max_input_vars = 3000 max_input_time = 1000
After modifying your PHP settings you need to restart your Apache for the changes to take effect.
STEP 8: Configure PHP 7.4 FPM Pools
PHP 7.4 FPM allows you to configure the user and group that the service will run under. You can modify these with these commands
sudo nano /etc/php/7.4/fpm/pool.d/www.conf
Change the following lines by replacing the www-data with your username.
User = username group = username listen.owner = username listen.group = username
Hit CTRL+X and Y to save the configuration and check if the configuration is correct and restart PHP.
STEP 9: Restart PHP 7.4 FPM
After completion update, your PHP FPM settings you need to restart it to apply the changes.
sudo php-fpm7.4 -t sudo service php7.4-fpm restart
















