← Volver al blog

How to Upgrade PHP Version in Ubuntu

  • Xernode
  • 1 min de lectura
  • 1 de abril de 2026
Ubuntu php ubuntu server upgrade update

Introduction

Upgrading your PHP version in Ubuntu is essential for security, performance, and compatibility with modern applications like WordPress. This guide shows you how to safely upgrade PHP on your server.

Step-by-step Guide

  1. Check your current PHP version
    • php -v
  2. Add the PHP repository (if needed)
    • sudo apt update
    • sudo apt install software-properties-common
    • sudo add-apt-repository ppa:ondrej/php
    • sudo apt update
  3. Install the desired PHP version (e.g., PHP 8.2)
    • sudo apt install php8.2 php8.2-cli php8.2-fpm php8.2-mysql php8.2-xml php8.2-curl php8.2-gd php8.2-mbstring
  4. Switch the default PHP version (CLI)
    • sudo update-alternatives --set php /usr/bin/php8.2
  5. Restart your web server
    • For Apache:n
      • sudo systemctl restart apache2
    • For Nginx (with PHP-FPM):n
      • sudo systemctl restart php8.2-fpm
      • sudo systemctl restart nginx
  6. Verify the new PHP version
  7. (Optional) Remove old PHP versions
    • sudo apt remove php7.4 php7.4-cli php7.4-fpm
    • sudo apt autoremove

Recommendations

  • Always back up your site and database before upgrading PHP.
  • Test your applications after the upgrade to ensure compatibility.
  • Keep your PHP version updated for security and performance.

Call To Action

eed a fast and secure Ubuntu VPS? Check out our hosting plans! https://xernode.com/#pricing

Related Guides

How to Set Up Automatic Backups in Linux

How to Install WordPress on a VPS