title: PHP cURL doesn't see the /etc/hosts file
body: <p>I'm having troubles on making the PHP cURL library recognize the alias I created in my <code>/etc/hosts</code> file.</p>
  
  <p>This is what I have in my <code>/etc/hosts</code> file right now:</p>
  
  <pre><code>192.168.0.20 www.example.dev
  </code></pre>
  
  <p>On the other side (192.168.0.20) Apache is configured to run the virtual host on the <code>example.dev</code> domain.
  The alias works if I test it on my browser but with PHP cURL just doesn't work.</p>
  
  <p>The <code>hosts</code> file is on both machines <em>(192.168.0.10 &lt;= PHP cli, 192.168.0.20 &lt;= Apache)</em>.</p>
  
  <p>For the sake of completeness this is the PHP code I'm using.</p>
  
  <pre class="lang-php prettyprint-override"><code>        $this-&gt;url = 'http://www.example.dev/';
          $this-&gt;ch = curl_init();
          $header = array
          (
              "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
              "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3",
              "Accept-Encoding: gzip,deflate,sdch",
              "Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4",
              "Cache-Control: max-age=0",
              "Connection: keep-alive",
          );
  
          $sUserAgent = $this-&gt;tor ? UserAgents::getRandom() : UserAgents::CHROME16_LINUX;
  
          curl_setopt($this-&gt;ch, CURLOPT_HTTPHEADER, $header);
          curl_setopt($this-&gt;ch, CURLOPT_USERAGENT, $sUserAgent);
          curl_setopt($this-&gt;ch, CURLOPT_URL, $this-&gt;url);
          curl_setopt($this-&gt;ch, CURLOPT_HEADER, false);
          curl_setopt($this-&gt;ch, CURLINFO_HEADER_OUT, true);
          curl_setopt($this-&gt;ch, CURLOPT_FOLLOWLOCATION, true);
          curl_setopt($this-&gt;ch, CURLOPT_RETURNTRANSFER, (bool) $waitResponse);
          curl_setopt($this-&gt;ch, CURLOPT_VERBOSE, (bool) $this-&gt;verbose);
          curl_setopt($this-&gt;ch, CURLOPT_PORT, $this-&gt;port);
          curl_setopt($this-&gt;ch, CURLOPT_AUTOREFERER, true);
          curl_setopt($this-&gt;ch, CURLOPT_MAXREDIRS, 10);
          curl_setopt($this-&gt;ch, CURLOPT_ENCODING, '');
          curl_setopt($this-&gt;ch, CURLOPT_CONNECTTIMEOUT, 30);
          curl_setopt($this-&gt;ch, CURLOPT_TIMEOUT, 60);
          curl_setopt($this-&gt;ch, CURLOPT_DNS_CACHE_TIMEOUT, 120);
          curl_setopt($this-&gt;ch, CURLOPT_COOKIESESSION, true);
          curl_setopt($this-&gt;ch, CURLOPT_COOKIEFILE, 'cookie');
  
          foreach ($this-&gt;files as $k =&gt; $file) {
              $this-&gt;data['_file_' . $k] = '@' . $file;
          }
  
          curl_setopt($this-&gt;ch, CURLOPT_POST, true);
          curl_setopt($this-&gt;ch, CURLOPT_POSTFIELDS, $this-&gt;data);
  
          $this-&gt;result = curl_exec($this-&gt;ch);
  </code></pre>
  
  <p><strong>Note:</strong> This issue seems like <a href="https://stackoverflow.com/questions/3390549/set-curl-to-use-local-virtual-hosts">this one</a> but PHP related.</p>