PHP Composer Quickstart



hey youtubers today I'm going to talk about composer a PHP dependency manager and this has been needed for a while I haven't personally got into the thick of it but I know at some point it's just ridiculously good idea Python has something called pip for Python package management and PHP really really needs this so to get started what you just want to do is go to the download to get it on your computer and if you have a console with curl enabled you can just download it like this I'm using Windows so I just go to the windows installer and get composer setup and I previously installed this but I'll go through anyways again it's very simple to install and it just locates your PHP executable since I'm using WAMP it found that if you're using xx a.m. P or whatever it's called don't do that and it says yeah there it is it's downloading the far file and you might get this error that says the OpenSSL extension is missing and that's an easy fix now the first thing you might think is I have to recompile PHP well if you downloaded WAMP you don't have to I don't think you do with xampp either so finish install and finish and first thing is if I open up my WAMP toolbar and I go to PHP ini and I look for SSL and comment the uncomment the semicolon and save it it's not going to work because lamp unfortunately uses a different PHP I and I that you open from here than it does in the console and it's kind of a pain in the butt so I'm going to my lamp directory C Drive lamp I'm going to go to bin which is binary I'm going to go to PHP and then PHP five four three and then I'll go down to PHP ini and in here I'll look for SSL and you see how the other one was uncommented but this one wasn't because this applies to the console now that's not true in a linux environment you just have one PHP ini unless you're doing something crazy with a bunch of virtual hosts that allow their own ini files and I'll just restart WAMP okay so what I'm going to do is open up a console I'll just open up a git bash it's my favorite because it's really sweet and simple now if you had a console open previously you're going to want to close it so that it can rear edge astir Composer solve this type composer and if you get a list of commands you're ready to go so it's very simple right there so what we're going to do is actually install a couple packages just to test it out so they're stored at packages org ok if I go to the main site they show you how to define your dependencies and this is why it's good if you're building an application and you have a framework with some other third party software or you don't have to reinvent the wheel you can simply define the version you want to use and when you deploy it on your server it's always going to use the correct version so you don't have to worry about breaking changes and things if you already have everything working that's why it's really useful so with that said I'm going to go to just C drive workspace and I'm going to make a directory called my app okay and this is just for pretend and I'll CD into my app and there's nothing in here and the way we do this is it's in JSON code so I'll say touch composer dot JSON okay and you could type notepad to open notepad for composer dot JSON like this well I guess it's not in my shell but I have sublime shortcut it in here so I'll just do sub blah and here it is here so what I'll do is I'll just copy this stuff and paste it in here and we can actually get rid of all this okay and remember this is just JSON formatted it's telling you what to require and this is just one of the simple things you can do so let's start with a couple things let's say I want to install XP SPL to some PHP signal library and there's a whole bunch of stuff here that looks confusing what I would suggest is scrolling down to a stable version so I'll do 4.01 and right here it says require and it gives us the code right here so I'll copy this and I'll paste it in there and do a comma because I'm going to add something else and let's try G data for Zenergy data now this can get big but though we'll try it anyways and you see there's a dev master the reason I don't want to do dev masters because it could be changing so I'm going to pick a version that's already stable and not going to change so I'll copy this and I'll paste it in here okay so this should get two items and let's go ahead and run it so here's my file I'll just ctrl C to cancel out and list all I have to do is say composer install and since I have a composer JSON file it's just going to do whatever is in there so let's take a moment and watch it do its magic so let's say you had to pass a project along to somebody it'd be great just fantastic to be able to install the exact same packages without digging around downloading a bunch of things I know you have get but this is a very nice we use this for Python and it's really a lifesaver okay so it's done there I'll list the file directories out and I'm just going to type Explorer period I guess this get console doesn't like me very much I'll just open Windows Explorer workspace and we made one called my app and we just have some our composer files and all that so inside of vendors where it put the code okay so we have programmer which is the XP SPL library all this stuff I go back and I go to Zen I have G data boom it's all there ridiculously easy to use and this autoload guy right here let me open this up this is generated by composer and this in my opinion when I first saw it it looks a little crazy like what is this it looks like a I don't know a sha-1 182 183 in length not exactly sure what it is besides that this is just something you leave there so that's how you could get started with composer and inside your my app you could just make a new file and playground PHP and you can require any of these vendors that are needed they pass it along to a friend you say just run composer install and it will install whatever's in here and you're good to go hope that helps guys thanks for watching

22 thoughts on “PHP Composer Quickstart

  1. You should enable php_openssl extension (if it is not already enabled, but it should be by default) through WAMP configurator interface – not manually – and then you should not take care about which php.ini is used (WAMP would configure the correct one).

  2. I know it's very old video but can u help with this error "Could not open input file: composer.phar", I type composer in command prompt and I got this error. Help me please!

  3. $ composer update
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
    The "http://packagist.org/p/symfony/event-dispatcher%24b691b3c505c584f0929db40cbf5e81e2440d1e5f9bffe8b940932769cf66edc0.json" file could not be downloaded: failed to open stream: HTTP request failed!
    http://packagist.org could not be fully loaded, package information was loaded from the local cache and may be out of date

    SOMEBODY PLS HELP ME HELP ME I try running that command in my git bash

  4. looks kinda complicated! isn't it easier to just download a zip file with all the files and FTP them to your server ?

  5. I came here because I wanted to get html2pdf installed. Apparently it uses composer, but I don't really see the point of composer. Why can't I just download html2pdf and include it. Why do I need all the extra stress of installing composer and messing around with all this command line stuff. It seems a total waste of time. Your tutorial is good by the way, but I just don't understand the point of composer?

  6. im getting below error while installing composer
    Some settings on your machine may cause stability issues with Composer.
    If you encounter issues, try to change the following:

    The OpenSSL library (0.9.8y) used by PHP does not support TLSv1.2 or TLSv1.1.
    If possible you should upgrade OpenSSL to version 1.0.1 or above.

    please help me how to upgrade OpenSSL, im new to this kind of error.

Leave a Reply

Your email address will not be published. Required fields are marked *