Close [x]

PHP 5.5 or 5.6—Ubuntu

Edit this page on GitHub

Contents

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

PHP versions supported

Magento requires:

  • PHP 5.6.x
  • PHP 5.5.x

Magento no longer supports PHP 5.4.

Help if you're just starting out

If you鈥檙e 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 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/php5-5.6
    apt-get -y update
    apt-get -y install php5 php5-mhash php5-mcrypt php5-curl php5-cli php5-mysql php5-gd php5-intl php5-xsl php5-bcmath
    

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

  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.4-1+deb.sury.org~trusty+1 (cli) (built: Dec 21 2014 19:28:16)
    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.

  1. Set PHP configuration options.

PHP 5.6 on Ubuntu 12

Before continuing, enter the following command to make sure you鈥檙e running Apache 2.4:

apache2 -v

The result should be similar to the following:

Server version: Apache/2.4.10 (Ubuntu)
Server built:   Jul 22 2014 22:46:25

If you鈥檙e running an earlier Apache version, see Upgrading Apache on Ubuntu 12 first.

Ubuntu 12 comes with PHP 5.3 by default. PHP 5.3 is not supported by Magento and upgrading to it might involve additional tasks not discussed here. For more information, consult a resource like phpave.

To install or upgrade to PHP 5.6 on Ubuntu 12:

  1. Enter the following commands in the order shown:

    apt-get -y update
    add-apt-repository ppa:ondrej/php5-5.6
    apt-get -y update
    apt-get -y install php5 php5-mhash php5-mcrypt php5-curl php5-cli php5-mysql php5-gd php5-intl php5-xsl php5-bcmath
    

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

  2. Verify that PHP 5.6 installed properly:

    php -v
    

    Messages similar to the following should 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.

  3. Set PHP configuration options.

PHP 5.5 on Ubuntu 14 or Ubuntu 12

See one of the following sections for more information:

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 php5-mhash php5-mcrypt php5-curl php5-cli php5-mysql php5-gd php5-intl php5-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.

PHP 5.5 on Ubuntu 12

We can鈥檛 verify this procedure; if you know how to install PHP 5.5 on Ubuntu 12, please click Edit this page on GitHub at the top of this page and let us know.

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 = 768M 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

Optional: Configure caching alternatives

You can optionally specify alternatives to file system caching in php.ini by modifying the value of session.save_handler. Magento supports the following values:

  • files (the default) for file system caching
  • db for database caching
  • redis for Redis caching
  • Any other custom cache type you set up; however, it's up to you to know how to specify it in php.ini