Just simply using file_get_contents on any URL is throwing the 500 internal server error by apache. The same goes to cURL. I'm using MAMP with php 8.3.30.
// Using
$response = file_get_contents("https://google.com");
// Using
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://google.com");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$response = curl_exec($ch);
if (!curl_errno($ch)) {
echo $response;
}
curl_close($ch);
I have literally tried every solution I could find on Google and given by the AI, nothing is working at all so I'm making this thread.
---
Here's everything that I tried:
1: The related php.ini config I have
allow_url_fopen = On
max_execution_time = 120
memory_limit = 256M
2: Error reporting options
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
nothing is printed, just apache's default 500 internal server error
3: Checked every single log files in the logs directory too, apache_error.log, php_error.log and the mysql and mamp log files, absolutely nothing is printed there.
4: Faked the user agent like
$opts = [
"http" => [
"method" => "GET",
"header" => "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36\r\n"
]
];
$context = stream_context_create($opts);
echo file_get_contents("https://google.com", false, $context);
doesn't work either.
I'm also sure the internal server error is not thrown from the site that I'm trying to get the contents from. The error page is from my apache. It doesn't even take time to process this request, it's instant.
I've never encounter this type of problem before. What on Earth is happening here? If I missed any configuration, please point.
And btw, I'm executing this from my localhost (laptop) and not a host or any server. Could that be the reason? I don't think I've had this problem a few years back tho.