Composer Does Not Install

Image from Composer website https://getcomposer.org/
Image from Composer website https://getcomposer.org/

Today, I’m trying out a new PHP framework called Slim, a micro-framework. It has a minimal foot print as stated but I will find out by the end of the day. I’m building a simple web app that pulls data from a Piwik instance using the Piwik Repotrting HTTP API. I need to build something quick hence the use of this small framework. The creator’s of the framework say that an afternoon is enough to learn the framework (I hope so). Of course, a good background in PHP is a must.

Composer, a PHP dependency manager, is a first requirement to be able to install Slim. However, as I was installing composer in a folder, I got the following error (I’m developing in a Mac OSX environment):

All settings correct for using Composer

Downloading…

Could not create file /Users/brianbirir/Sites/piwik/composer.phar: fopen(/Users/brianbirir/Sites/piwik/composer.phar): failed to open stream: Permission denied

Download failed: fopen(/Users/brianbirir/Sites/piwik/composer.phar): failed to open stream: Permission denied

fwrite() expects parameter 1 to be resource, boolean given

after writing the following command:

curl -sS https://getcomposer.org/installer | php

Solution:

Just add sudo before curl and php  and composer shall install. Remember composer should be installed in the folder where your project will run from or where the source code is stored.

 

UPDATE One:

Because I need to implement the project ASAP, I decided to move on with CodeIgniter, a framework I’m very familiar with (I’ll learn Slim later, maybe the coming week). But to pull the data from the API, I need to use something that would consume the JSON via HTTP, basically a HTTP client. I decided to use Requests for PHP. It does not rely on cURL and is framework agnostic. There are other PHP REST clients (e.g. Guzzle) but this is the simplest (See page on Why Requests). I will post another blog article on using Code Igniter together with Requests for PHP.

January 13, 2016

Posted In: Information Technology

Tags: , , ,

Leave a Comment