Question

Cannot Upgrade PHP without Impacting Droplet (WordPress) Installation

Hello,

I am struggling to update my PHP version on my DigitalOcean droplet. It is currently on 7.0.33 and I would like to update it to PHP 7.4+. The ondrej php upgrade method does not work for me so I tried using the sergey-dryabzhinsky repo. Upon getting the php to successfully upgrade to 7.4, my website loads only a Apache screen and no longer links to the web page.

How can I upgrade my PHP from 7.0.33 to 7.4+ without affecting the WordPress installation? I know there must be a way to do this without impacting any directories or configs. Please advise.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
April 29, 2024

Heya @28aa9846729a44cf9f819481fa1755,

Can you tell us why using the ondrej:php repo does not work? Here is the usual way to upgrade PHP version with Apache.

Step 1: Backup Your Data

Before making any significant changes to your server, it’s essential to back up your data. You can use the snapshot function:

https://docs.digitalocean.com/products/images/snapshots/

It doesn’t matter that you have tried some stuff, just make sure you back up now before you proceeed

Step 2: Update Your System

Log in to your server via SSH and run the following commands to update your package lists and upgrade existing packages:

sudo apt update
sudo apt upgrade

Step 3: Add PHP 7.4 Repository

You need to add a repository that contains PHP 7.4 packages. The Ondřej Surý PPA is widely used for PHP installations on Ubuntu:

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

Step 4: Install PHP 7.4

Once the repository is added, you can install PHP 7.4:

sudo apt install php7.4

Install PHP 7.4 modules that you might need. Commonly used modules include:

sudo apt install php7.4-cli php7.4-fpm php7.4-json php7.4-common php7.4-mysql php7.4-zip php7.4-gd php7.4-mbstring php7.4-curl php7.4-xml php7.4-bcmath php7.4-json

Step 5: Disable the Old PHP Version

Disable the old PHP 7.0 version to avoid conflicts:

sudo a2dismod php7.0

Step 6: Enable PHP 7.4

Enable PHP 7.4 to make it the default version:

sudo a2enmod php7.4
sudo systemctl restart apache2

That is it, it’s a straightforward process.

Can you let me know what errors you hit if you follow it?

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.