PHP able to receive post request with a raw text but its giving error when post same data raw json

I’m posting data to my API endpoint. it’s simple JSON data. But I’m getting error 404 when posting data as raw JSON but if I post the same data at the same endpoint as raw text its works.

working as raw text

getting error 404 as raw JSON

<?php
    var_dump(http_response_code());
    var_dump($_POST);
    echo file_get_contents("php://input");
        
  ?>

I have removed all code from the API end point and just trying to print post data.

Sample JSON :

{
    "object": "whatsapp_business_account",
    "entry": [
        {
            "id": "456",
            "changes": [
                {
                    "value": {
                        "messaging_product": "whatsapp",
                        "metadata": {
                            "display_phone_number": "123456789",
                            "phone_number_id": 123456789
                        },
                        "contacts": [
                            {
                                "profile": {
                                    "name": "NAME"
                                },
                                "wa_id": 123456789
                            }
                        ],
                        "messages": [
                            {
                                "from": 123456789,
                                "id": "wamid.ID",
                                "timestamp": 123456789,
                                "text": {
                                    "body": "MESSAGE_BODY"
                                },
                                "type": "text"
                            }
                        ]
                    },
                    "field": "messages"
                }
            ]
        }
    ]
}
 

I have checked JSON and it’s a valid JSON. no special character but still unable to solve this issue.

One more thing its working on my local machine under XAMPP but not on Linux shared server.