Logo



Services

Digital Marketing Services

Web Design and Development

Digital Transformation

App Design and Development

Cloud Solution Services

Local IQ™ – Localization Intelligence

Work

Blog

About

Upgrading PHP on an Amazon Lightsail instance isn’t so straightforward. In fact, we recently worked through this process on a Debian server running Apache and WordPress. Getting the PHP repository, Apache handler, PHP-FPM, OPcache, and Redis to work was a process, but the good thing is we’ve put together this guide to make your next upgrade easier.

Important: This guide applies to the AWS Lightsail Debian OS blueprint with Apache installed. It does not apply to Bitnami installations.

Why Upgrade to PHP 8.4.27 and Beyond?

On October 21, 2026, PHP released critical security patches addressing two vulnerabilities that could allow unauthenticated remote code execution. The NSA also issued an urgent advisory urging organizations to update their PHP installations.

PHP 8.4.27 contains these security fixes. While PHP 8.5.12 is the newest stable release overall, this guide focuses on upgrading from PHP 8.2 to the patched PHP 8.4 branch.

Before You Start

Take an AWS Lightsail snapshot, back up your WordPress database, and test on a staging server when possible. Confirm your plugins and theme support PHP 8.4. Additionally, you’ll need SSH access, sudo privileges, and WP-CLI installed.

First, check your PHP server configuration and confirm that you have 8.2, 8.3, or 8.4:

php -v

Step 1: Install PHP 8.4, Imagick, and Redis

Start by spinning up a Lightsail Blueprint and updating its packages:

sudo apt update

Next, install Ondřej Surý’s PHP repository using its current signing-key instructions:

sudo apt install -y lsb-release ca-certificates curl apt-transport-https software-properties-common
sudo curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
sudo apt update

Now install PHP-FPM, required WordPress extensions, Imagick, and Redis:

sudo apt install -y php8.4 php8.4-fpm php8.4-common php8.4-mysql php8.4-xml php8.4-mbstring php8.4-curl php8.4-gd php8.4-zip php8.4-intl php8.4-bcmath php8.4-opcache php8.4-imagick php8.4-redis redis-server

Check the installed version with php8.4 -v. Confirm it reports 8.4.27 or the version you’re upgrading to.

Step 2: Configure PHP-FPM and OPcache

On a 4 GB Lightsail instance, PHP worker settings need attention. A memory limit of 768 MB combined with 16 simultaneous workers could exhaust the server’s RAM.

Start with a conservative three-worker configuration and increase it after checking actual memory usage.

sudo bash -c  '
# 1. Update PHP-FPM Pool Settings
TARGET_FPM="/etc/php/8.4/fpm/pool.d/www.conf"
sed -i "s/^pm = .*/pm = dynamic/" "$TARGET_FPM"
sed -i "s/^pm.max_children = .*/pm.max_children = 16/" "$TARGET_FPM"
sed -i "s/^pm.start_servers = .*/pm.start_servers = 4/" "$TARGET_FPM"
sed -i "s/^pm.min_spare_servers = .*/pm.min_spare_servers = 3/" "$TARGET_FPM"
sed -i "s/^pm.max_spare_servers = .*/pm.max_spare_servers = 6/" "$TARGET_FPM"
sed -i "s/^pm.max_requests = .*/pm.max_requests = 500/" "$TARGET_FPM"

# 2. Update PHP Core Settings 
TARGET_INI="/etc/php/8.4/fpm/php.ini"
sed -i "s/^memory_limit = .*/memory_limit = 768M/" "$TARGET_INI"
sed -i "s/^upload_max_filesize = .*/upload_max_filesize = 80M/" "$TARGET_INI"
sed -i "s/^post_max_size = .*/post_max_size = 80M/" "$TARGET_INI"
sed -i "s/^max_execution_time = .*/max_execution_time = 300/" "$TARGET_INI"

# 3. Optimize OPcache in conf.d
cat << "EOF" > /etc/php/8.4/fpm/conf.d/10-opcache.ini
zend_extension=opcache.so
opcache.enable = 1
opcache.memory_consumption = 256
opcache.interned_strings_buffer = 32
opcache.max_accelerated_files = 20000
opcache.revalidate_freq = 60
opcache.save_comments = 1
EOF
'

For your own server, optimize the pool, memory, and upload limits to match your site’s needs.

Step 3: Switch Apache to PHP 8.4-FPM

Once PHP is installed and configured, disable the old PHP 8.2 Apache handler and enable PHP 8.4-FPM.

sudo a2dismod php8.2
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.4-fpm
sudo update-alternatives --set php /usr/bin/php8.4
sudo systemctl restart apache2
sudo systemctl restart php8.4-fpm
sudo systemctl restart redis-server

If your Apache virtual host explicitly references the PHP 8.2 socket, update that configuration as well. Otherwise, Apache may continue pointing to the old PHP handler.

Step 4: Enable Redis Object Caching in WordPress

Redis can reduce repeated database queries by keeping frequently requested WordPress data in memory. We cover the broader benefits in our guide to website caching.

Install and Start Redis:

cd /var/www/html
wp plugin install redis-cache --activate --allow-root
wp redis enable --allow-root

Step 5: Verify PHP, Apache, and Redis

Before removing PHP 8.2, confirm everything is working and that you’re seeing the latest release of PHP:

php -v
wp-redis status

In WordPress, you can also navigate to Tools > Site Health > Info > Server to confirm the PHP version serving your website. 

Next, test your website’s frontend, contact forms, uploads, plugins, and admin dashboard. Once everything is stable and your rollback window has passed, remove the old packages:

sudo apt purge php8.2* libapache2-mod-php8.2 -y
sudo apt autoremove -y

How Far Back Can You Upgrade PHP?

There isn’t a universal limit on how many PHP versions you can jump. The main limitations are your Debian version, WordPress installation, plugins, themes, and custom code.

Moving from PHP 8.2 to 8.4 means accounting for changes introduced in both PHP 8.3 and 8.4. Prior to larger migrations, it’s not a bad idea to review the official PHP migration guides and WordPress compatibility documentation.

For older installations, keep these points in mind:

  • PHP 8.2: Security support ends December 31, 2026. PHP 8.2.35 contains the October security fixes if an immediate branch upgrade isn’t possible.
  • PHP 8.1 and earlier: These versions no longer receive standard PHP project security updates. Upgrading may require changes to applications, plugins, and extensions.
  • Bitnami installations: These use different PHP and Apache configuration paths. Our Lightsail Bitnami caching guide covers that environment separately.

Keep Your Lightsail Server Updated

PHP updates are part of maintaining a secure WordPress website. The bigger challenge is making sure Apache, PHP-FPM, Redis, and your WordPress application continue working together afterward.

If you need help managing your hosting environment, Uplancer’s cloud solution services can help with infrastructure, server configuration, and ongoing maintenance. Contact us today for a free consultation.

More Common Sense Articles

Enjoying this article? Check out some more topics from our blog on digital common sense.