flancer32/sample_mage2_module

Magento 2 sample module.

0.0.1 2015-12-02 11:29 UTC

This package is auto-updated.

Last update: 2024-11-06 10:02:50 UTC


README

Stub for Magento 2 module with development environment.

Build Status

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.

Installation

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.

Setup environment

System requirements

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
		'/.../sample_DB_NAME_module/deploy/composer_opts.json'...
...
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.

Tests

$ 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.

Notes

Install Composer

This is allowed for PHP 5.6:

$ sudo apt-get install composer

Use this method for PHP 7:

$ 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

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.

Install PHP extensions on Ubuntu:

$ 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

Apache2

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

Sample of the virtual host config:

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

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.

Links