You should upgrade your PHP for your server to version 7.4 or higher for security reasons. You can find PHP version info from here: https://www.php.net/supported-versions.php. Here I am doing an upgrade from PHP version 7.2 to 7.4 on my Ubuntu server, before you do any changes, make sure you have a good backup of your server/application which may be running on your server.
To see current version:
command: php -version
output: PHP 7.2.24-0ubuntu0.18.04.7 and some other details of your server
First, make sure your server is up to date by running the following commands:
Command: apt update
Command: apt-upgrade
Then add repository to install PHP:
Command: add-apt-repository ppa:ondrej/php
Command: apt update
You will get message like this to continue or cancel:
To install PHP7.4
Command: apt install php7.4
To see the version you can re-run the command:
Command: php -version
Output: PHP 7.4.14 with some other info
Now you have the PHP 7.4 on your server you can update your application to take effect of newer version of PHP. Here is example of web server apache
Command: sudo a2enmod php7.4
Considering dependency mpm_prefork for php7.4:
Considering conflict mpm_event for mpm_prefork:
ERROR: Module mpm_event is enabled – cannot proceed due to conflicts. It needs to be disabled first!
Considering conflict mpm_worker for mpm_prefork:
ERROR: Could not enable dependency mpm_prefork for php7.4, aborting
To fix:
Command: sudo a2dismod mpm_event
Module mpm_event disabled.
To activate the new configuration, you need to run:
systemctl restart apache2
Before you restart, you will need to activate PHP7.4, otherwise you will get this error:
Command: sudo systemctl restart apache2
Install PHP 7.4 Extensions
Installing PHP extensions are simple with the following syntax.
Command: sudo apt install php7.4-extension_name
Here are some commonly used php-extensions
:
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
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
To search with nano editor: F6
or CTR+W 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
For web server to take effect restart the service:
Command: sudo systemctl restart apache2
Finally doing clean up of old stuff no longer needed:
Command: apt autoremove
That’s should it, if you have other applications you just have to update that, some may automatically be done, no other action needed. You should test everything to make sure all functioning well.