I switched to PHP 5.6.0 and now I get the following warning everywhere:
Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will
be removed in a future version. To avoid this warning set
'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream
instead. in Unknown on line 0
Warning: Cannot modify header information - headers already sent in Unknown on line 0
Fine, I rely on some deprecated feature. Except that I don't!
- I haven't ever used this variable in any of my scripts. To be honest I had no idea it even exists.
phpinfo()
shows that I havealways_populate_raw_post_data
set to 0 (disabled). So what is going on?
I don't want to "avoid the warning" by setting this value to -1. This will just hide the warning, and I'll still have deprecated configuration. I want to solve the problem at its source and know why PHP thinks that HTTP_RAW_POST_DATA
populating is turned on.
For anyone still strugling with this problem after changing the php.init as the accepted answer suggests. Since the error ocurs when an ajax petition is made via
POST
without any parameter all you have to do is change the send method toGET
.Still an other option if you want to keep the method
POST
for any reason is to add an empty JSON object to the ajax petititon.It turns out that my understanding of the error message was wrong. I'd say it features very poor choice of words. Googling around shown me someone else misunderstood the message exactly like I did - see PHP bug #66763.
After totally unhelpful "This is the way the RMs wanted it to be." response to that bug by Mike, Tyrael explains that setting it to "-1" doesn't make just the warning to go away. It does the right thing, i.e. it completely disables populating the culprit variable. Turns out that having it set to 0 STILL populates data under some circumstances. Talk about bad design! To cite PHP RFC:
So yeah, setting it to -1 not only avoids the warning, like the message said, but it also finally disables populating this variable, which is what I wanted.
I got this error message when sending data from a html form (Post method). All I had to do was change the encoding in the form from "text/plain" to "application/x-www-form-urlencoded" or "multipart/form-data". The error message was very misleading.
I experienced the same issue on nginx server (DigitalOcean) - all I had to do is to log in as
root
and modify the file/etc/php5/fpm/php.ini
.To find the line with the
always_populate_raw_post_data
I first rungrep
:That returned the line
704
Then simply open
php.ini
on that line withvi
editor:Remove the semi colon to uncomment it and save the file
:wq
Lastly reboot the server and the error went away.
If the
.htaccess
file not avilable create it on root folder and past this line of code.Put this in
.htaccess
file (tested working well for API)you should add or uncomment the property
always_populate_raw_post_data
inphp.ini
and set its value to-1
. In my casephp.ini
is located in:C:\wamp64\bin\php\php5.6.25\php.ini
Finally restart WAMP (or click restart all services)