Always_populate_raw_post_data setting in PHP 5.6 & Magento 2.0

Reading Time: 3 Minutes
It's only fair to share...
Share on Facebook1Tweet about this on TwitterShare on LinkedInShare on Google+

Does Magento 2 throw an error about always_populate_raw_post_data being set to 0? And thus having problems installing or updating Magento with PHP 5.6 and PHP 7? Then read on, because here is how to fix upgrades to Magento 2.0 in PHP 5.6 and higher (PHP 7).

Advertisement:

PHP always_populate_raw_post_data ($HTTP_RAW_POST_DATA) & Magento 2.0 #

Magento 2.0 requires PHP’s always_populate_raw_post_data to be disabled, or set to -1 in your php.ini file. Since PHP 5.6, the use of $HTTP_RAW_POST_DATA is deprecated and will be removed in PHP 7.0. However, in PHP 5.6, this setting is commented out, making it equal to 0, not -1.

This causes errors when you try to install, or update to, Magento 2.0 using PHP 5.6 or PHP 7.

The PHP always_populate_raw_post_data setting will let PHP always populate the $HTTP_RAW_POST_DATA containing the raw POST data, if set to true (1). Otherwise, the variable is populated only when the MIME type of the data is unrecognized.

Pro tip: learn how to validate MIME types with PHP Fileinfo!

Magento 2.0 PHP Settings Check #

And this is where Magento goes wrong… Well, in my opinion Magento goes wrong by quitting the installer. The error should only be thrown when both display_errors and display_startup_errors are enabled in your PHP configuration. On my production servers, they’re disabled. Unfortunately, the Magento 2.0 PHP settings check still complains about this and throws the following error message:

Your PHP Version is 5.6.15, but always_populate_raw_post_data = 0. $HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will be removed in PHP 7.0. This will stop the installer from running. Please open your php.ini file and set always_populate_raw_post_data to -1. If you need more help please call your hosting provider.

PHP Settings Check, the quick fix for Magento #

Here is how you can quickly fix Magento’s always_populate_raw_post_data = 0 error with PHP 5.6/7.0:

  • upload a user defined ini-file, or a .user.ini file, to your website’s root folder. It has to contain the following setting:
always_populate_raw_post_data = -1

While going through your PHP config, fix & set correct values for curl.cainfo and openssl.cafile too. Stop turning off CURLOPT_SSL_VERIFYPEER (or sslverify = false for wp_remote_get() in WordPress).

Related:   Prepared statements: SQL Injection tegengaan

This will set the always_populate_raw_post_data value to how it is supposed to be: -1. For your Magento website only. The directive is a PHP_INI_PERDIR and PHP_INI_ALL setting, meaning you can set it anywhere. If you are a server administrator, make the change to your php.ini file; automatically populating $HTTP_RAW_POST_DATA is removed in PHP 7.0.0 and deprecated in PHP 5.6.

If set to TRUE, PHP will always populate the $HTTP_RAW_POST_DATA containing the raw POST data. Otherwise, the variable is populated only when the MIME type of the data is unrecognised.

The preferred method for accessing raw POST data is php://input, and $HTTP_RAW_POST_DATA is deprecated in PHP 5.6.0 onwards. Setting always_populate_raw_post_data to -1 will opt into the new behaviour that will be implemented in a future version of PHP, in which $HTTP_RAW_POST_DATA is never defined.

Regardless of the setting, $HTTP_RAW_POST_DATA is not available with enctype=”multipart/form-data”.

It's only fair to share...
Share on Facebook1Tweet about this on TwitterShare on LinkedInShare on Google+

Advertisement:

14 Replies to “Always_populate_raw_post_data setting in PHP 5.6 & Magento 2.0”

  1. Hi, I’m a newbie trying to install Magento on MAMP. No coding skills, what a shame…so I’ve come across this error;
    PHP Settings Check
    Need Help?
    PHP Documentation
    Your PHP Version is 5.6.10, but always_populate_raw_post_data = 0. $HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will be removed in PHP 7.0. This will stop the installer from running. Please open your php.ini file and set always_populate_raw_post_data to -1. If you need more help please call your hosting provider.

    I understand php.ini must be changed, so I’d like to know what application should be used to do so.
    Any help would be highly appreciated:-)))

    1. Hi Angela, thank you for your reaction.

      If you have access to the web servers’ php.ini file, you can edit it with whatever editor you prefer (Notepad on Windows, vi(m) or emacs on Linux, Brackets, TextWrangler or BBEdit on Mac OS). You should ask your hosting provider for more information and/or support. If your hosting environment supports user-defined ini-files then you can make the changes in your webroot, in a file configured by PHP. You can use the phpinfo() function to look up the required file name, or again: ask you hosting provider. Normally you should be able to create the file on your local computer, with your favorite text editor and upload it to your website using FTP.

      On the shell, through ssh, you can use echo to create the file:

      echo -n 'always_populate_raw_post_data = -1' > .user.ini

      Assuming .user.ini is the configured filename for these types of PHP user defined ini-file.

      1. Yes I can find the php.ini file but I can’t change it, cannot find the right application for this purpose….maybe creating a new php.ini file and replacing the existing one through Notepad could help?

      2. Hey I updated the php.ini file on my local host under MAMP but I’m still running into the same error. Any other advice?

  2. Nothing happens when i change the .ini file in my mamp folder. I assume it must be in the folder called 5.6.10/php.ini – right?

    1. nothing happens at my server either…

      Your PHP Version is 5.6.18-1+deb.sury.org~trusty+1, but always_populate_raw_post_data = 0. $HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will be removed in PHP 7.0. This will stop the installer from running. Please open your php.ini file and set always_populate_raw_post_data to -1. If you need more help please call your hosting provider.

      have changed the php.ini file with the property always_populate_raw_post_data = -1 and restarted apache2. I just keep getting the error message.

      Help anyone?

      1. Fixed the Magento2 always_populate_raw_post_data -1 issue as the php.ini file configuration is not working:

        In your apache2 config file /etc/apache2/sites-available/000-default.conf
        add this: php_value always_populate_raw_post_data -1

        mine looks like this:

        AllowOverride All
        php_value always_populate_raw_post_data -1

  3. Hi everyone,
    I am a newbie and don’t have no experience using magento.

    When I look in my php.ini file I find this
    “; Always populate the $HTTP_RAW_POST_DATA variable. PHP’s default behavior is
    ; to disable this feature. If post reading is disabled through
    ; enable_post_data_reading, $HTTP_RAW_POST_DATA is *NOT* populated.
    ; http://php.net/always-populate-raw-post-data
    ;always_populate_raw_post_data = on”

    Where do I change “always_populate_raw_post_data to -1” ?
    can anybody help me with that?

    1. Hi Ronny,

      Thank you for your comment! In the php.ini, remove the “;” before “always_populate_raw_post_data” and change “on” to “-1”, so it becomes:

      always_populate_raw_post_data = -1

      Don’t forget to restart your web server afterwards.

  4. I had same trouble.

    In my case there is a .php.ini.swp file , I was solved Once you remove it.

    > rm /etc/php5/apache2/.php.ini.swp
    > /etc/init.d/apache2 restart

    1. Hi!
      A .swp file is a vi swap file. Vi, or vim, stores changes to the file you’re editing in a swap file or recovery (like for when vi crashes). You can recover with vi -r <filename>. This has nothing much to do with the always_populate_raw_post_data setting and Magento, but can be pretty annoying :) Use :set noswapfile, or without the “:” in your vimrc file to disable the swap file.

  5. I Installed WAMP and Magento 2 on Win Server 2012 R2 and fixed this error by uncommenting the php_value always_populate_raw_post_data -1 located in C–Wamp64—bin—php—php5.6.16—php.ini

Hi! Join the discussion, leave a reply!