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?

link|improve this question
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
feedback

2 Answers

up vote 1 down vote accepted

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.

link|improve this answer
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
feedback

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);
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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