Close [x]

PHP 5.5, 5.6, or 7.0—Ubuntu

Edit this page on GitHub

Updated: 25 June 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-1+deb.sury.org~precise+1 (cli) (built: Dec 21 2014 19:26:25)
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.

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

PHP 7.0 on Ubuntu 14

To install PHP 7 on Ubuntu 14:

  1. Enter the following commands in the order shown:

    sudo apt-get -y update
    sudo add-apt-repository ppa:ondrej/php
    sudo apt-get -y update
    sudo apt-get install -y php7.0 libapache2-mod-php7.0 php7.0 php7.0-common php7.0-gd php7.0-mysql php7.0-mcrypt php7.0-curl php7.0-intl php7.0-xsl php7.0-mbstring php7.0-zip php7.0-bcmath php7.0-iconv
    

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

  2. Enter the following command to verify PHP 7.0.2 installed properly:

    php -v
    

    Following is a sample response that indicates PHP 7.0.2 is installed:

    PHP 7.0.8-2+deb.sury.org~trusty+1 (cli) ( NTS )
    Copyright (c) 1997-2016 The PHP Group
    Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
      with Zend OPcache v7.0.8-2+deb.sury.org~trusty+1, 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.

  3. Set PHP configuration options.

PHP 5.6 on Ubuntu 14

To install PHP 5.6 or to upgrade from PHP 5.5 on Ubuntu 14:

  1. Enter the following commands in the order shown:

    apt-get -y update
    add-apt-repository ppa:ondrej/php
    apt-get -y update
    apt-get -y install php5.6 php5.6-mcrypt php5.6-mbstring php5.6-curl php5.6-cli php5.6-mysql php5.6-gd php5.6-intl php5.6-xsl
    
  2. Enter the following command to verify PHP 5.6 installed properly:

    php -v
    

    Following is a sample response that indicates PHP 5.6 is installed:

    PHP 5.6.22-4+deb.sury.org~trusty+1 (cli)
    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.

  3. Set PHP configuration options.

PHP 5.5 on Ubuntu 14

To install PHP 5.5 on Ubuntu 14:

  1. Enter the following command:

    apt-get -y update
    apt-get -y install php5.6 php5.6-mcrypt php5.6-mbstring php5.6-curl php5.6-cli php5.6-mysql php5.6-gd php5.6-intl php5.6-xsl
    
  2. Verify the PHP version by entering php -v. Messages similar to the following should display:

    PHP 5.5.9-1ubuntu4.4 (cli) (built: Sep  4 2014 06:56:34)
    Copyright (c) 1997-2014 The PHP Group
    Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.3, 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.

  3. Set PHP configuration options.

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]
    
  • Set always_populate_raw_post_data = -1

    always_populate_raw_post_data is deprecated in PHP 5.6 and is dropped in PHP 7.0.x. This setting causes PHP to always populate $HTTP_RAW_POST_DAT with raw POST data. Failure to set this properly in PHP 5.5 or 5.6 results in errors when connecting to the database.

  • Set the PHP memory limit.

    Our detailed recommendations are:

    • Compiling code, 768M
    • Deploying static asses, 768M
    • Installing and updating Magento components from Magento Marketplace, 1G
    • Testing, 2G
  • 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 --ini
    

    Use the value of 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 the preceding step.
  6. Change the value of memory_limit to one of the values at the beginning of this section.

    For example,

    memory_limit=768M
    
  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 your web server:

    • Ubuntu: service apache2 restart
    • CentOS: service httpd restart
    • Ubuntu and CentOS: service nginx restart