How to Setup Composer with PHP on Windows

in #utopian-io8 years ago (edited)

logo.png

What is Composer?

Composer is a modern tool for dependency management in PHP, like a package manager. as It allows to easily install PHP packages and even frameworks etc..

What Will I Learn?

  • Configure PHP 7
  • Install Composer
  • Basic Usage

Requirements

  • Windows 10,8.1,7 (x64)
  • Text Editor (Notepad++ eg.)
  • PHP 5 or above
  • Visual C++ Redistributable for Visual Studio 2012
  • Visual C++ Redistributable for Visual Studio 2017

Difficulty

  • Basic

Setup Composer

Composer requires the PHP OpenSSL extension to be enabled, so let's enable it in your php path C:\PHP\php.ini

Sketch.png

Use your text editor's search function to search for extension=openssl, there should already be a commented line for it
Sketch1.png

just uncomment that line.

Sketch2.png

Make sure you've set the path of extensions.

Search for ; extension_dir = "ext" Then uncomment it and set the path of ext folder.

for example: extension_dir = "C:\php\php5\ext"
Sketch7.png

The installer will download composer for you and set up your PATH environment variable so you can simply call composer from any directory.

Download and then run [Composer-Setup.exe] (https://getcomposer.org/Composer-Setup.exe) - it will install the latest version of composer whenever it is executed.

Install Composer

  • Developer Mode means that it will automatically select the php path if you have more than one php version and you prefer a specific version just uncheck it.

Sketch3.png

Follow the instructions, when prompted for the path to PHP, browse to your php path and select php.exe.

Sketch4.png

Then follow the rest of instructions of the setup process. Until you finish.
Sketch5.png

That's it, Composer is now installed globally and it can be used from anywhere. you can try it out, just open a new command prompt and type composer.

Check Composer Version

Open command prompt then type composer -v

Sketch6.png

Note:

you may need to restart the system to use composer globally.

Basic Usage

To start using Composer in your project, all you need is a Create a new file composer.json that you've been created file. This file describes the dependencies of your project. also it can contain other meta data.

Create a new file composer.json that you've been created in a directory, that directory is a package. When you add a require to a project, you are making a package that depends on other packages.

For example I want I want to install Laravel framework

So So I will create new project folder and call it laravel

Sketch8.png

Then Then Open it. Then Create a new file composer.js

{
    "require": {
        "laravel/laravel": "5.0.*"
    }
}

That's it.

Previous Tutorials


Images has been taken/created by @Jinzo for an open source project.



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Great post.

This post has received a 0.18 % upvote from @drotto thanks to: @jinzo.

Your contribution cannot be approved because it does not follow the Utopian Rules, and is considered as plagiarism. Plagiarism is not allowed on Utopian, and posts that engage in plagiarism will be flagged and hidden forever.

You can contact us on Discord.
[utopian-moderator]

That isn't correct at all.
even the picture you've made the text isn't matching with my post.

Thank you.

Coin Marketplace

STEEM 0.13
TRX 0.34
JST 0.036
BTC 108529.70
ETH 4405.54
USDT 1.00
SBD 0.82