Close [x]

PHP 5.5, 5.6, or 7.0—CentOS

Edit this page on GitHub

Updated: 25 May 2016 (PDT)

Contents

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

PHP versions supported

Magento requires:

  • 7.0.2–7.0.6 except for 7.0.5 (supported by Magento version 2.0.1 and later only) There is a known PHP issue that affects our code compiler when using PHP 7.0.5. We recommend you not use PHP 7.0.5; instead, use PHP 7.0.2–7.0.4 or 7.0.6.
  • PHP 5.6.x
  • PHP 5.5.x, where x is 22 or greater

Magento no longer supports PHP 5.4.

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, messages similar to the following display:

PHP 5.6.4 (cli) (built: Dec 20 2014 17:30:46)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, 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.

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 5.5, 5.6, or 7.0 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.

Continue with one of the following sections:

PHP 7 on CentOS

There is more than one way to install PHP 7.0.2 or later; the following is a suggestion only. Consult a reference for additional options.

To upgrade to PHP 7.0.2 or later:

  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. Enter the following command:

    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
    

    The bcmath extension is required for Magento Enterprise Edition (EE) only.

  4. Restart Apache: service httpd restart

  5. Enter the following command to verify that PHP 5.6 is installed:

    php -v
    

    The following response indicates that PHP 5.6 is installed properly:

    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. Set up PHP configuration options.

PHP 5.6 on CentOS

There is more than one way to upgrade CentOS 6.5 to PHP 5.6; the following is a suggestion only. Consult a reference for additional options.

To upgrade to PHP 5.6:

  1. 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
    yum -y install php56u php56u-opcache php56u-xml php56u-mcrypt php56u-gd php56u-devel php56u-mysql php56u-intl php56u-mbstring php56u-bcmath
    

    The bcmath extension is required for Magento Enterprise Edition (EE) only.

  2. Restart Apache: service httpd restart

  3. Enter the following command to verify that PHP 5.6 is installed:

    php -v
    

    The following response indicates that PHP 5.6 is installed properly:

    PHP 5.6.18 (cli) (built: Feb  4 2016 09:29:52)
    Copyright (c) 1997-2016 The PHP Group
    Zend Engine v2.6.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.

  4. Set up PHP configuration options.

PHP 5.5 on CentOS

There is more than one way to upgrade CentOS 6.5 to PHP 5.5; the following is a suggestion only. Consult a reference for additional options.

To upgrade to PHP 5.5:

  1. 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
    yum -y install php55u php55u-opcache php55u-xml php55u-mcrypt php55u-gd php55u-devel php55u-mysql php55u-intl php55u-mbstring php55u-bcmath
    

    The bcmath extension is required for Magento Enterprise Edition (EE) only.

  2. Enter the following command to verify the version:

    php -v
    

    The following messages display:

    PHP 5.5.32 (cli) (built: Feb  4 2016 09:30:35)
    Copyright (c) 1997-2015 The PHP Group
    Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
    
  3. Restart Apache: service httpd restart
  4. Continue with the next section.

Set PHP configuration options

This section discusses how to:

  • Set the system time zone for PHP; otherwise, errors like the following display during the installation and time-related operations like cron might not work:
    PHP Warning:  date(): It is not safe to rely on the system's timezone settings. [more messages follow]
  • Increase the PHP memory limit to at least 768MB for normal operation or 2GB for testing.
  • Set always_populate_raw_post_data = -1
    always_populate_raw_post_data is deprecated in PHP 5.6. This setting causes PHP to always populate $HTTP_RAW_POST_DATA with raw POST data. Failure to set this properly in PHP 5.6 results in errors when connecting to the database.
  • Disable asp_tags. If asp_tags are enabled, errors display when accessing PHTML templates.
    asp_tags will be removed in PHP 7.

To set PHP options:

  1. Locate php.ini by entering the following command:
    php -i | grep "Loaded Configuration File"
    Typical locations follow:

    Ubuntu: /etc/php5/cli/php.ini
    CentOS: /etc/php.ini
  2. Open php.ini in a text editor.
  3. Locate your server's time zone in the available time zone settings.
  4. Locate the following setting and uncomment it if necessary:
    date.timezone =
  5. Add the time zone setting you found in step 1.
  6. Change memory_limit to:

    memory_limit = 1GB or more for normal operation
    memory_limit = 2G or more for testing
  7. Required for PHP 5.6, recommended for PHP 5.5. Locate always_populate_raw_post_data, uncomment it if necessary, and set it as follows:
    always_populate_raw_post_data = -1
  8. Locate the following setting:
    asp_tags =
  9. Make sure its value is set to Off
  10. Save your changes and exit the text editor.
  11. Restart Apache:

    Ubuntu: service apache2 restart
    CentOS: service httpd restart