如何使用 composer 安装 Magento2 示例模块?

Posted

技术标签:

【中文标题】如何使用 composer 安装 Magento2 示例模块?【英文标题】:How do I install a Magento2 sample-module using composer? 【发布时间】:2016-02-09 04:39:12 【问题描述】:

我在本地机器上使用 Magento 2 EE。我已经在这个上搜索了几个小时。我想安装此处列出的示例页面模块:

https://github.com/magento/magento2-samples/tree/master/sample-module-newpage

我在页面上阅读了以下引文,而不是上传并尝试通过创建和上传文件和文件夹来硬塞里面的所有内容:

This module is intended to be installed using composer.

我对 Composer 和 Grunt 和 Github 的世界以这种方式分叉和更新文件很陌生;我是老派,但正在努力适应。

我该怎么做?我已经设法在我的机器上安装了 Composer,并且终端打开到 Magento 2 的文件夹。我可以只运行 github 命令或 Composer 命令吗?我试过了:

#localhost:magento2ee: composer magento/sample-module-newpage

  [InvalidArgumentException]                               
  Command "magento/sample-module-newpage" is not defined.  

我也试过

#localhost:magento2ee: composer require magento/sample-module-newpage



  [InvalidArgumentException]
Could not find package magento/sample-module-newpage at any version for your minimum-stability (alpha). Check the package spelling or your minimum-stability  

下面是我的 composer.json 文件


    "name": "magento/magento2ee",
    "description": "Magento 2 (Enterprise Edition)",
    "type": "magento-core",
    "version": "1.0.0-beta4",
    "license": [
        "proprietary"
    ],
    "require": 
        "php": "~5.5.0|~5.6.0",
        "zendframework/zend-stdlib": "2.4.0",
        "zendframework/zend-code": "2.4.0",
        "zendframework/zend-server": "2.4.0",
        "zendframework/zend-soap": "2.4.0",
        "zendframework/zend-uri": "2.4.0",
        "zendframework/zend-validator": "2.4.0",
        "zendframework/zend-console": "2.4.0",
        "zendframework/zend-modulemanager": "2.4.0",
        "zendframework/zend-mvc": "2.4.0",
        "zendframework/zend-text": "2.4.0",
        "zendframework/zend-i18n": "2.4.0",
        "zendframework/zend-eventmanager": "2.4.0",
        "zendframework/zend-view": "2.4.0",
        "zendframework/zend-servicemanager": "2.4.0",
        "zendframework/zend-json": "2.4.0",
        "zendframework/zend-config": "2.4.0",
        "zendframework/zend-form": "2.4.0",
        "zendframework/zend-di": "2.4.0",
        "zendframework/zend-serializer": "2.4.0",
        "zendframework/zend-log": "2.4.0",
        "zendframework/zend-http": "2.4.0",
        "magento/zendframework1": "1.12.13",
        "composer/composer": "1.0.0-alpha10",
        "monolog/monolog": "1.11.0",
        "oyejorge/less.php": "1.7.0.3",
        "pelago/emogrifier": "0.1.1",
        "tubalmartin/cssmin": "2.4.8-p4",
        "solarium/solarium": "3.3.0",
        "magento/magento-composer-installer": "*",
        "braintree/braintree_php" : "2.39.0",
        "symfony/console": "~2.3 <2.7"
    ,
    "require-dev": 
        "lib-libxml": "*",
        "ext-ctype": "*",
        "ext-gd": "*",
        "ext-spl": "*",
        "ext-dom": "*",
        "ext-simplexml": "*",
        "ext-mcrypt": "*",
        "ext-hash": "*",
        "ext-curl": "*",
        "ext-iconv": "*",
        "ext-intl": "*",
        "ext-xsl": "*",
        "ext-mbstring": "*",
        "phpunit/phpunit": "4.1.0",
        "squizlabs/php_codesniffer": "1.5.3",
        "phpmd/phpmd": "@stable",
        "pdepend/pdepend": "2.0.6",
        "sjparkinson/static-review": "~4.1",
        "fabpot/php-cs-fixer": "~1.2",
        "lusitanian/oauth": "~0.3"
    ,
    "replace": 
        "magento/module-admin-notification": "self.version",
        "magento/module-advanced-pricing-import-export": "self.version",
        "magento/module-authorization": "self.version",
        "magento/module-authorizenet": "self.version",
        "magento/module-backend": "self.version",
        "magento/module-backup": "self.version",
        "magento/module-braintree": "self.version",
        "magento/module-worldpay": "self.version",
        "magento/module-bundle": "self.version",
        "magento/module-bundle-import-export": "self.version",
        "magento/module-cache-invalidate": "self.version",
        "magento/module-captcha": "self.version",
        "magento/module-catalog": "self.version",
        "magento/module-catalog-import-export": "self.version",
        "magento/module-catalog-inventory": "self.version",
        "magento/module-catalog-rule": "self.version",
        "magento/module-catalog-search": "self.version",
        "magento/module-catalog-url-rewrite": "self.version",
        "magento/module-catalog-widget": "self.version",
        "magento/module-checkout": "self.version",
        "magento/module-checkout-agreements": "self.version",
        "magento/module-cms": "self.version",
        "magento/module-cms-url-rewrite": "self.version",
        "magento/module-config": "self.version",
        "magento/module-configurable-import-export": "self.version",
        "magento/module-configurable-product": "self.version",
        "magento/module-contact": "self.version",
        "magento/module-cookie": "self.version",
        "magento/module-cron": "self.version",
        "magento/module-currency-symbol": "self.version",
        "magento/module-customer": "self.version",
        "magento/module-customer-import-export": "self.version",
        "magento/module-deploy": "self.version",
        "magento/module-design-editor": "self.version",
        "magento/module-developer": "self.version",
        "magento/module-dhl": "self.version",
        "magento/module-directory": "self.version",
        "magento/module-downloadable": "self.version",
        "magento/module-eav": "self.version",
        "magento/module-email": "self.version",
        "magento/module-advanced-search": "self.version",
        "magento/module-fedex": "self.version",
        "magento/module-gift-message": "self.version",
        "magento/module-google-adwords": "self.version",
        "magento/module-google-analytics": "self.version",
        "magento/module-google-optimizer": "self.version",
        "magento/module-google-shopping": "self.version",
        "magento/module-google-tag-manager": "self.version",
        "magento/module-grouped-import-export": "self.version",
        "magento/module-grouped-product": "self.version",
        "magento/module-import-export": "self.version",
        "magento/module-indexer": "self.version",
        "magento/module-integration": "self.version",
        "magento/module-layered-navigation": "self.version",
        "magento/module-log": "self.version",
        "magento/module-msrp": "self.version",
        "magento/module-media-storage": "self.version",
        "magento/module-multishipping": "self.version",
        "magento/module-newsletter": "self.version",
        "magento/module-offline-payments": "self.version",
        "magento/module-offline-shipping": "self.version",
        "magento/module-page-cache": "self.version",
        "magento/module-payment": "self.version",
        "magento/module-paypal": "self.version",
        "magento/module-persistent": "self.version",
        "magento/module-product-alert": "self.version",
        "magento/module-quote": "self.version",
        "magento/module-reports": "self.version",
        "magento/module-require-js": "self.version",
        "magento/module-review": "self.version",
        "magento/module-rss": "self.version",
        "magento/module-rule": "self.version",
        "magento/module-sales": "self.version",
        "magento/module-sales-rule": "self.version",
        "magento/module-sales-sequence": "self.version",
        "magento/module-search": "self.version",
        "magento/module-send-friend": "self.version",
        "magento/module-shipping": "self.version",
        "magento/module-sitemap": "self.version",
        "magento/module-solr": "self.version",
        "magento/module-store": "self.version",
        "magento/module-swatches": "self.version",
        "magento/module-tax": "self.version",
        "magento/module-tax-import-export": "self.version",
        "magento/module-theme": "self.version",
        "magento/module-translation": "self.version",
        "magento/module-ui": "self.version",
        "magento/module-ups": "self.version",
        "magento/module-url-rewrite": "self.version",
        "magento/module-user": "self.version",
        "magento/module-usps": "self.version",
        "magento/module-version": "self.version",
        "magento/module-webapi": "self.version",
        "magento/module-weee": "self.version",
        "magento/module-widget": "self.version",
        "magento/module-wishlist": "self.version",
        "magento/module-admin-gws": "self.version",
        "magento/module-advanced-checkout": "self.version",
        "magento/module-banner": "self.version",
        "magento/module-banner-customer-segment": "self.version",
        "magento/module-catalog-event": "self.version",
        "magento/module-catalog-permissions": "self.version",
        "magento/module-custom-attribute-management": "self.version",
        "magento/module-customer-balance": "self.version",
        "magento/module-customer-custom-attributes": "self.version",
        "magento/module-customer-finance": "self.version",
        "magento/module-customer-segment": "self.version",
        "magento/module-enterprise": "self.version",
        "magento/module-gift-card": "self.version",
        "magento/module-gift-card-account": "self.version",
        "magento/module-gift-registry": "self.version",
        "magento/module-gift-wrapping": "self.version",
        "magento/module-invitation": "self.version",
        "magento/module-logging": "self.version",
        "magento/module-multiple-wishlist": "self.version",
        "magento/module-ogone": "self.version",
        "magento/module-cybersource": "self.version",
        "magento/module-pci": "self.version",
        "magento/module-persistent-history": "self.version",
        "magento/module-price-permissions": "self.version",
        "magento/module-promotion-permissions": "self.version",
        "magento/module-reminder": "self.version",
        "magento/module-reward": "self.version",
        "magento/module-rma": "self.version",
        "magento/module-sales-archive": "self.version",
        "magento/module-advanced-catalog": "self.version",
        "magento/module-scalable-checkout": "self.version",
        "magento/module-scalable-oms": "self.version",
        "magento/module-scheduled-import-export": "self.version",
        "magento/module-target-rule": "self.version",
        "magento/module-variable": "self.version",
        "magento/module-versions-cms": "self.version",
        "magento/module-website-restriction": "self.version",
        "magento/theme-adminhtml-backend": "self.version",
        "magento/theme-frontend-blank": "self.version",
        "magento/theme-frontend-luma": "self.version",
        "magento/language-de_de": "self.version",
        "magento/language-en_us": "self.version",
        "magento/language-es_es": "self.version",
        "magento/language-fr_fr": "self.version",
        "magento/language-nl_nl": "self.version",
        "magento/language-pt_br": "self.version",
        "magento/language-zh_cn": "self.version",
        "magento/framework": "self.version",
        "trentrichardson/jquery-timepicker-addon": "1.4.3",
        "colinmollenhour/cache-backend-redis": "dev-master#193d377b7fb2e88595578b282fa01a62d1185abc",
        "colinmollenhour/credis": "dev-master#f07bbfd4117294f462f0fb19c49221d350bf396f",
        "linkorb/jsmin-php": "1.1.2",
        "phpseclib/phpseclib": "0.2.1",
        "components/jquery": "1.11.0",
        "blueimp/jquery-file-upload": "5.6.14",
        "components/jqueryui": "1.10.4",
        "twbs/bootstrap": "3.1.0",
        "tinymce/tinymce": "3.4.7"
    ,
    "extra": 
        "component_paths": 
            "trentrichardson/jquery-timepicker-addon": "lib/web/jquery/jquery-ui-timepicker-addon.js",
            "colinmollenhour/cache-backend-redis": "lib/internal/Cm/Cache/Backend/Redis.php",
            "colinmollenhour/credis": "lib/internal/Credis",
            "linkorb/jsmin-php": "lib/internal/JSMin",
            "phpseclib/phpseclib": "lib/internal/phpseclib",
            "components/jquery": [
                "lib/web/jquery.js",
                "lib/web/jquery/jquery.min.js",
                "lib/web/jquery/jquery-migrate.js",
                "lib/web/jquery/jquery-migrate.min.js"
            ],
            "blueimp/jquery-file-upload": "lib/web/jquery/fileUploader",
            "components/jqueryui": [
                "lib/web/jquery/jquery-ui.js",
                "lib/web/jquery/jquery-ui.min.js"
            ],
            "twbs/bootstrap": [
                "lib/web/jquery/jquery.tabs.js"
            ],
            "tinymce/tinymce": "lib/web/tiny_mce"
        
    ,
    "config": 
        "use-include-path": true
    ,
    "autoload": 
        "psr-4": 
            "Magento\\Framework\\": "lib/internal/Magento/Framework/",
            "Magento\\Setup\\": "setup/src/Magento/Setup/"
        
    ,
    "autoload-dev": 
        "psr-4": 
            "Magento\\Sniffs\\": "dev/tests/static/framework/Magento/Sniffs/",
            "Magento\\Tools\\": "dev/tools/Magento/Tools/",
            "Magento\\Tools\\Sanity\\": "dev/build/publication/sanity/Magento/Tools/Sanity/",
            "Magento\\TestFramework\\Inspection\\": "dev/tests/static/framework/Magento/TestFramework/Inspection/",
            "Magento\\TestFramework\\Utility\\": "dev/tests/static/framework/Magento/TestFramework/Utility/",
            "Magento\\ToolkitFramework\\": "dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/"
        
    ,
    "minimum-stability": "alpha",
    "prefer-stable": true

【问题讨论】:

你能发布你的 composer.son 吗? 我已经添加了我的 composer.json 文件,这是默认文件(没有变化) 【参考方案1】:

希望这会有所帮助。首先,您是否克隆了示例存储库?

如果是,则 cd 到您要安装并运行的示例目录:

composer install

这应该安装模块。如果要安装所有模块,请备份一个目录并运行composer install

【讨论】:

你能给我一个更一步一步的 - 我在哪里放置相同的文件和克隆文件等?感谢您到目前为止的回复 好的,我会做的,在这里解释一下。如果我错过了什么,请告诉我。 好的,我会做的,在这里解释一下。如果我错过了什么,请告诉我。第 1 步:克隆存储库。 git clone git@github.com:magento/magento2-samples.git 第 2 步:cd 到您想要的模块 cd magento2-samples/sample-module-newpage 第 3 步:使用 Composer 安装示例 composer install 我尝试了 JamesHalsall 的建议,但没有奏效。我知道 Magento 计划推出一组新模块,但不确定何时推出。如果我可以让它工作,我会更新它。【参考方案2】:

我相信你的问题是因为你试图要求一个没有稳定版本(即标记)的包。

您可以通过多种方式告诉 Composer,您很乐意安装开发稳定性包。您可以通过手动将其添加到 composer.json 中的 "require" 属性来仅允许此软件包...

"magento/sample-module-newpage": "dev-master"

或者您可以通过添加此根属性告诉 composer 允许在 composer.json 中列出的所有包中使用开发稳定性包...

"minimum-stability": "dev"

更新您的composer.json 文件后,您需要通过执行composer update magento/sample-module-newpage 来获取该包

【讨论】:

我已经尝试了所有命令。你能给我一个更蹩脚的男人的解释吗

以上是关于如何使用 composer 安装 Magento2 示例模块?的主要内容,如果未能解决你的问题,请参考以下文章

如何安装麦进斗Magento2

设置 Magento2 后如何安装示例数据?

Magento2开发教程 - 如何向数据库添加新表

docker安装Magento2

我已经在我的本地系统上安装了 Magento2,它给了我以下错误通知作为“PHP Extension xsl”。我该如何解决这个问题

Ubuntu 安装 magento2