How to install composer on Wamp

If you run PHP applications on WAMP and if you need to need to install composer to manage dependency of libraries inside your project, you can do so by installing Composer for Windows.

Installing composer

  1. You can download composer from here.
  2. Run the setup file and click Next button.
  3. The next screen is to Select Components. Leave the default settings and click Next.Installing composer on Wamp
  4. In this step, Composer setup wizard will check for location of PHP binary in PATH environment variable. If you have successfully installed WAMP on your system, you should see something like the screenshot seen below.Compose PHP Path
  5. The setup wizard will attempt to download the required files from getcomposer.org . You installation will be completed once this step is done.

How to fix “Failed to open stream” error

In case your setup encounters Failed to open stream error, you can fix this by enabling openssl extension in php.ini file. This error message means that the composer setup is unable to download required files via the https protocol. Because the openssl extension is not enabled in either Apache’s php.ini file or WAMP PHP’s php.ini file or both.

 

How to install composer on Wamp

 

To enable openssl extension just uncomment the line that reads extension=php_openssl.dll. You can uncomment by removing the semicolon preceding the line.

Enable Openssl in WAMP via php.ini

 

Please note that there will be two php.ini files. You should make the above mentioned changes to both the files. If WAMP Server is installed on C:\ drive, you should find the php.ini files at,

C:\wamp\bin\php\<php_version>\php.ini
C:\wamp\bin\apache\<apache_version>\bin\php.ini

Resuming Composer Setup

Once the openssl extension is enabled, click Retry. Or restart the setup wizard again. You shouldn’t have any issues now.

ALSO READ  Adding content to an existing PDF using FPDI PHP library

Why do you need Composer?

So you read somewhere that composer is the only or easiest way to install a PHP library/framework you need for your  project? Composer is a dependency manager for PHP. Some libraries/frameworks need other libraries to work properly. For instance, I was recently working with Ratchet – a websocket framework for PHP. Ratchet needs React, Guzzle, symphony and other frameworks to work. Downloading and including the right version of each of these libraries would be painful task. But with composer, I just specified the unique package name of the library I want to download inside your project folder. Composer automatically downloaded all the dependencies  and made it available for me via the autoload.php file.

composer-json-example

 

Leave a Reply