How do I upgrade my PHP version?
I cannot find anywhere how to do this. Wordpress is telling me an upgrade is required but they tell me to go my hosting company to upgrade PHP. Linode tells me PHP is not part of the services they provide. Any help is much appreciated.
I think I located your account and I took note of your distribution version, so I’ll form my advice around this information. I’m not sure which version of PHP you’re currently running, but the below instructions detail how to upgrade to PHP 7.4 or 8.0.
Before getting started, there’s some risk to consider when upgrading to a PHP version that isn’t native to your distribution version - you can read more details surrounding this in this Community post.
Retrofitting this newer version with your distribution requires you to download a PHP repository, which is covered in these steps.
1) Update server:
sudo apt-get update && apt-get upgrade
sudo apt -y install software-properties-common
3) Add PHP repository
sudo add-apt-repository ppa:ondrej/php
4) Update repository index
sudo apt-get update
5) Install php7.4
sudo apt-get install php7.4
6) Install php extensions (run
dpkg -l php7.4* for list) - these are some common ones:
sudo apt install php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring php7.4-opcache php7.4-soap php7.4-zip php7.4-intl -y
Since you’ll now have multiple PHP versions on your server, you’ll want to set this as the default:
update-alternatives --set php /usr/bin/php7.4
If you wanted to install PHP 8.0 instead of 7.4, you could do the following:
sudo apt-get update && apt-get upgrade sudo apt -y install software-properties-common sudo add-apt-repository ppa:ondrej/php apt-get install php7.4 apt-get install libapache2-mod-php7.4 php7.4-fpm libapache2-mod-fcgid php7.4-curl php7.4-dev php7.4-gd php7.4-mbstring php7.4-zip php7.4-mysql php7.4-xml update-alternatives --set php /usr/bin/php8.0
Thank you so much for the help here. If I add on the C-panel will upgrading my PHP be easier through a dashboard of sorts? Or would I still need to run code manually?
@foxkeeper Since it sounds like you already have an existing server, it is mostly easier to follow the instructions @jtoscani laid out. This is because installing cPanel on an existing server will erase the current contents. It is possible to deploy a new server using our cPanel Marketplace App. Then you'd need to transfer your website files over to it. You may find the below links helpful with migrating your data to a new server.
Hi, I have the same issue. The instructions worked great. Thanks. However, my Wordpress site is still giving me a hard time:
PHP is the programming language used to build and maintain WordPress. Newer versions of PHP are created with increased performance in mind, so you may see a positive effect on your site’s performance. The minimum recommended version of PHP is 7.4.
Any idea what the problem might be?
Should have checked …
I just wanted to add a quick note to this. If you are going to be updating PHP in a Debian system, all the instructions above will work except for the command for adding the PHP repo (which is intended for Ubuntu). As per the repo instructions, the commands you want to use for Debian are:
curl -sSL https://packages.sury.org/php/README.txt | sudo bash -x sudo apt update
Hi, everyone! I followed your instructions and in my terminal everything seems to work just fine, when I check the php version is indeed 7.4. However, when I check my Wordpress it says that I have the old version. Does anyone has any idea why is that? Thanks a lot!
Solved: I followed this answer: https://www.linode.com/community/questions/18801/my-website-says-i-need-to-upgrade-php-but-php-v-shows-the-current-version-why
E: Unable to locate package php7.4
I tried both the ubuntu and debian instructions. They both give this error.
It would be nice if the instructions included potential trouble spots and didn't leave us hanging when they yield an error instead of the promised php upgrade.
PHP 7.4 will go EOL on Nov 28, 2022. That's prob why neither Ubuntu nor Debian distros have it (hence, your error). Linode cannot control what the distro vendors do or do not publish…
PHP 7.4 will go EOL on Nov 28, 2022
Does this mean that Ubuntu 20.04 will see a PHP 8.x package in their repository? If so, since I've been using the ppa:ondrej/php repository should I delete it and get updates from Ubuntu once they add it?
Or will 20.22 remain with 7.x. How do EOL packages work in Ubuntu distributions?
Does this mean that Ubuntu 20.04 will see a PHP 8.x package in their repository?
Since 20.04 is not a "current" release, I would say no. Canonical rarely (if ever) back ports that far back. A 22.xx package may be back ported to 22.04 but probably not any farther back than that (and probably only if some paying customer has complained about the availability of fixes for known bugs ). 22.04 is the current LTS release.
If you want 8.0 as a release package (as opposed to a PPA), you'll have to upgrade to 22.04. If you want 8.1 on 22.04, you'll have to use a PPA.
This post was linked to in another Community Questions post: How do I update my Linode's PHP version? | Linode Questions
I wanted to cross post my response on that post here. Specifically, it's regarding upgrading PHP on a Debian machine. The tl;dr is you'll want to use the PPA to get the new PHP. Here are the links I provided in my other update: