Windows10使用Composer安装Magento2.2.7

1 . 使用composer下载Magento2.2.7

composer create-project --repository=https://repo.magento.com/ magento/project-community-edition magento_227 2.2.7

注意使用compose下载的时候出现提示时,输入您的Magento身份验证密钥。您的公钥是您的用户名; 您的私钥是您的密码。 这里安装没有出现,是因为我之前安装过保存了秘钥的。

下载过程如下:


D:\www\20190812magento227>composer create-project --repository=https://repo.magento.com/ magento/project-community-edition magento_227 2.2.7
Installing magento/project-community-edition (2.2.7)
  - Installing magento/project-community-edition (2.2.7): Loading from cache
Created project in magento_227
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 295 installs, 0 updates, 0 removals
  - Installing magento/magento-composer-installer (0.1.13): Loading from cache
  - Installing vertex/sdk (1.1.0): Loading from cache
  - Installing magento/zendframework1 (1.13.1): Loading from cache
  - Installing psr/container (1.0.0): Loading from cache
  - Installing container-interop/container-interop (1.2.0): Loading from cache
  ......
  ......
  ......
  - Installing zendframework/zend-escaper (2.6.0): Loading from cache
  - Installing zendframework/zend-uri (2.7.0): Loading from cache
  - Installing zendframework/zend-loader (2.6.0): Loading from cache
  
  - Installing zendframework/zend-console (2.7.0): Loading from cache
  - Installing zendframework/zend-mvc (2.7.15): Loading from cache
  - Installing zendframework/zend-math (2.7.1): Loading from cache
  - Installing zendframework/zend-crypt (2.6.0): Loading from cache
  - Installing zendframework/zend-code (3.1.0): Loading from cache
  - Installing tedivm/jshrink (v1.3.3): Loading from cache
 
friendsofphp/php-cs-fixer suggests installing php-cs-fixer/phpunit-constraint-isidenticalstring (For IsIdenticalString constraint.)
friendsofphp/php-cs-fixer suggests installing php-cs-fixer/phpunit-constraint-xmlmatchesxsd (For XmlMatchesXsd constraint.)
lusitanian/oauth suggests installing predis/predis (Allows using the Redis storage backend.)
Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
Writing lock file
Generating autoload files

D:\www\20190812magento227>

2 . 创建空的数据库名称以及建立网站的站点名称。

创建空数据库名称为: local_magento2_2_7

建立网站的站点,绑定站点域名为:http://local.magento2.com

3 . 进入网站的根目录

D:\www\20190812magento227>cd magento_227
D:\www\20190812magento227\magento_227>

4 . 使用下面的命令进行安装

php bin/magento setup:install --base-url=http://local.magento227.com --db-host=localhost --db-name=local_magento2_2_7 --db-user=root --db-password=root --backend-frontname=admin --admin-firstname=admin --admin-lastname=admin --admin-email=admin@admin.com --admin-user=admin --admin-password=admin123 --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1

安装过程如下:

D:\www\20190812magento227\magento_227> php bin/magento setup:install --base-url=http://local.magento227.com --db-host=localhost --db-name=local_magento2_2_7 --db-user=root --db-password=root --backend-frontname=admin --admin-firstname=admin --admin-lastname=admin --admin-email=admin@admin.com --admin-user=admin --admin-password=admin123 --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1
Starting Magento installation:
File permissions check...
[Progress: 1 / 513]
Required extensions check...
[Progress: 2 / 513]
Enabling Maintenance Mode...
[Progress: 3 / 513]
Installing deployment configuration...
[Progress: 4 / 513]
Installing database schema:
Schema creation/updates:
Module 'Magento_Store':
Installing schema... Upgrading schema...
[Progress: 5 / 513]
Module 'Magento_Directory':
 ......
 ......
 ......
Module 'Temando_Shipping':
[Progress: 506 / 513]
Module 'Vertex_Tax':
[Progress: 507 / 513]
[Progress: 508 / 513]
Installing admin user...
[Progress: 509 / 513]
Caches clearing:
Cache cleared successfully
[Progress: 510 / 513]
Disabling Maintenance Mode:
[Progress: 511 / 513]
Post installation file permissions check...
For security, remove write permissions from these directories: 'D:/www/20190812magento227/magento_227/app/etc'
[Progress: 512 / 513]
Write installation date...
[Progress: 513 / 513]
[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /admin
Nothing to import.

D:\www\20190812magento227\magento_227>

安装完成之后在浏览器中输入网站的站点显示如下。

表示安装成功,你看见的只是没有示例数据的网站。

5. 安装示例数据

如果您的Magento应用程序设置为生产模式,请不要安装示例数据。首先切换到默认模式。在生产模式下安装样本数据将失败。

查看安装之后当前模式命令:

php bin/magento deploy:mode:show

显示当前模式为 默认模式,不能在开发模式和生成模式下安装数据库,如果在开发模式下安装则会提示:

所以直接在默认模式下安装数据库

D:\www\20190812magento227\magento_227>php bin/magento deploy:mode:show
Current application mode: default. (Note: Environment variables may override this value.)

D:\www\20190812magento227\magento_227>

然后执行下面命令安装数据:

php bin/magento sampledata:deploy

您需要进行身份验证才能完成操作,如果之前在输入身份验证时候,保存了数据记录,那么现在就不需要输入。

数据库示例的安装过程如下:


D:\www\20190812magento227\magento_227>php bin/magento deploy:mode:show
Current application mode: default. (Note: Environment variables may override this value.)

D:\www\20190812magento227\magento_227>php bin/magento sampledata:deploy
./composer.json has been updated
Loading composer repositories with package information

    Authentication required (repo.magento.com):
      Username: 56f942d7cb2b84dc71416a14c7de96e2
      Password:
Do you want to store credentials for repo.magento.com in D:/www/20190812magento227/magento_227/var/composer_home/auth.json ? [Yn] y
Updating dependencies (including require-dev)
Package operations: 20 installs, 0 updates, 0 removals
  - Installing magento/module-catalog-sample-data (100.2.0): Downloading (100%)
  - Installing magento/module-bundle-sample-data (100.2.0): Downloading (100%)
  - Installing magento/module-customer-sample-data (100.2.0): Downloading (100%)
  - Installing magento/sample-data-media (100.2.0): Downloading (100%)
  - Installing magento/module-theme-sample-data (100.2.0): Downloading (100%)
  - Installing magento/module-cms-sample-data (100.2.0): Downloading (100%)
  - Installing magento/module-widget-sample-data (100.2.0): Downloading (100%)
  - Installing magento/module-catalog-rule-sample-data (100.2.0): Downloading (100%)
  - Installing magento/module-sales-rule-sample-data (100.2.0): Downloading (100%)
  - Installing magento/module-downloadable-sample-data (100.2.0): Downloading (100%)
  - Installing magento/module-wishlist-sample-data (100.2.0): Downloading (100%)
  - Installing magento/module-review-sample-data (100.2.0): Downloading (100%)
  - Installing magento/module-tax-sample-data (100.2.0): Downloading (100%)
  - Installing magento/module-msrp-sample-data (100.2.0): Downloading (100%)
  - Installing magento/module-product-links-sample-data (100.2.0): Downloading (100%)
  - Installing magento/module-grouped-product-sample-data (100.2.0): Downloading (100%)
  - Installing magento/module-offline-shipping-sample-data (100.2.0): Downloading (100%)
  - Installing magento/module-swatches-sample-data (100.2.0): Downloading (100%)
  - Installing magento/module-configurable-sample-data (100.2.0): Downloading (100%)
  - Installing magento/module-sales-sample-data (100.2.1): Downloading (100%)
<warning>Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.</warning>
Writing lock file
Generating autoload files

D:\www\20190812magento227\magento_227>

如果安装Magento 之后安装示例数据,则还必须运行以下命令来更新<magento_root>文件夹中的数据库和架构:

php bin/magento setup:upgrade

命令执行过程如下:

D:\www\20190812magento227\magento_227>php bin/magento setup:upgrade
Cache cleared successfully
File system cleanup:
D:/www/20190812magento227/magento_227/generated/code/Amazon
D:/www/20190812magento227/magento_227/generated/code/Composer
D:/www/20190812magento227/magento_227/generated/code/Magento
D:/www/20190812magento227/magento_227/generated/code/Symfony
D:/www/20190812magento227/magento_227/generated/code/Temando
The directory 'D:/www/20190812magento227/magento_227/generated/metadata/' doesn't exist - skipping cleanup
D:/www/20190812magento227/magento_227/pub/static/adminhtml
D:/www/20190812magento227/magento_227/pub/static/deployed_version.txt
D:/www/20190812magento227/magento_227/pub/static/frontend
D:/www/20190812magento227/magento_227/var/view_preprocessed/pub
Updating modules:
Schema creation/updates:
Module 'Magento_Store':
Module 'Magento_Directory':
Module 'Magento_Eav':
Module 'Magento_Theme':
Module 'Magento_Cms':
Module 'Magento_Customer':
Module 'Magento_AdminNotification':
Module 'Magento_Indexer':
Module 'Magento_AdvancedPricingImportExport':
Module 'Magento_Config':
Module 'Magento_Backend':
Module 'Magento_Catalog':
......
......
......
Module 'Klarna_Kp':
Module 'Magento_Version':
Module 'Magento_Swagger':
Module 'Magento_WebapiSecurity':
Module 'Magento_GroupedProductSampleData':
Module 'Magento_CatalogWidget':
Module 'Magento_WidgetSampleData':
Module 'Dotdigitalgroup_Email':
Module 'Magento_WishlistAnalytics':
Module 'Magento_WishlistSampleData':
Module 'Temando_Shipping':
Module 'Vertex_Tax':
Nothing to import.

D:\www\20190812magento227\magento_227>

这个时候,看见这个数据则代表操作完成。 
再刷新网站,如果是下面的结果,则表示示例数据安装成功。

这个时候,发现前台后台有些部分均为空白,解决办法:

找到该文件的D:\www\20190812magento227\magento_227\vendor\magento\framework\View\Element\Template\File\Validator.php

修改下面代码:

protected function isPathInDirectories($path, $directories)
    {
        if (!is_array($directories)) {
            $directories = (array)$directories;
        }
        foreach ($directories as $directory) {
            if (0 === strpos($this->fileDriver->getRealPath($path), $directory)) {
                return true;
            }
        }
        return false;
    }

将上面代码修改成下面代码

protected function isPathInDirectories($path, $directories)
    {
        if (!is_array($directories)) {
            $directories = (array)$directories;
        }
        $realPath = $this->fileDriver->getRealPath($path);
        $realPath = str_replace('\\', '/', $realPath); // extra code added
        foreach ($directories as $directory) {
            if (0 === strpos($realPath, $directory)) {
                return true;
            }
        }
        return false;
    }

然后删除var下面的缓存。

这个时候。打开后台的登录地址,显示可以登录了

打开首页地址显示如下:
http://local.magento2.com/index.php

总结: 使用composer安装,由于网络原因安装比较慢,需要耐心等待,方便升级。

Leave a Reply

您的邮箱地址不会被公开。 必填项已用 * 标注