PHP Composer installation fails: file could not be downloaded: allow_url_fopen must be enabled

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, December 30, 2015

Follow me on Twitter as @mattiasgeniar

If you have composer installed (the package manager for PHP), you can get the following ‘error’ message when you try to run a composer install.

$ composer install
 Loading composer repositories with package information
[Composer\Downloader\TransportException]
The "https://packagist.org/packages.json" file could not be downloaded: allow_url_fopen must be enabled in php.ini (https:// wrapper is disabled in the server configuration by allow_url_fopen=0 failed to open stream: no suitable wrapper could be found)

install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-plugins] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--ignore-platform-reqs] [--] [<packages>]...

The easiest fix is just to set the allow_url_fopen option to On in php.ini. But that enables it server-wide, you may not want that.

Here’s a simple workaround, by setting the option when calling the composer binary.

$ which composer
/usr/local/bin/composer

$ php -d allow_url_fopen=on /usr/local/bin/composer install

By calling the php binary with the -dallow_url_fopen=on parameter, you’re overwriting the php.ini for that invocation of composer. So you can bypass the php.ini settings altogether.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.