How to update PHP version
Hello everyone, In this article, we will understand how to update the PHP version. Before that let’s understand what is PHP.
PHP is a common server-side programming language. Many CMS and popular frames like WordPress, Magento and Laravel are written in PHP. While writing this article PHP 8.0 is the most recent major version of PHP.
PHP introduces a number of revolutionary changes, performance enhancements, and many new features such as named arguments, JIT compiler, union types, match expression and more. This post will show you how to install PHP 8 on Ubuntu 18.04 and integrate it with Apache for WordPress. The same steps apply to Ubuntu 20.04 also.
Check your PHP version installed.
Firstly, open the terminal, connect to your server using SSH, and switch to root account access or use sudo.
Note: Before upgrading or installing any PHP version, ensure that your applications support it.
ssh <USERNAME>@<SERVER_IP> sudo su -
Before we move ahead, we can check the existing installed PHP version on the server simply by typing the following command.
Check your PHP modules installed
To check installed PHP modules in Ubuntu, type the following command (as Ubuntu makes PHP modules available via packages
sudo dpkg --get-selections | grep -i php sudo update-alternatives --list php
Add PPA for PHP 8
In order to install PHP 8.0 on Ubuntu you may have to add third-party repositories and install from there.
Simply run the commands below to add the below repository to Ubuntu.
sudo apt-get install software-properties-common sudo add-apt-repository ppa:ondrej/php sudo apt update
Install PHP 8 for apache
To use PHP 8.0 with Apache instead, use the steps below:
For Apache2 you’ll want to run the commands below along with the installed modules above.
sudo apt install php8.0
After the installation has completed, you can confirm the installation using the following command.
Upgrade to PHP 8 for Apache
Once you have installed PHP 8 you need to upgrade to the latest installed version of PHP. You need to disable the old PHP version and enable the new PHP version 8.
sudo a2dismod php7.4 sudo a2enmod php8.0
After enabling PHP 8.0, run the commands below to restart Apache2 and PHP 8.0 should be used to support WordPress.
sudo systemctl restart apache2.service or sudo service apache2 restart
Testing PHP Processing
Suppose we have apache2 installed and we already deployed our site in that. Then we can test whether the web server is configured properly for PHP processing, by creating a new file named phpinfo.php inside the /var/www/html/ directory with the following code:
<?php // Show all information, defaults to INFO_ALL phpinfo(); ?>
Save the file, open your browser, and visit: https://dns-or-server_ip/phpinfo.php
Note: Let's consider you have WordPress website hosted on same machine and it uses current php then you might get below error.
PHP’s MySQL installation
Run the following commands depending on the PHP version to resolve the above error.
sudo apt-get update sudo apt-get install php8.0-mysql sudo systemctl restart apache2.service or sudo service apache2 restart