Debian – curl: (7) couldn’t connect to host

Bit of an odd one here with a pretty easy fix.

I was trying to install Composer on a fresh Debian server, and kept getting the following error:

myuser@debian-box:/var/www/html/mysite.co.uk$ sudo curl -sS http://getcomposer.org/installer | php
#!/usr/bin/env php
All settings correct for using Composer
Downloading...
Download failed: file_get_contents(https://getcomposer.org/composer.phar): failed to open stream: Connection timed out
Downloading...
Download failed: file_get_contents(https://getcomposer.org/composer.phar): failed to open stream: Connection timed out
Downloading...

A quick ls on the /var/www/html dir will show that the installer file has successfully downloaded, but the error is happening when trying to run the downloaded file.

The fix is to simply remove the call to https://getcomposer.org/composer.phar inside the installer file, and then re-run it.

So, something like: sudo vi /var/www/html/installer

Then once inside vi, type in /https, and keep hitting ‘n’ until you see:

$source = (extension_loaded('openssl') ? 'https' : 'http').'://getcomposer.org/composer.phar';

Then simply edit that line to be:

$source = (extension_loaded('openssl') ? 'http' : 'http').'://getcomposer.org/composer.phar';

Yes, it’s horrible – you could do a nicer job, but this will fix it quickly and you don’t need the file after this anyway.

So once saved (:wq), you can then do:

myuser@debian-box:/var/www/html/mysite.co.uk$ sudo php installer
All settings correct for using Composer
Downloading...

Composer successfully installed to: /var/www/html/mysite.co.uk/composer.phar
Use it: php composer.phar
myuser@debian-box:/var/www/html/mysite.co.uk$ ls
composer.phar installer
myuser@debian-box:/var/www/html/mysite.co.uk$ sudo mv composer.phar /usr/local/bin/composer

Or, you know, just use Ubuntu server and not experience this kind of hassle.

Setting up a Debian server for hosting a Symfony 2 site with Apache 2

This is more a guide for me than for the Internet at large, so if you do find this, and you find it useful, excellent.

  1. Install to shell
  2. Check network connectivity – ifconfig
  3. su
  4. Edit /etc/apt/sources.list , remove references to CD Rom
  5. aptitude install sudo
  6. add {user} ALL=(ALL) ALL , under the root line
  7. exit
  8. test with sudo apt-get update
  9. sudo apt-get install git curl acl vsftpd
  10. curl -s https://getcomposer.org/installer | php
  11. sudo mv composer.phar /usr/local/bin/composer