• Facebook
  • Twitter
9
VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)

Setting Up Composer PHP Dependencies Manager in Windows

Ayub Lin October 13, 2012

Setting Up Composer PHP in WindowsProbably one of the most important principles in Software Engineering is DRY (Don’t Repeat Yourself!), every time you found yourself writing the same code more than once, in a same project, or in different projects then you have to re-think of what you have done. For example, how many times you have wrote authentication system for your projects? Or email class to send emails with PHP? If you’re doing it over and over again, maybe a package management could help you on this.

PHP Packages Dependencies Manager

PHP has PECL and PEAR as repository for extension and code libraries, PECL stands for PHP Extension Community Library, in PECL extensions is written in C language, and can be loaded into PHP to provide additional functionality. What you need to use PECL is administrator rights, C compiler and associated dependencies for those extensions. PEAR is PHP Extension and Application Repository, where in PEAR the extension or libraries is written in PHP. So it could be downloaded and loaded to our PHP code.

PECL and PEAR are great tools, but they are system-wide packages manager, meaning, it’s installed on the system not per project, and not everyone prefer that, at least me. I often just do everything on-the-fly in PHP, whenever I need a PHP library, I will just simply download and include it, and it’s the era of PHP Frameworks, many commons functionalities has been included on the frameworks. But that’s create one big problem, everyone have their own pick on the framework, and each framework has their OWN implementation of providing functionalities with their libraries, that makes switching frameworks not an enjoyable task, we need to re-learn many things.

What is Composer?

Composer exists to overcome the problem mentioned above, composer is a dependencies manager that come in a form of command utilities, composer make it possible to ‘plug and play’ PHP packages across application no matter what frameworks we are using as long as the packages follow the shared format. With composer we can define our project dependencies simply in a ‘composer.json’ file, and later on we can install and update these dependencies automatically.

An example:

    "require": {
        "illuminate/blade": "dev-master"
    }

This will make composer include ‘blade’ from the vendor `illuminate` in our project, and we can do update to the ‘blade’ package with one command.

Setting Up Composer In Windows

And here comes the main topic, how to set up composer, and this one is specifically written for windows users. At first, I planned to wrote the complete instruction on how to setup composer in windows with the standard way, which including downloading the installer manually and run the install on command prompt, and also how to make the composer can be accessed globally by pre-run a bat script every time we open command prompt, it can be achieved by hacking around with the registry editor, but I found a much better solution, instead of going with all the fuss, we are going to use a really cool installer built by John Stevenson which you can download the composer windows installer and do the install easily. With this installer, you can choose whether you want to install it per project basis or install it globally so you can run the ‘composer’ command everywhere on your projects.

[Update]  Before you continue to read, please read John’s comment.

Installing Composer in Per Project Basis

To install composer in windows per project basis, you just need to choose the ‘basic’ option in the installation procedure.

Composer Windows Installer Basic Option

Composer Windows Installer Basic Option

And then you just need to specify the folder, where you want the composer will be installed.

Composer Windows Installer Choose Folder

Composer Windows Installer Choose Folder

And here it is, you can access the composer on the selected folder, and you will need to be able to run ‘php’ via command prompt, and use the composer.phar that has been installed in the folder.

Run Composer Command Per Project Basis

Run Composer Command Per Project Basis

Installing Composer to Use Globally in Every Projects

This is the setup that I prefer, to install the composer globally, that way you can use composer everywhere. And to setup composer in windows globally, just like the previous one, you just need to choose an option, which is ‘global’ option.

Composer Windows Installer Global Option

Composer Windows Installer Global Option

And here you go, open up your command prompt, and you can access composer, as easy as just calling composer.

Run Composer Command Globally

Conclusion

Composer is a great tool for managing packages and dependencies in your projects, let’s hope every packages in PHP will be available in composer soon and I encourage everyone to write their packages in compliance with composer, so that everyone can share their packages no matter what framework we are using. And for your information most of the famous PHP frameworks has started to give their full support to composer, and built their system components as composer packages, you can check out FuelPHP, Laravel 4, and Symfony2. So it’s the end of guide on setting up composer in windows, for UNIX based operating system, you could do this easily via terminal, which has been documented well on the composer site.

Comments (9)

  1. Hey Ayub,
    Just saying thanks for this guide. It was the only one I could find that was of any help and was very simple!
    I was following Jeffs PHP tutorials and he started using composer and i got stuck being on windows. Looking at the post date you brang it out just intime for me :)

    Thanks again.

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    Reply
    • Hi Jarvus, glad that this helps you and the biggest credit also goes to John Stevenson (I can’t find his personal site), the one who made the windows installer.

      And thank you for sparing your time saying thanks, means a lot to me :)

      VN:F [1.9.22_1171]
      Rating: 0.0/5 (0 votes cast)
      Reply
      • mee too following Jeffs tutorials and thank god I found your website…you saved me man… thank you…

        VA:F [1.9.22_1171]
        Rating: 0.0/5 (0 votes cast)
        Reply
        • Hi, you’re welcome, thanks for reading :) btw, which Jeffs tutorial that you guys were mentioning?

          VN:F [1.9.22_1171]
          Rating: 0.0/5 (0 votes cast)
          Reply
  2. Hi Ayub

    Many thanks for your kind comments about my Composer installer. It has now been adopted over at http://getcomposer.org

    Also, and sorry because all your nice screenshots are now out of date (!), I have updated it to automatically do a global install as the default, which basically gives people no choice, but at least makes it simpler.

    If anyone wants to install it manually, I have got full instructions on the github wiki, which includes getting it set up for Git Bash and Cygwin.

    Thanks again,

    John

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    Reply
    • Hi John, you’re welcome :)

      Ahh, it’s been officially adopted, nice! I will update the download link.

      I see, for now I will give a notice at the post to the reader to see your comment, and I will update my post later :D

      VN:F [1.9.22_1171]
      Rating: 0.0/5 (0 votes cast)
      Reply
  3. I didn’t get an option in the installation process to select Basic or Global… any idea why?

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    Reply
  4. Pingback: Setting Up Composer PHP Dependencies Manager in Windows | Manny Isles

Leave a Comment

Login to your account

Can't remember your Password ?

Register for this site!

! Important: This is an archived version of the old website
disclaimer