{"id":212,"date":"2014-04-17T05:58:58","date_gmt":"2014-04-17T05:58:58","guid":{"rendered":"https:\/\/staging.heliossolutions.co\/blog\/?p=212"},"modified":"2017-10-27T14:08:48","modified_gmt":"2017-10-27T14:08:48","slug":"composer-the-dependency-manager-for-php","status":"publish","type":"post","link":"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/","title":{"rendered":"Composer : The dependency manager for PHP"},"content":{"rendered":"<h3>Introduction<\/h3>\n<p>Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you.<\/p>\n<hr \/>\n<h3>Dependency management<\/h3>\n<p>Composer deals with &#8220;packages&#8221; or libraries, but it manages them on a per-project basis, installing them in a directory (e.g. vendor) inside your project.<\/p>\n<hr \/>\n<h4>The problem that Composer solves is this:<\/h4>\n<ul class=\"bloginnercontent\">\n<li>You have a project that depends on a number of libraries.<\/li>\n<li>Some of those libraries depend on other libraries.<\/li>\n<li>You declare the things you depend on.<\/li>\n<li>Composer finds out which versions of which packages need to be installed, and installs them (meaning it downloads them into your project).<\/li>\n<\/ul>\n<hr \/>\n<h3>Declaring dependencies<\/h3>\n<p>Let&#8217;s say you are creating a project, and you need a library that does logging. You decide to use monolog. In order to add it to your project, all you need to do is create a composer.json file which describes the project&#8217;s dependencies.<\/p>\n[php]\n{<br \/>\n    &quot;require&quot;: {<br \/>\n        &quot;monolog\/monolog&quot;: &quot;1.2.*&quot;<br \/>\n    }<br \/>\n}<br \/>\n[\/php]\n<p>We are simply stating that our project requires some monolog\/monolog package, any version beginning with 1.2.<\/p>\n<hr \/>\n<h3>System Requirements<\/h3>\n<p>Composer requires PHP 5.3.2+ to run.<\/p>\n<p>Installing Composer<br \/>\nInstalling Composer is really easy as it can all be done through the command line. I\u2019m using OS X, but the following should be the same for any *nix operating system.<\/p>\n<h4>So fire up Terminal and run the following commands:<\/h4>\n[php]\n$ curl -s https:\/\/getcomposer.org\/installer | php<br \/>\n$ sudo mv composer.phar \/usr\/local\/bin\/composer<br \/>\n[\/php]\n<p>The first command downloads the composer.phar file to your computer. The second line moves the composer.phar file in to your bin so that is accessible globally on your computer.<\/p>\n<h4>Now run the following command:<\/h4>\n[php]$ composer[\/php]\n<p>If you have installed Composer successfully, you should be given a list of available commands and descriptions.<\/p>\n<hr \/>\n<h3>Using Composer<\/h3>\n<p>Now that you have Composer installed, you can use it to require some packages into your project. To make a Composer configuration file, we just need to make a JSON file in the root of the project.<br \/>\nFor example, if you wanted to use monolog package you could create the following composer.json file.<\/p>\n[php]\n{<br \/>\n  &quot;require&quot;: {<br \/>\n   &quot;monolog\/monolog&quot;: &quot;1.2.*&quot;<br \/>\n  }<br \/>\n}<br \/>\n[\/php]\n<p>To resolve and download dependencies, run the install command:<\/p>\n[php]$ php composer.phar install[\/php]\n<p>If you did a global install and do not have the phar in that directory run this instead:<\/p>\n[php]$ composer install[\/php]\n<p>Following the example above, this will download monolog into the vendor\/monolog\/monolog directory.<\/p>\n<hr \/>\n<h3>Autoloading<\/h3>\n<p>Besides downloading the library, Composer also prepares an autoload file that&#8217;s capable of autoloading all of the classes in any of the libraries that it downloads. To use it, just add the following line to your code&#8217;s bootstrap process:<\/p>\n<p>require &#8216;vendor\/autoload.php&#8217;;<\/p>\n<p>That&#8217;s it, enjoy the new gained knowledge<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project\u2026<\/p>\n","protected":false},"author":3,"featured_media":217,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[45],"class_list":["post-212","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-open-source","tag-dependency-manager-php"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Composer : The dependency manager for PHP - Helios Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Composer : The dependency manager for PHP - Helios Blog\" \/>\n<meta property=\"og:description\" content=\"Introduction Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project\u2026\" \/>\n<meta property=\"og:url\" content=\"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/\" \/>\n<meta property=\"og:site_name\" content=\"Helios Blog\" \/>\n<meta property=\"article:published_time\" content=\"2014-04-17T05:58:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-10-27T14:08:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/staging.heliossolutions.co\/blog\/wp-content\/uploads\/2014\/01\/Dependency-Management-Tool-For-PHP-Composer.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"525\" \/>\n\t<meta property=\"og:image:height\" content=\"254\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"helios\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"helios\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/\"},\"author\":{\"name\":\"helios\",\"@id\":\"https:\/\/staging.heliossolutions.co\/blog\/#\/schema\/person\/ce1ab8197db1f84358e99b203e8f6b38\"},\"headline\":\"Composer : The dependency manager for PHP\",\"datePublished\":\"2014-04-17T05:58:58+00:00\",\"dateModified\":\"2017-10-27T14:08:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/\"},\"wordCount\":489,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/staging.heliossolutions.co\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/staging.heliossolutions.co\/blog\/wp-content\/uploads\/2014\/01\/Dependency-Management-Tool-For-PHP-Composer.jpg\",\"keywords\":[\"dependency manager php\"],\"articleSection\":[\"Open Source\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/\",\"url\":\"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/\",\"name\":\"Composer : The dependency manager for PHP - Helios Blog\",\"isPartOf\":{\"@id\":\"https:\/\/staging.heliossolutions.co\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/staging.heliossolutions.co\/blog\/wp-content\/uploads\/2014\/01\/Dependency-Management-Tool-For-PHP-Composer.jpg\",\"datePublished\":\"2014-04-17T05:58:58+00:00\",\"dateModified\":\"2017-10-27T14:08:48+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/#primaryimage\",\"url\":\"https:\/\/staging.heliossolutions.co\/blog\/wp-content\/uploads\/2014\/01\/Dependency-Management-Tool-For-PHP-Composer.jpg\",\"contentUrl\":\"https:\/\/staging.heliossolutions.co\/blog\/wp-content\/uploads\/2014\/01\/Dependency-Management-Tool-For-PHP-Composer.jpg\",\"width\":525,\"height\":254},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/staging.heliossolutions.co\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Composer : The dependency manager for PHP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/staging.heliossolutions.co\/blog\/#website\",\"url\":\"https:\/\/staging.heliossolutions.co\/blog\/\",\"name\":\"Helios Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/staging.heliossolutions.co\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/staging.heliossolutions.co\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/staging.heliossolutions.co\/blog\/#organization\",\"name\":\"Helios\",\"url\":\"https:\/\/staging.heliossolutions.co\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/staging.heliossolutions.co\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/staging.heliossolutions.co\/blog\/wp-content\/uploads\/2023\/01\/Helios-blue-website.png\",\"contentUrl\":\"https:\/\/staging.heliossolutions.co\/blog\/wp-content\/uploads\/2023\/01\/Helios-blue-website.png\",\"width\":250,\"height\":47,\"caption\":\"Helios\"},\"image\":{\"@id\":\"https:\/\/staging.heliossolutions.co\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/staging.heliossolutions.co\/blog\/#\/schema\/person\/ce1ab8197db1f84358e99b203e8f6b38\",\"name\":\"helios\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/staging.heliossolutions.co\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/acb724e9e4c2d0799bde8878da07c0aa?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/acb724e9e4c2d0799bde8878da07c0aa?s=96&d=mm&r=g\",\"caption\":\"helios\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Composer : The dependency manager for PHP - Helios Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/","og_locale":"en_US","og_type":"article","og_title":"Composer : The dependency manager for PHP - Helios Blog","og_description":"Introduction Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project\u2026","og_url":"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/","og_site_name":"Helios Blog","article_published_time":"2014-04-17T05:58:58+00:00","article_modified_time":"2017-10-27T14:08:48+00:00","og_image":[{"width":525,"height":254,"url":"https:\/\/staging.heliossolutions.co\/blog\/wp-content\/uploads\/2014\/01\/Dependency-Management-Tool-For-PHP-Composer.jpg","type":"image\/jpeg"}],"author":"helios","twitter_card":"summary_large_image","twitter_misc":{"Written by":"helios","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/#article","isPartOf":{"@id":"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/"},"author":{"name":"helios","@id":"https:\/\/staging.heliossolutions.co\/blog\/#\/schema\/person\/ce1ab8197db1f84358e99b203e8f6b38"},"headline":"Composer : The dependency manager for PHP","datePublished":"2014-04-17T05:58:58+00:00","dateModified":"2017-10-27T14:08:48+00:00","mainEntityOfPage":{"@id":"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/"},"wordCount":489,"commentCount":0,"publisher":{"@id":"https:\/\/staging.heliossolutions.co\/blog\/#organization"},"image":{"@id":"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/#primaryimage"},"thumbnailUrl":"https:\/\/staging.heliossolutions.co\/blog\/wp-content\/uploads\/2014\/01\/Dependency-Management-Tool-For-PHP-Composer.jpg","keywords":["dependency manager php"],"articleSection":["Open Source"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/","url":"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/","name":"Composer : The dependency manager for PHP - Helios Blog","isPartOf":{"@id":"https:\/\/staging.heliossolutions.co\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/#primaryimage"},"image":{"@id":"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/#primaryimage"},"thumbnailUrl":"https:\/\/staging.heliossolutions.co\/blog\/wp-content\/uploads\/2014\/01\/Dependency-Management-Tool-For-PHP-Composer.jpg","datePublished":"2014-04-17T05:58:58+00:00","dateModified":"2017-10-27T14:08:48+00:00","breadcrumb":{"@id":"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/#primaryimage","url":"https:\/\/staging.heliossolutions.co\/blog\/wp-content\/uploads\/2014\/01\/Dependency-Management-Tool-For-PHP-Composer.jpg","contentUrl":"https:\/\/staging.heliossolutions.co\/blog\/wp-content\/uploads\/2014\/01\/Dependency-Management-Tool-For-PHP-Composer.jpg","width":525,"height":254},{"@type":"BreadcrumbList","@id":"https:\/\/staging.heliossolutions.co\/blog\/composer-the-dependency-manager-for-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/staging.heliossolutions.co\/blog\/"},{"@type":"ListItem","position":2,"name":"Composer : The dependency manager for PHP"}]},{"@type":"WebSite","@id":"https:\/\/staging.heliossolutions.co\/blog\/#website","url":"https:\/\/staging.heliossolutions.co\/blog\/","name":"Helios Blog","description":"","publisher":{"@id":"https:\/\/staging.heliossolutions.co\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/staging.heliossolutions.co\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/staging.heliossolutions.co\/blog\/#organization","name":"Helios","url":"https:\/\/staging.heliossolutions.co\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/staging.heliossolutions.co\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/staging.heliossolutions.co\/blog\/wp-content\/uploads\/2023\/01\/Helios-blue-website.png","contentUrl":"https:\/\/staging.heliossolutions.co\/blog\/wp-content\/uploads\/2023\/01\/Helios-blue-website.png","width":250,"height":47,"caption":"Helios"},"image":{"@id":"https:\/\/staging.heliossolutions.co\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/staging.heliossolutions.co\/blog\/#\/schema\/person\/ce1ab8197db1f84358e99b203e8f6b38","name":"helios","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/staging.heliossolutions.co\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/acb724e9e4c2d0799bde8878da07c0aa?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/acb724e9e4c2d0799bde8878da07c0aa?s=96&d=mm&r=g","caption":"helios"}}]}},"feat_image_thumb":"https:\/\/staging.heliossolutions.co\/blog\/wp-content\/uploads\/2014\/01\/Dependency-Management-Tool-For-PHP-Composer-525x250.jpg","mainsite_thumb":"https:\/\/staging.heliossolutions.co\/blog\/wp-content\/uploads\/2014\/01\/Dependency-Management-Tool-For-PHP-Composer-150x170.jpg","alt_text":"","_links":{"self":[{"href":"https:\/\/staging.heliossolutions.co\/blog\/wp-json\/wp\/v2\/posts\/212","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/staging.heliossolutions.co\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/staging.heliossolutions.co\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/staging.heliossolutions.co\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/staging.heliossolutions.co\/blog\/wp-json\/wp\/v2\/comments?post=212"}],"version-history":[{"count":0,"href":"https:\/\/staging.heliossolutions.co\/blog\/wp-json\/wp\/v2\/posts\/212\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/staging.heliossolutions.co\/blog\/wp-json\/wp\/v2\/media\/217"}],"wp:attachment":[{"href":"https:\/\/staging.heliossolutions.co\/blog\/wp-json\/wp\/v2\/media?parent=212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/staging.heliossolutions.co\/blog\/wp-json\/wp\/v2\/categories?post=212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/staging.heliossolutions.co\/blog\/wp-json\/wp\/v2\/tags?post=212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}