Upgrading to PHP 7 (Personal Home Page) on Linux Cloud Servers

2020-01-02 By Aaron 4051 Views linux php development
3 reviews

PHP (Hypertext Preprocessor) is one of the most commonly used open-source scripting languages. It can be easily incorporated into HTML code and is widely used in the development of websites, CMS applications, etc.

Different versions of PHP are available, with the latest version being more secure and patched against all vulnerabilities of the previous version. It is necessary that PHP in a server is kept up-to-date with the latest version since the newer versions of PHP provide better security, improved performance for websites, and also several features and improvements from the older versions.

Before upgrading the PHP version in the server, it is important that you make sure that all the applications/websites hosted on the server are compatible with the newer version of PHP. It is also important that all the data in the server is backed-up before proceeding with the PHP upgrade.


This guide outlines the basic steps to upgrade PHP v5.6 to PHP v7 on the Linux server.


CentOS


  1. Check the current version of PHP running in the server with either of the below commands.

    # php -v
    (or)
    # php --version
    

    An output similar to below will be displayed, which shows the current PHP version as 5.6.

    Php71

  2. Download the Remi and EPEL repository packages in the server using the below commands.

    # wget -q http://rpms.remirepo.net/enterprise/remi-release-7.rpm
    
    # wget -q https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    
  3. Install both the RPM packages and enable Remi PHP 7 repo.

    # rpm -i remi-release-7.rpm epel-release-latest-7.noarch.rpm
    

    To enable Remi repo for PHP 7, execute either of the below commands depending upon the version of PHP 7 that is required.

    # yum-config-manager --enable remi-php70 (for PHP7.0)
    
    # yum-config-manager --enable remi-php71 (for PHP7.1)
    
    # yum-config-manager --enable remi-php72 (for PHP7.2)
    
  4. Now, upgrade PHP in the server using the below command.

    # yum install php
    

    The existing PHP version will be upgraded to PHP 7, once the execution of the command has been completed.

  5. Check the PHP version once again to confirm that PHP has been upgraded.

    # php -v
    (or)
    # php --version
    

    Php72


Ubuntu


  1. Check the version of PHP currently installed in the server by executing the below command.

    # php -v
    (or)
    # php --version
    

    The output will be as follows:

    Php73

  2. Before upgrading to PHP 7 in the Ubuntu server, a PPA (Personal Package Archive) needs to be added to the system’s APT resources. For this, execute the below command.

    # sudo add-apt-repository ppa:ondrej/php
    

    A description of the PPA will be displayed, along with a prompt to proceed. Press Enter to continue.

  3. Once the PPA has been added, update the local package cache.

    # sudo apt-get update
    
  4. Install PHP 7 by running the below command.

    # sudo apt-get install php7.0
    
  5. Check the PHP version once again to confirm that PHP has been upgraded.

    # php -v
    (or)
    # php --version
    

    Php74


Debian


  1. Check the version of PHP currently installed in the server by executing the below command.

    # php -v
    (or)
    # php --version
    

    Php75

  2. Before upgrading to PHP 7 in the Debian server, a PPA (Personal Package Archive) needs to be added to the system’s APT resources. For this, execute the below commands.

    # apt install apt-transport-https lsb-release ca-certificates
    
    # wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
    
    # sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
    
  3. Once the PPA has been added, update the local package cache.

    # apt-get update
    
  4. Install PHP 7 by running the below command.

    # apt-get install php7.0
    
  5. Check the PHP version once again to confirm that PHP has been upgraded.

    # php -v
    (or)
    # php --version
    

    Php76

What do you think about this article?

Rate this article
Need assistance?

Try this guide to receive free bundled services at signup on a new free account.

Sign Up

Your Feedback Is Important

We hope you’ll give the new products and updates a try. If you have an idea for improving our products or want to vote on other user ideas so they get prioritized, please submit your feedback on our Community platform. And if you have any questions, please feel free to ask in the Community or contact our Technical Support team.