How do I upgrade my CentOS 7 Linode to PHP7?

Linode Staff

I am running CentOS 7. How do I upgrade my Linode to PHP 7?

1 Reply

Caution
Changes to a single component of your software stack can have subtle side effects and break dependencies.

When changing software versions of a production server you should have a known working backup of your configuration. (If you have not tested your backup, you cannot be sure that you have one.)

Assumptions
The Linode provided CentOS 7 image does not install PHP by default, but running yum install php will install:

php --version
PHP 5.4.16 (cli) (built: Nov  1 2019 16:04:20)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

We will assume you are upgrading from version 5.4 for this reason.

Centos Recommended PHP Upgrade
From the Centos Wiki, to use PHP 7 according to their recommendations, you will want to look at the following page: https://wiki.centos.org/HowTos/php7

Remi's Repository
There is also a commonly used Third-Party repository called Remi's Repo that is tailored around providing the latest versions of the PHP stack. Here is what the CentOS wiki says about this:

Remi Repository - (See http://rpms.remirepo.net/) Remi Collet maintains a large collection of RPMS, including latest versions of PHP etc. He's also got an FAQ at http://blog.remirepo.net/pages/English-FAQ . Note that this is a collection of repos, and using the -safe series will ensure that nothing from the base CentOS Linux distro is overwritten or replaced. However, be aware that this repo does not play nicely with other third party repos - for example, Remi's packages contain Obsoletes: lines for packages from both IUS and Webtatic repos and thus will automatically replace them with the .remi version. This may not be the desired behaviour and you should be careful with enabling this repo for that reason.

To use Remi's Repo, you will likely want to use the Configuration Wizard at https://rpms.remirepo.net/wizard/ to select which specific version of PHP 7 you would like and whether or not you will be using multiple versions of PHP simultaneously.

As an example, to upgrade to PHP 7.4.4 from PHP 5.4 and only use the new version, the wizard provides these instructions:

CentOS 7 provides PHP version 5.4 in its official repository

Command to install the EPEL repository configuration package:
    yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Command to install the Remi repository configuration package:
    yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm

Command to install the yum-utils package (for the yum-config-manager command):
    yum install yum-utils

You want a single version which means replacing base packages from the distribution

Packages have the same name than the base repository, ie php-*

Some common dependencies are available in remi-safe repository, which is enabled by default

PHP version 7.4 packages are available for CentOS 7 in remi-php74 repository

Command to enable the repository:
    yum-config-manager --enable remi-php74

If the priorities plugin is enabled, ensure remi-php74 have higher priority (a lower value) than base and updates

Command to upgrade (the repository only provides PHP):
    yum update

Command to install additional packages:
    yum install php-xxx

Command to install testing packages:
    yum --enablerepo=remi-php74-test install php-xxx

Command to check the installed version and available extensions:
    php --version
    php --modules

I hope this helps.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct