Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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
up vote 2 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.

share|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

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

curl_setopt($curlHandle, CURLOPT_URL, '');
curl_setopt($curlHandle, CURLOPT_HTTPPROXYTUNNEL, true);
curl_setopt($curlHandle, CURLOPT_PROXYPORT, 8080);
curl_setopt($curlHandle, CURLOPT_PROXY, '');
// optional
// curl_setopt($curlHandle, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
// curl_setopt($curlHandle, CURLOPT_PROXYUSERPWD, 'user:s3cr3t'); 
// curl_setopt($curlHandle, CURLOPT_PROXYAUTH, CURLAUTH_NTLM);


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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