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?
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/audit/audit.log if in fact selinux is the cause.
If you are new to running apache under selinux have a look at
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.
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);