PHP 7.0 or 7.1—CentOS

If you must install both Apache and PHP, install Apache first.

PHP versions supported

7.0.0, 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.0.6–7.0.x 7.1.x
Not supported Supported Not supported Supported Not supported Supported (2.1.2 and later) Supported (2.1.2 and later)

Help if you’re just starting out

If you’re new to all this and need some help getting started, we suggest the following:

Verify PHP is installed

To verify if PHP is installed already, enter php -v. If PHP is installed, a message similar to the following displays:

PHP 7.0.20 (cli) (built: Jun  8 2017 09:31:38) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
  with Zend OPcache v7.0.20, Copyright (c) 1999-2017, by Zend Technologies

The preceding message confirms that the Zend OPcache is installed. We strongly recommend using the OPcache for performance reasons. If your PHP distribution does not come with the OPcache, see the PHP OPcache documentation.

If PHP is installed, continue with the next prerequisite, MySQL.

If PHP is not installed, see one of the following sections:

CentOS repositories

Linux systems provide software like PHP in one or more repositories. CentOS, unlike Ubuntu, has a set of officially recommended repositories. Other repositories are considered less safe for the reasons stated on the CentOS wiki.

We’re not aware that you can install PHP 7.0 or 7.1 from a CentOS-recommended repository. Therefore, you must consider the following:

  • If you’re setting up a system that will be deployed in production, you should choose a hosting provider who uses repositories considered to be safe and reliable.

    You should also consider upgrading to a later version of CentOS that has the desired PHP version in a recommended repository.

  • If you’re setting up a development system, you can use any repository you wish.

In this topic, we show how to install PHP using the Inline with Upstream Stable (IUS) repository, which is not on the CentOS recommended list. However, packages installed from IUS do not use the same names as CentOS-provided packages, so no existing system packages are replaced.

Before you continue, review their Getting Started topic.

Magento does not officially recommend using the IUS repository. We discuss it here for example purposes only.

PHP 7.0 on CentOS

There is more than one way to install PHP 7.0 on CentOS; the following is a suggestion only. Consult a reference for additional options.

To install PHP 7.0 on CentOS 6 or 7:
  1. CentOS 6. Enter the following commands in the order shown:

    yum -y update
    yum -y install epel-release
    wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
    wget https://centos6.iuscommunity.org/ius-release.rpm
    rpm -Uvh ius-release*.rpm
    yum -y update
    
  2. CentOS 7. Enter the following commands:

    yum install -y http://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/ius-release-1.0-14.ius.centos7.noarch.rpm
    yum -y update
    
  3. Install all required PHP extensions:

    yum -y install php70u php70u-pdo php70u-mysqlnd php70u-opcache php70u-xml php70u-mcrypt php70u-gd php70u-devel php70u-mysql php70u-intl php70u-mbstring php70u-bcmath php70u-json php70u-iconv php70u-soap
    

    The bcmath extension is required for Magento Commerce only.

  4. Restart Apache: service httpd restart

  5. Verify that PHP 7.0 is installed properly:

    php -v
    

    The following response indicates that PHP 7.0.3 is installed:

    PHP 7.0.3 (cli) (built: Feb  4 2016 08:51:10) ( NTS )
    Copyright (c) 1997-2016 The PHP Group
    Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
    

    The preceding message confirms that the Zend OPcache is installed. We strongly recommend using the OPcache for performance reasons. If your PHP distribution does not come with the OPcache, see the PHP OPcache documentation.

  6. Verify that all required PHP extensions were installed:

    php -me
    

    You should see output similar to the following:

    [PHP Modules]
    bcmath
    calendar
    Core
    ctype
    curl
    date
    dom
    exif
    fileinfo
    filter
    ftp
    gd
    gettext
    hash
    iconv
    intl
    json
    libxml
    mbstring
    mcrypt
    mysqli
    mysqlnd
    openssl
    pcntl
    pcre
    PDO
    pdo_mysql
    Phar
    readline
    Reflection
    session
    SimpleXML
    soap
    sockets
    SPL
    standard
    tokenizer
    wddx
    xml
    xmlreader
    xmlwriter
    xsl
    Zend OPcache
    zip
    zlib
    
    [Zend Modules]
    Zend OPcache
    
  7. Continue with Required PHP settings.

PHP 7.1 on CentOS

There is more than one way to install PHP 7.1 on CentOS; the following is a suggestion only. Consult a reference for additional options.

To install PHP 7.1 on CentOS 6 or 7:
  1. CentOS 6. Enter the following commands in the order shown:

    yum -y update
    yum -y install epel-release
    wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
    wget https://centos6.iuscommunity.org/ius-release.rpm
    rpm -Uvh ius-release*.rpm
    yum -y update
    
  2. CentOS 7. Enter the following commands:

    yum install -y http://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/ius-release-1.0-14.ius.centos7.noarch.rpm
    yum -y update
    
  3. Install all required PHP extensions:

    yum -y install php71u php71u-pdo php71u-mysqlnd php71u-opcache php71u-xml php71u-mcrypt php71u-gd php71u-devel php71u-mysql php71u-intl php71u-mbstring php71u-bcmath php71u-json php71u-iconv php71u-soap
    

    The bcmath extension is required for Magento Commerce only.

  4. Restart Apache: service httpd restart

  5. Verify that PHP 7.1 is installed properly:

    php -v
    

    The following response indicates that PHP 7.1.6 is installed:

    PHP 7.1.6 (cli) (built: Jan  9 2017 09:23:16) ( NTS )
    Copyright (c) 1997-2017 The PHP Group
    Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.1.6, Copyright (c) 1999-2017, by Zend Technologies
    

    The preceding message confirms that the Zend OPcache is installed. We strongly recommend using the OPcache for performance reasons. If your PHP distribution does not come with the OPcache, see the PHP OPcache documentation.

  6. Verify that all required PHP extensions were installed:

    php -me
    

    You should see output similar to the following:

    [PHP Modules]
    bcmath
    calendar
    Core
    ctype
    curl
    date
    dom
    exif
    fileinfo
    filter
    ftp
    gd
    gettext
    hash
    iconv
    intl
    json
    libxml
    mbstring
    mcrypt
    mysqli
    mysqlnd
    openssl
    pcntl
    pcre
    PDO
    pdo_mysql
    Phar
    readline
    Reflection
    session
    SimpleXML
    soap
    sockets
    SPL
    standard
    tokenizer
    wddx
    xml
    xmlreader
    xmlwriter
    xsl
    Zend OPcache
    zip
    zlib
    
    [Zend Modules]
    Zend OPcache
    
  7. Continue with Required PHP settings.

Next

Required PHP settings