Ubuntu Lamp - Proxy - Firewall - Joomla curl and fsockopen not working

Okay, I've been struggling with this for a couple of days now.

I have a Joomla installation on a local machine on our network for our intranet, Jomsocial also installed.

The problem is when I go to site setup or edit an event or go to any joomla module that calls the external api, I get either

CURL error : 7 Failed to connect to maps.google.com port 80: Connection timed out 

      

or

Connection timed out (110) 

      

The problem is definitely not Joomla or Jomsocial. I have other php applications running on the same server which also cannot communicate with external api

Server Tuning

Ubuntu 14Lts PHP 5.5 Apache 2.4.7 MariaDB

The server is behind a proxy, but has full internet access from the CLI. all required php extensions are included. I have set the global proxy variable in / etc / environment also in apt config and set the proxy variable in Joomla. My Joomla updates and component updates are working fine, but no fsockopen function curls are not working.

I don't know where else to look for the error. I think the www-data user may not have sufficient privileges to execute fsockopen and curl from the browser.

Any advice?

UPDATE, I tested the site on another computer that is not on the corporate network (directly connected to the internet) and everything works. So I'm pretty sure my problem is with my machine and network permissions, in particular my www-data user. How can I fix this?

+3


source to share


3 answers


It looks like the variable is http_proxy

not being used by PHP (mod_php) even if used to pass it PassEnv

or if it is directly set with SetEnv

. Also, it displays correctly when getenv('http_proxy')

called in a PHP script.

However, there are two ways to make it work:



  • Install it in Apache envvars ( /etc/apache2/envvars

    ) as follows:

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

    and restart Apache.

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

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

Again, if you check with getenv('http_proxy')

, you will see that they are set correctly.

+1


source


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

  • Make sure php5-curl is installed. Joomla can only use proxies with CURL as the transport layer.

    sudo apt-get install php5-curl
    
          

  • I didn't have to inject proxies in Joomla config. The only thing that was done was that the update connection will not time out, but will return immediately.

  • It is not enough to place environment variables in / etc / apache 2 / envvars, you also need to use "PassEnv" in / etc / apache 2 / apache2.conf, i.e. (taken from fooobar.com/questions/2226290 / ... )

    PassEnv http_proxy
    
          

  • In addition, I had to pass as a HTTP_PROXY , https_proxy , as the xml-lists were obtained via http and files using https (possible update files from github), You may need to have these variables in lower case, but on the configuration page Joomla "PHP info" similarly named variables are displayed in uppercase.

  • I don't know where it really mattered, but restarting apache2 like this seems to be the correct way (instead of apache2ctl).

     sudo service apache2 restart
    
          



I have collected some random code to check whether the curl and php work together or not, most of which comes from fooobar.com/questions/2226291 / ... . I just added a lot of error messages. Place the test.php file in your webfolder root and watch with your favorite browser.

<?php
ini_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>';
?>

      

+1


source


Use this:

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

      

or that:

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.

      

0


source







All Articles