Does Magento 2 throw an error about always_populate_raw_post_data being set to 0? And are you 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+.

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. And this is what causes errors when trying to install or update 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.

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 Magento 2.0's PHP settings check still complains, 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

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.

When you go through your PHP configuration, fix & set correct values for curl.cainfo and openssl.cafile too! Stop turning off CURLOPT_SSL_VERIFYPEER!

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".

HTH :)

Donate a cup of coffee
Donate a cup of coffee

Thank you very much! <3 ❤️

14 Comments

  1. 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

  2. sakamotz

    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

    • 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.

  3. Ronny

    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?

    • 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. shahzad

    .user.ini file Great it worked. thanks

  5. berteldk

    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?

    • jaf kman

      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?

      • jaf kman

        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

  6. Angela

    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:-)))

    • 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.

    • max

      You should be able to change the php.ini from /Applications/MAMP/conf/php5.6.1/php.ini

      • Angela

        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?

      • danieliwao

        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?

Leave a Reply

Your email address will not be published. Required fields are marked *