Magento 2 Progress Towards Installation via Composer

ComposerWith the latest GitHub push, Magento 2 can now be downloaded and installed completely using Composer! (Composer is a PHP package manager similar in concept to Maven for Java developers.) This represents a nice milestone in Magento 2’s Composer support. This is by no means the end of the Composer work – more work is in progress.

This post is intended for developers who want to have a poke around and see how things are progressing. Feedback is welcome! You may also like to read up on a previous post regarding Composer talking about version numbering.

Disclaimer: The following is my own thoughts and opinions. This is not official documentation. I was just trying to sneak something out quickly so people can get a better look and provide feedback.

Installing Magento 2 via Composer

The following steps install Magento 2 Community Edition from scratch. I did the following on Windows, but it should work on Linux just as easily.

Step 1. Create a new empty directory and change into that directory.

> mkdir C:\magento2\alpha89
> cd /D C:\magento2\alpha89

Step 2. If you have not done so before, you will need to download Composer.  From a command prompt I used the following command (I had curl already installed).

> curl -sS https://getcomposer.org/installer | php
#!/usr/bin/env php
All settings correct for using Composer
Downloading...
 
Composer successfully installed to: C:\magento2\alpha89\composer.phar
Use it: php composer.phar

Step 3. Create a composer.json file with the following contents. (This might change in the future.)

{
  "name": "alankent/store",
  "require": {
    "magento/magento-composer-installer": "*",
    "magento/product-community-edition": "0.1.0-alpha89"
  },
  "repositories": [
    {
      "type": "composer",
      "url": "http://packages.magento.com/"
    }
  ],
  "extra": {
    "magento-root-dir": "htdocs",
    "magento-deploystrategy": "copy"
  },
  "minimum-stability": "dev"
}

Step 4. From a shell prompt run php composer.phar install. This will take some time to complete as it downloads approximately 100 modules (around 4 minutes on my laptop). Note it will ask you whether you want it to create the htdocs directory for you. Enter ‘y’. (The following shows the output when I ran it a second time – looks like Composer cached the downloads from the previous test run. Your output might look a little different as a result.)

> php composer.phar install
Loading composer repositories with package information
Installing dependencies (including require-dev)
 - Installing justinrainbow/json-schema (dev-master d97cf3c)
 Cloning d97cf3ce890fe80f247fc08594a1c8a1029fc7ed

 - Installing icecave/isolator (2.2.1)
 Loading from cache

 - Installing eloquent/pops (3.1.1)
 Loading from cache

 - Installing eloquent/liberator (1.1.1)
 Loading from cache

 - Installing eloquent/enumeration (5.1.0)
 Loading from cache

 - Installing eloquent/composer-config-reader (2.0.0)
 Loading from cache

 - Installing magento/magento-composer-installer (dev-master 373bc44)
 Cloning 373bc44cbe3f974b6d9f1e195e3c06f1e7fbacd3

magento root dir "htdocs" missing! create now? [Y,n] y
magento root dir "htdocs" created
 - Installing magento/framework (0.1.0-alpha89)
 Loading from cache

 - Installing magento/language-zh_cn (0.1.0-alpha89)
 Loading from cache

 - Installing magento/language-pt_br (0.1.0-alpha89)
 Loading from cache

...snip...

 - Installing magento/module-captcha (0.1.0-alpha89)
 Loading from cache

 - Installing magento/module-authorizenet (0.1.0-alpha89)
 Loading from cache

 - Installing magento/product-community-edition (0.1.0-alpha89)
 Loading from cache

icecave/isolator suggests installing eloquent/asplode (Drop-in exception-based error handling.)
magento/magento-composer-installer suggests installing theseer/autoload (~1.14)
magento/magento-composer-installer suggests installing zetacomponents/console-tools (dev-master)
magento/magento-composer-installer suggests installing colinmollenhour/modman (*)
magento/magento-composer-installer suggests installing magento-hackathon/composer-command-integrator (*)
magento/framework suggests installing ext-imagick (Use Image Magick >=3.0.0 as an optional alternative image processing library)
Writing lock file
Generating autoload files

Congratulations! You will then have the full Magento 2 community edition created for you under the htdocs directory.

If you want to see the site run, you will need to set up a MySQL database and your Apache configuration file to point to the new server as per normal. If the page looks broken, it may be your Apache server configuration is not set up correctly for rewrites – you need mod_rewrite enabled and if using Apache 2.4 remember some of the configuration settings have changed.

If you still have troubles, there is a workaround – you can pre-generate the static resource files. (These instructions may change before the final 2.0 release.) This step is normally only intended for in production mode.

> cd htdocs
> php -f dev/tools/Magento/Tools/View/deploy.php

Ignore any error messages that are output (for now).

Some Details

So what is this 0.1.0-alpha89 business for version numbers? The Composer packages have their own version numbers that are not the same as the “product” version numbers that marketing will use. “0.1.0” indicates the very early stage of life of the release and “-alpha89” indicates “here is a complete build you can experiment with like an official release, but its alpha stage”. This should help with testing upgrades (e.g. from alpha89 to alpha90 next week). Remember the Magento 2 developer beta is scheduled for the end of 2014, so using “alpha” seemed appropriate for now. The “89” reflects the GitHub code drop number that we increment each week. So what will the version number be when we release Magento 2.0 officially? TBD.

What is packages.magento.com? This is a Satis repository of the Magento 2 packages. This might change around by final release, but it gets the packages out there for now without polluting packagist.org with our weekly alpha code drops. Note that the root package listing all the modules that make up community edition is currently on packagist.org at https://packagist.org/packages/magento/product-community-edition. We are still experimenting with where best to host everything.

Conclusion

Special thanks and acknowledgements go to all who contributed to the community hackathon Composer project upon which the Magento Composer support has been built.

It is worth noting that Composer support is not replacing having a web-based guided installation process in Magento 2. The command line install will be an alternative for developers.

Also this post was not meant to be exhaustive – just help get people interested in Composer going and poking around a bit quicker. Internally we follow an iterative Agile development methodology which is about getting something working, then build upon it. So this is by no means the end of Composer related development for Magento 2 – far from it. Keep your eyes out for further developments in future GitHub pushes. All feedback and suggestions are welcome via the Magento 2 GitHub project issue tracker.

Added Aug 4: See also my next post on creating a first Magento 2 module as a Composer Package.

6 comments

  1. Quoc Vu · · Reply

    Great post Alan. I would say Composer is closer to Node npm. Phing is like Maven.

  2. Very good article, this is going to be very first tutorial about use of composer for magento2 installation.

    Thanks for sharing.

  3. Thanks for your sharing. If you want to know installation of magento 2 on server, you can read this post: http://blog.magestore.com/how-to-install-magento-2/

  4. +1.
    If you are trying to install Magento 2 on Mackbook (MEMP stack) using composer, here is another descriptive article:
    http://www.blog.magepsycho.com/magento-2-installation-on-memp-mac-os-x-nginx-mysql-php-fpm-stack/

  5. Great article!
    If you need to install Magento on VPS, check us out! We have script installer that solve this problem so you can focus on what really matters.
    https://blog.runcloud.io/how-to-install-magento

  6. Alex Morco · · Reply

    Thanks, Alan, You always help Magento developers, I have installed it via composer, Here’s the guide that helped me in it, https://www.cloudways.com/blog/install-magento-2-composer/. Hope it will help your readers as well.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.