2017 © Pedro Peláez

magento2-module sample_mage2_module

Magento 2 sample module.



Magento 2 sample module.

  • Thursday, February 2, 2017
  • by flancer32
  • Repository
  • 3 Watchers
  • 3 Stars
  • 70 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown


Sample module for Magento 2

Stub for Magento 2 module with development environment., (*1)

Build Status, (*2)

Environment is deployed using PHP Composer (sources are downloaded from Magento repo), contains simple tests units and CI descriptor to run these tests on Travis-CI., (*3)


Create local configuration

$ cp deploy.cfg.sh.init deploy.cfg.work.sh
$ nano deploy.cfg.work.sh    //edit configuration for deployment

Get credentials to authenticate on 'repo.magento.com'

Go to your Magento Connect account, section (_My Account / Connect / Developer / Secure Keys_) and generate pair of keys to connect to Magento 2 repository., (*4)

Setup environment

System requirements, (*5)

Run deployment script

$ sh deploy.sh

Clean up application's root folder (/.../sample_mage2_module/work)...

Create M2 CE project in '/.../sample_mage2_module/work' using 'composer install'...
    Authentication required (repo.magento.com):    // NOTE: on the first iteration only if you will save credentials.
      Username: <Magento pub key>
      Password: <Magento priv key>
Filter original    // NOTE: unset unnecessary nodes and merge Magento's "composer.json" with your own options.
        '/.../sample_DB_NAME_module/work/composer.json' on
        '/.../sample_DB_NAME_module/deploy/composer_unset.json' set and populate with additional options from
Update M2 CE project with additional options...
Drop M2 database DB_NAME...
Database "DB_NAME" dropped

(Re)install Magento using database 'DB_NAME' (connecting as 'USER_NAME').
Create working folders before permissions will be set.

Switch Magento 2 instance into 'developer' mode.
Enabled developer mode.

Set file system ownership (OWNER:GROUP) and permissions...

Deployment is done.
Go to http://.../ to check your Magento 2 instance.


$ cd work/vendor
$ php ./bin/phpunit -c flancer32/sample_mage2_module/test/unit/phpunit.dist.xml
$ php ./bin/phpunit -c flancer32/sample_mage2_module/test/functional/phpunit.dist.xml

Travis CI

Last log., (*6)


Install Composer

This is allowed for PHP 5.6:, (*7)

$ sudo apt-get install composer

Use this method for PHP 7:, (*8)

$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer

Required PHP exts

You can see error message like this, (*9)

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for magento/product-community-edition 2.0.2 -> satisfiable by magento/product-community-edition[2.0.2].
    - magento/product-community-edition 2.0.2 requires ext-gd * -> the requested PHP extension gd is missing from your system.

in case of not all required PHP extensions are installed., (*10)

Install PHP extensions on Ubuntu:, (*11)

$ sudo apt-get install php7.0-bcmath php7.0-curl php7.0-gd php7.0-intl php7.0-mbstring php7.0-mcrypt php7.0-mysql php7.0-xml libapache2-mod-php7.0 php7.0-zip php7.0-json php7.0-opcache


$ sudo apt-get install libapache2-mod-php7.0
$ sudo a2enmod rewrite
$ sudo service apache2 restart

Sample of the virtual host config:, (*12)

<VirtualHost *:80>
        ServerName mage2.localhost
        ServerAdmin webmaster@localhost
        DocumentRoot /.../sample_mage2_module/work
        <Directory "/.../sample_mage2_module/work/">
                AllowOverride All
                Require all granted
        LogLevel info
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

Don't forget about AllowOverride All, otherwise rewrite rules in .htaccess files will not be allowed and public resources will not be generated in the /pub/static/[frontend|adminhtml] folders., (*13)

The Versions

02/02 2017


9999999-dev https://github.com/flancer32/sample_mage2_module

Magento 2 sample module.

  Sources   Download


by Alex Gusev

08/12 2016


dev-Habr_Di_Proxy https://github.com/flancer32/sample_mage2_module

Magento 2 sample module.

  Sources   Download


by Alex Gusev

10/08 2016


dev-MOBI-386 https://github.com/flancer32/sample_mage2_module

Magento 2 sample module.

  Sources   Download


by Alex Gusev

02/12 2015

0.0.1 https://github.com/flancer32/sample_mage2_module

Magento 2 sample module.

  Sources   Download


The Requires

  • flancer32/sample_magelib_demo dev-master


by Alex Gusev