Reputation: 111
I'm on Linux Fedora 20, with a LAMP. I use this simple php script which use curl :
// test.php
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPGET, 1);
curl_setopt($ch, CURLOPT_URL, "http://xx.xx.xx.xx:8080/file.xml");
curl_setopt($ch, CURLOPT_USERPWD, FEDORA_USER.":".FEDORA_PASS);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
In php cli, I make :
php test.php
Curl works.
In php cli, I make :
curl http://xx.xx.xx.xx:8080/file.xml
Curl works.
But in a navigator (chrome, firefox, ...), curl doesn't work. The error is :
Fatal error: (7) `curl_exec(...)` returned false.
Error: Failed to connect to xx.xx.xx.xx: Permission denied.
Info: Array ( [url] => http://xx.xx.xx.xx:8080/file.xml
[content_type] =>
[http_code] => 0
[header_size] => 0
[request_size] => 0
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0
[namelookup_time] => 1.6E-5
[connect_time] => 0
[pretransfer_time] => 0
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => -1
[starttransfer_time] => 0
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => 172.17.100.8
[certinfo] => Array ( )
[primary_port] => 8080
[local_ip] =>
[local_port] => 0
)
in /home/...../test.php on line 139
Navigator use /etc/php.ini
Php-cli use /etc/php.ini
I don't unterstand why it doesn't work on navigator, the problem isn't server side. Can you help me?
Upvotes: 2
Views: 1055
Reputation: 3484
If you found the problem was SELinux, you can allow httpd to hit the network with setsebool -P httpd_can_network_connect on
and avoid disabling all of SELinux. See https://stackoverflow.com/a/50808173/404960
Upvotes: 2