2

I am trying to get PHP to execute a curl connection to another server. To connect to the server, we need to go via a proxy. Within bash, we have set the env-variable http_proxy and this works correctly while using the php script from the command-line. However, when attempting to execute curl, or wget from apache, it fails with no errors. The server is configured with SELinux based on Centos defaults. This has been unchanged as I am unsure about SELinux configuration. Has anyone else had a similar issue?

  • 1
    Just to be clear: are you trying to eval/exec the curl binary from within a PHP file that's being served by apache? – SmallClanger Nov 29 '10 at 17:17
4

Under SELinux httpd (and therefore its children) isn't allowed to make outgoing connections. Try

setsebool -P httpd_can_network_connect 1

You should see messages in /var/log/messages or /var/log/audit/audit.log if in fact selinux is the cause.

If you are new to running apache under selinux have a look at httpd_selinux(8).

Edited to add: P.S. If you're not an selinux guru plan to spend a lot of time trying to get even mildly unusual apache configs working under selinux.

  • Yes it was SELinux that was preventing apache from performing the curl execution. However, after fixing that, I ended up disabling SELinux anyway because of the need to perform command execution which was also being blocked by SELinux. Thanks anyway and sorry for the late response. – Alex Lintott Jan 5 '11 at 11:33
  • is it possible to allow connection to localhost only ? – Pavel Niedoba Oct 13 '16 at 17:52
0

Have you told curl it needs to connect via a proxy?

$curlHandle=curl_init();
curl_setopt($curlHandle, CURLOPT_URL, 'http://www.google.com');
curl_setopt($curlHandle, CURLOPT_HTTPPROXYTUNNEL, true);
curl_setopt($curlHandle, CURLOPT_PROXYPORT, 8080);
curl_setopt($curlHandle, CURLOPT_PROXY, 'proxy.localnet.com');
// optional
// curl_setopt($curlHandle, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
// curl_setopt($curlHandle, CURLOPT_PROXYUSERPWD, 'user:s3cr3t'); 
// curl_setopt($curlHandle, CURLOPT_PROXYAUTH, CURLAUTH_NTLM);

$out=curl_exec($curlHandle);

curl_close($curlHandle);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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