2

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?

5
  • I assume you have checked that the php_curl and php_openssl extensions are enabled in the php.ini used by Apache? Its not the same one that is used by PHP CLI in most cases, although I am not a fedora user.
    – RiggsFolly
    Jul 28, 2015 at 16:13
  • Yes, they are enabled in phpinfo().
    – Jeremy
    Jul 28, 2015 at 16:20
  • Maybe you have disabled php-curl mod in /etc/php5/apache2/php.ini. php-cli and apache2 php.ini - is different files. Jul 28, 2015 at 16:26
  • Also possible, that remote host reject your http-query. Try to execute also file_get_contents('xx.xx.xx.xx:8080/file.xml'). If it gives you same result, its not a curl problem, but server rejects you query. Jul 28, 2015 at 16:36
  • No, php-cli use php.ini like the navigator, the problem is not here. And it's not a reject by the server, it have no logs. I find the soluce, I don't know why but curl is blocked by SElinux when I use it from local to remote. I disabled SElinux and it's work. Thanks all for your help.
    – Jeremy
    Jul 29, 2015 at 13:31

1 Answer 1

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.