Ubuntu Lamp - Proxy - Firewall - Joomla curl and fsockopen wont work Ubuntu Lamp - Proxy - Firewall - Joomla curl and fsockopen wont work apache apache

Ubuntu Lamp - Proxy - Firewall - Joomla curl and fsockopen wont work


It appears that the http_proxy variable is not used by PHP (mod_php) even if PassEnv is used to pass it, or if it directly set with SetEnv. In addition, it is displayed correctly when getenv('http_proxy') is called in a PHP script.

However, there are two ways to get it working:

  • Set it in the Apache envvars (/etc/apache2/envvars) as follows:

    export http_proxy=http://proxy.example.com:8080/

    and restart Apache.

  • Put in the PHP files that load the application (e.g. index.php, bootstrap.php and etc.):

    putenv('http_proxy=http://proxy.example.com:8080/');

Again, if you test with getenv('http_proxy') you will see that they are set correctly.


I've just had the same problem with a pretty close setup (only difference is mysql instead of MariaDb, and Joomla 3.4.1) and it took me quite a while to get everything together, so I will put the list of possible stumbling blocks here:

  1. Make sure php5-curl is installed. Joomla can use a proxy only with CURL as transport layer.

    sudo apt-get install php5-curl
  2. I found no use in entering the proxy in the Joomla configuration. The only good it did was that the update connection would not time out but return immediately.

  3. It is not enough to place the environment variables in /etc/apache2/envvars, you also need to use "PassEnv" in /etc/apache2/apache2.conf,i.e. (taken from https://stackoverflow.com/a/21571588/1967646)

    PassEnv http_proxy
  4. Also, I needed to pass both HTTP_PROXY, HTTPS_PROXY as xml-lists were fetched via http and files lateron via https (probably update files from github). Possibly, you need to have these variables in lower case but on the joomla configuration page "PHP information" similarly named variables show up in upper case.

  5. I don't know where this really made any difference, but restarting apache2 as follows seems to be the right way (instead of apache2ctl).

     sudo service apache2 restart

I put together some haphazard code for testing whether curl and php would work together or not, most of it comes from https://stackoverflow.com/a/1477710/1967646. I only added plenty of error reporting. Put in a file test.php in the webfolder's root dir and look at with your favorite browser.

<?phpini_set('display_errors', 'On');error_reporting(E_ALL);$url = 'http://update.joomla.org/core/list.xml';function get_page($url, $proxy=true) {    if ($url!='') {        $ch = curl_init ();        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);        curl_setopt($ch, CURLOPT_URL, $url);        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);        if ($proxy) {            curl_setopt($ch, CURLOPT_PROXY, '<enter your proxy host here>');            curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);            curl_setopt($ch, CURLOPT_PROXYPORT, <enter your proxy port here>);        }        if (! $html = curl_exec($ch)) {            echo '<br>Last CURL error is '.curl_error($ch).'<br>';    } else {            echo '<br>CURL without error.<br>';    }        curl_close($ch);        return $html;    } else {    echo 'Empty URL.';    }}echo 'Hello, getting pages via curl:';$html=get_page($url);var_dump($html);echo bin2hex($html);echo '<br>';var_dump(get_page($url, false));echo '<br>done.<br>';?>


Use this:

export http_proxy=http://your.proxy.server:port/

or this:

From man curl:

-x, --proxy <[protocol://][user:password@]proxyhost[:port]> Use the specified HTTP proxy.  If the port number is not specified, it is assumed at port 1080.