The document discusses using Composer and modules to better organize Magento projects. It recommends:
- Using Composer to install Magento core and modules separately from the project codebase.
- Treating modules as independent, reusable components with their own versioning and maintenance.
- Allowing multiple teams to collaborate on developing the same module for different projects.
- Managing module versions and dependencies flexibly between projects through Composer.
2. HOW DO WE USUALLY START THE PROJECT
• Getting core
• Installing few already existing modules
• Developing few customizations
3
4
3. HOW DO WE MAINTAIN THE PROJECT
• Lots of useful/useless modules installed and
their list is smth difficult to get right away
• Development has introduced multiple
dependencies
• Development has over-customised a bunch of
general purpose modules
• Thanks god core is untouched
5
6
4. THOUGH IN SOME TIME…
7
• It is faster and easier to implement a feature issuing
dependencies on other modules
WHY PROJECT LOSE FIT
• Or vice versa - some module in the project becomes kind
of “customization” module storing everything
• Original purpose and integrity of each separate module is
not tracked by anyone
• The same module in the other project is being developed
in parallel instead of getting benefit from already created
code
8
5. SOLUTION: LETS WATCH THE MODULES
9
CONCEPTS
• Project and modules relation should not be hardcoded
• This relation should be many to many and remain flexible
• Module “purity” and maintenance (at least of main line)
should be delegated to “module maintainer”
• Module development by different teams should be done
together even though being conducted in different projects
• Module versions should be clear and all ready-to-use
10
6. TOOLS
• Composer
(https://getcomposer.org/)
• Magento-composer-installer
(https://github.com/magento-hackathon/magento-composer-installer)
• Whatever VCS
and
11
STEPS
1) Install Composer
Check the link to Github for code of all the steps (in final slides)
2) Ensure Magento-composer-installer is required
3) Create your project’s initial composer.json file
4) Install Magento files via Composer
5) Create Magento DB, user and grant permissions
6) Ensure corresponding Magento folders are writable
7) Finalise magento installation: install.php from CLI or web
12
7. 1. COMPOSER
$ mkdir bin
$ curl -s https://getcomposer.org/installer | php -- --install-dir=bin
In the project root issue:
Create empty project root folder.
13
2. MAGENTO-COMPOSER-INSTALLER
…
"require": {
…
"magento-hackathon/magento-composer-installer": "*"
},
"repositories": [
{
"type": "composer",
"url": "http://packages.firegento.com"
}
],
…
Add to composer.json if your project already uses composer
14
8. 2. MAGENTO-COMPOSER-INSTALLER (2)
…
"require": {
"magento/core": "1.9.0.1"
},
"repositories": [
{
"type": "composer",
"url": "http://packages.firegento.com"
}
],
…
Or simply require Magento core installation in composer.json
if you’re starting from scratch
(Note, full version on composer.json file is shown in next step)
15
3. COMPOSER.JSON
{
"authors": [
{
"name": "Alec Bedzir",
"email": "alec.bedzir@vaimo.com"
}
],
"require": {
"magento/core": "1.9.0.1"
},
"repositories": [
{
"type": "composer",
"url": "http://packages.firegento.com"
}
],
"extra":{
"magento-root-dir": "htdocs/",
"magento-deploystrategy": "copy"
},
"minimum-stability": "dev"
}
The very basic version of the file which
installs magento only with no other
modules.
!
File should be named composer.json and
put into the root directory of the project
16
9. 4. INSTALLING MAGENTO VIA COMPOSER
$ php ./bin/composer.phar -n install
In the project root issue:
17
5. DB, USER AND PERMISSIONS
$ mysql -u root -p -e "
CREATE DATABASE magento_composer
CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER magento_user@127.0.0.1 IDENTIFIED BY '123456';
GRANT ALL ON magento_composer.* TO magento_user@127.0.0.1;
"
Run sql for preparing Mysql infrastructure for Magento:
18
11. EXPECTED RESULT . <project root>
|-- bin
| `-- composer.phar
|-- composer.json
|-- composer.lock
|-- htdocs
| |-- …
| |-- app
| |-- cron.php
| |-- index.php
| |-- …
| `-- var
`-- vendor
|-- autoload.php
|-- bin
|-- …
|-- magento
`-- magento-hackathon
1) Magento was deployed to ./htdocs
under the project root
2) Composer.lock file has been
generated
3) Magento installation is entirely
comlete
21
TROUBLESHOOTING
If magento/core is not put into your htdocs directory:!
!
• Check whether this is not the issue with installing outdated version: (e.g. 1.4). Be sure version is 2.0.0 and higher.
(this can be checked in composer install operation log:
…
Installing dependencies (including require-dev)
- Installing magento-hackathon/magento-composer-installer (1.4)
…!
!
• check whether you have the up-to-date version of composer!
!
• check whether cache of composer is cleaned!
!
• check whether you don't have any custom configuration in ~/.composer/config.json
(e.g. which overlaps with your per-project configuration)!
!
If Magento after installation with composer throws at you
Fatal error: Call to a member function getModelInstance() on a non-object
in /var/www/magento-composer/htdocs/app/Mage.php on line 463!
!
• simply check the user magento files belong to and ensure app/etc/ media/ and var/ are writable.
22
12. SHOW TIME!
23
SPECIFICS OF VERSIONING
• Trickiest part: project has versions but modules too
• Thus, upgrade in project doesn’t mean that modules were
upgraded too. Probably they were downgraded
• Each project environment (dev, staging, live etc.) should be
backed up by separate branch of the project repo
• Forking module for customizing it to very specific needs is
a good option
24
13. USAGE AND BENEFITS
• Modules repos are separate and module tracking is easy
• One can’t break the module’s overall purpose with his code
as this will fail other projects using this module
• Module get’s a “maintainer” or few of them which are
responsible for main line of its development
• Multiple teams working on the same module contribute to
it simultaneously
25
USAGE AND BENEFITS (2)
• Flexible module versions locking in the project
• Modules used in the project and their versions are easy to
check
26
14. DEVELOPING IDEA IN
• Push to module repo on BitBucket via hook informs Jenkins about new
changes
• Jenkins having successfully done the build of the module (with all the
checks, tests etc) updates “Vaimo packages” - our own Magento module
composer repository
• Composer (custom of Vaimo edition) upon next “composer update”
fetches the updated packages feed and uses it for updating the project
• In our internal web tool “Server portal” we track each module’s state, it’s
all available versions, projects were it is installed and in which revisions
27
LINKS AND DEMO FILES
Files executed during demo (for Magento entire installation and for cleanup):
https://github.com/alecbedzir/composer_plus_magento_devhub_2014_Jul
!
Magento-composer-installer
https://github.com/magento-hackathon/magento-composer-installer
!
Firegento - Magento Module Composer Repository
http://packages.firegento.com/
!
Composer
https://getcomposer.org/
28