Published: March 22, 2023 Author: JasonDarkX2 Category: Tech,Tutorials
Got an Ubuntu Apache server running an outdated version of PHP? Looking for a way to easily update PHP to version 8.0 or greater. Without much hassle, using the terminal/command line is the best method. So, fire up that terminal window or remote session if you’re working from home. It’s time to enter a series of commands. The current version of PHP is 8.2 and Ubuntu(LTS) is 22.04.2 at the time of writing.
Nevertheless, be sure that everything is compatible before initializing the update. It should be noted that WordPress 6.1 core will output a bunch of deprecated warnings if you update PHP to a version greater than 8.0. You can circumvent the issue by disabling WP_DEBUG in wp-config.php with define (‘WP_DEBUG’, false); What this will do is prevent PHP warning and error messages from showing. Have no fear your WordPress site would continue to work on PHP 8.0+ with deprecated warnings display disabled. So as long your themes and plugins are compatible and no other errors are present. Therefore, for consistency I’ll be assuming you are updating from an earlier version of PHP to PHP 8.0. Otherwise, if you’re looking to upgrade to a newer version, simply adjust the version number in the commands.
Step 1: Updating the dependency
$>sudo apt update
$>sudo apt upgrade
Step 2: Getting PPA repository
$>sudo apt install software-properties-common
$>sudo add-apt-repository ppa:ondrej/php
$>sudo apt update
Step 3: Install the newer version of PHP
$>sudo apt install php8.0
Step 4: Install PHP extensions
These are common extension, you'll want to have.
*if you're hosting WordPress site, be sure to install these as well*
$>sudo apt install php8.0-common php8.0-mysql php8.0-xml php8.0-xmlrpc php8.0-curl
php8.0-gd php8.0-imagick php8.0-cli php8.0-dev php8.0-imap php8.0-mbstring php8.0-opcache php8.0-soap
php8.0-zip php8.0-redis php8.0-intl -y
$>sudo apt install php8.0-sqlite3
$>sudo apt-get install php8.0-ssh2
Step 5: configure PHP
It's time to configure PHP, simply edit the following file:
$>sudo nano /etc/php/8.0/apache2/php.ini
Configure the following fields to your optimal settings. I changed mine to the following
To search in nano use F6 key to bring up the search. Otherwise in Vim use the /^
upload_max_filesize = 32M
post_max_size = 48M
memory_limit = 256M
max_execution_time = 600
max_input_vars = 3000
max_input_time = 1000
Step 6: Disable previous version and enable current version
You'll want to disable the older version and enable the version you'll like to use. Because Apache will continue using active PHP version, until you make the change.
$>sudo a2dismod php(your current active version)
sudo a2enmod php8.0
sudo service apache2 restart
Step 7: Uninstall previous version of PHP
Once everything is working correctly, you can simply remove all previous versions of PHP.
$>sudo apt-get purge php7.*
That's it Cheers!!
, Web Development