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

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

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

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel