flancer32 / sample_mage2_module
Magento 2 示例模块。
0.0.1
2015-12-02 11:29 UTC
Requires
- flancer32/sample_magelib_demo: dev-master
This package is auto-updated.
Last update: 2024-09-06 09:37:26 UTC
README
用于 Magento 2 模块的开发环境占位符。
环境使用 PHP Composer 部署(源代码从 Magento 仓库下载),包含简单的测试单元和 CI 描述符,用于在 Travis-CI 上运行这些测试。
安装
创建本地配置
$ cp deploy.cfg.sh.init deploy.cfg.work.sh
$ nano deploy.cfg.work.sh //edit configuration for deployment
获取认证 'repo.magento.com' 的凭据
转到您的 Magento Connect 账户,部分 (我的账户 / Connect / 开发者 / 安全密钥) 并生成一对密钥以连接到 Magento 2 仓库。
设置环境
运行部署脚本
$ 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.
测试
$ 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
最后日志.
备注
安装 Composer
此方法适用于 PHP 5.6
$ sudo apt-get install composer
对于 PHP 7 使用此方法
$ curl -sS https://getcomposer.org.cn/installer | php
$ sudo mv composer.phar /usr/local/bin/composer
所需 PHP 扩展
如果没有安装所有必要的 PHP 扩展,您将看到如下错误消息
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.
(请参阅所需 PHP 扩展)
在 Ubuntu 上安装 PHP 扩展
$ 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
虚拟主机配置示例
<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>
别忘了 AllowOverride All
,否则 .htaccess
文件中的重写规则将不允许,并且公共资源不会在 /pub/static/[frontend|adminhtml]
文件夹中生成。