**Important Note:* As of early 2025, PHP 8.5 is in the development/beta phase (with the stable release expected in late 2025). The ondrej/php PPA provides these pre-release builds. It is highly recommended to use PHP 8.5 for testing and development environments rather than production until the official stable release.*
Step 1: Update Your System
Before installing any new software, it is best practice to update your system's package list and upgrade existing packages.
sudo apt update && sudo apt upgrade -y
Step 2: Add the Ondřej Surý PPA
The default Ubuntu 24.04 repositories only include PHP 8.3. To install PHP 8.5, you need to add the widely trusted ondrej/php Personal Package Archive (PPA).
First, install the prerequisite package for managing PPAs:
sudo apt install software-properties-common -y
Next, add the PHP PPA:
sudo add-apt-repository ppa:ondrej/php -y
Update the package list again to include the new PPA:
sudo apt update
Step 3: Install PHP 8.5
Now you can install the core PHP 8.5 package.
sudo apt install php8.5 -y
Step 4: Install Common PHP 8.5 Extensions
Most modern applications (like Laravel, WordPress, or Symfony) require specific PHP extensions. You can install the most commonly used extensions in a single command:
sudo apt install php8.5-cli php8.5-fpm php8.5-mysql php8.5-curl php8.5-gd php8.5-mbstring php8.5-xml php8.5-zip php8.5-bcmath php8.5-intl -y
(Note: If your application requires other specific extensions like php8.5-redis or php8.5-sqlite3, you can add them to this command).
Step 5: Verify the Installation
Check if PHP 8.5 was installed successfully and view its version. Because you might have other PHP versions installed, it is best to specify the version:
php8.5 -v
You should see output indicating PHP 8.5.x is running.
Step 6: Configure Your Web Server (Optional)
Depending on which web server you are using, you need to configure it to work with PHP 8.5.
For Apache:
If you are using Apache, you need to install the Apache PHP module and restart the service.
sudo apt install libapache2-mod-php8.5 -y
sudo systemctl restart apache2
For Nginx:
Nginx uses PHP-FPM (FastCGI Process Manager). Start and enable the PHP 8.5 FPM service:
sudo systemctl start php8.5-fpm
sudo systemctl enable php8.5-fpm
Next, update your Nginx server block configuration (usually located in /etc/nginx/sites-available/your_domain) to pass PHP requests to the PHP 8.5 FPM socket. Ensure the location ~ \.php$ block looks like this:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# Pass PHP requests to the PHP 8.5 FPM socket
fastcgi_pass unix:/var/run/php/php8.5-fpm.sock;
}
Restart Nginx to apply the changes:
sudo systemctl restart nginx
Step 7: Set PHP 8.5 as the Default CLI Version (Optional)
If you have multiple versions of PHP installed and want PHP 8.5 to be the default when you type php in the terminal, use the update-alternatives command:
sudo update-alternatives --set php /usr/bin/php8.5
You can verify the default CLI version by running:
php -v
Step 8: Test PHP Processing
To ensure your web server is correctly processing PHP files, create a test file in your web root directory.
sudo nano /var/www/html/info.php
Add the following PHP code to the file:
<?php
phpinfo();
?>
Save and close the file. Now, open your web browser and navigate to:
http://your_server_ip/info.php
You should see a detailed page showing your PHP 8.5 configuration. (Security Tip: Remember to delete this info.php file after testing, as it exposes sensitive server information).
sudo rm /var/www/html/info.php
Congratulations! You have successfully installed and configured PHP 8.5 on Ubuntu 24.04.
Top comments (0)