PHP powers millions of websites and web applications, including WordPress, Laravel, Magento, and many custom platforms. This guide explains how to install PHP 8.4 on an Ubuntu 24.04 VPS using the official Ondřej Surý repository to receive the latest stable packages and updates.
Requirements
- Ubuntu 24.04 VPS
- SSH access with root or sudo privileges
- Internet connection
Step 1 — Update Your System
sudo apt update
sudo apt upgrade -y
Step 2 — Install Required Packages
sudo apt install software-properties-common ca-certificates lsb-release apt-transport-https -y
Step 3 — Add the PHP Repository
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
Step 4 — Install PHP 8.4
sudo apt install php8.4 -y
Step 5 — Install Common PHP Extensions
sudo apt install php8.4-cli php8.4-fpm php8.4-common php8.4-mysql php8.4-curl php8.4-gd php8.4-mbstring php8.4-xml php8.4-zip php8.4-bcmath php8.4-intl php8.4-soap php8.4-opcache -y
Step 6 — Verify Installation
php -v
Example output:
PHP 8.4.x (cli)
Step 7 — Check PHP-FPM Status
sudo systemctl status php8.4-fpm
If it is not running:
sudo systemctl enable php8.4-fpm
sudo systemctl start php8.4-fpm
Step 8 — Test PHP
Create a PHP information file:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
Open your browser:
http://YOUR_SERVER_IP/info.php
If the PHP information page appears, PHP has been installed successfully.
Useful PHP Commands
php -v
php -m
php --ini
php -i
Security Tip
After testing, remove the info.php file because it exposes server configuration details.
sudo rm /var/www/html/info.php
Best Practices
- Keep PHP updated with security patches.
- Install only the extensions your applications require.
- Use PHP-FPM with Nginx for better performance.
- Enable OPcache to improve application speed.
- Regularly monitor PHP logs for errors.
Conclusion
PHP 8.4 delivers improved performance, better security, and compatibility with modern web applications. Combined with Nginx and MySQL, it provides a fast and reliable environment for hosting websites and APIs on your VPS.
Related Articles
- How to Install Nginx on Ubuntu 24.04 VPS
- How to Install MySQL on Ubuntu VPS
- How to Secure Your Linux VPS
- How to Install Docker on Ubuntu 24.04 VPS
- How to Connect to Your VPS via SSH
