在Linux实例上搭建Magento电子商务网站(CentOS 7)

  • A+
所属分类:建站
高性能企业级服务器首台5折

Magento是一款开源电商网站框架,其丰富的模块化架构体系及拓展功能可为大中型站点提供解决方案。它使用PHP开发,支持版本范围从PHP 5.6到PHP 7.1,并使用MySQL存储数据。本文主要说明如何在阿里云ECS实例上搭建Magento电子商务网站,使用的操作系统为Linux CentOS 7.2 64位。

适用对象

适用于熟悉ECS,熟悉Linux系统,刚开始使用阿里云进行建站的用户。

资源

本文描述的操作涉及的Linux ECS实例配置包括:2 vCPU、4 GiB内存、Cent OS 7.2 64位操作系统、VPC网络、分配的公网IP地址。

说明:用于搭建Magento 2的服务器,内存不能小于2 GiB。

根据本文搭建的Magento电子商务网站,使用的软件版本信息如下:

  • MySQL 5.7
  • PHP 7.0
  • Magento 2.1

前提条件

您已经创建了一台VPC网络类型的Linux ECS实例,详细操作,请参见 创建ECS实例。配置包括:2 vCPU、4 GiB内存、Cent OS 7.2 64位操作系统、VPC网络、分配公网IP地址。

ECS实例所在安全组中已经添加了如下表所示的安全组规则。详细操作,请参见 创建ECS实例 和 添加安全组规则

服务 规则方向 授权策略 协议类型 端口范围 授权类型 授权对象 优先级
HTTP 入方向 允许 自定义TCP 80/80 地址段访问 0.0.0.0/0 1
MySQL 入方向 允许 自定义TCP 3306/3306 地址段访问 0.0.0.0/0 1

操作步骤

使用云服务器ECS搭建Magento网站的操作步骤如下:

步骤1. 安装配置LAMP平台
步骤2. 创建数据库
步骤3. 安装配置Composer
步骤4. 安装配置Magento
步骤5. 添加cron作业

步骤1. 安装配置LAMP平台

本部分内容说明如何手动安装LAMP平台。您也可以在 云市场 购买LAMP镜像直接启动ECS实例,以便快速建站

  1. 依次运行以下命令更新包和存储库,并安装Apache Web服务器和MySQL服务器。
    1. 1
      <span class="com"><span class="hljs-comment"># yum -y update</span></span>
    2. 1
      <span class="com"><span class="hljs-comment"># yum -y install httpd</span></span>
    3. 1
      <span class="com"><span class="hljs-comment"># rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm</span></span>
    4. 1
      <span class="com"><span class="hljs-comment"># yum -y install mysql-community-server</span></span>
  2. 启动HTTP和MySQL服务并设置开机自启动。
    1. 1
      <span class="com"><span class="hljs-comment"># systemctl start httpd</span></span>
    2. 1
      <span class="com"><span class="hljs-comment"># systemctl enable httpd</span></span>
    3. 1
      <span class="com"><span class="hljs-comment"># systemctl start mysqld</span></span>
    4. 1
      <span class="com"><span class="hljs-comment"># systemctl enable mysqld</span></span>
  3. 编辑Apache配置文件:
    1. 运行命令
      1
      vim /etc/httpd/conf/httpd.conf

    2. 按 
      1
      i

       键进入编辑模式。

    3. 做以下修改:
      • 在 
        1
        Include conf.modules.d/*.conf

         之后添加 

        1
        LoadModule rewrite_module modules/mod_rewrite.so

      • 将以下内容的 
        1
        AllowOverride None

         改为 

        1
        AllowOverride all

        1. 1
          <span class="typ">Options</span> <span class="typ">Indexes</span> <span class="typ">FollowSymLinks</span>
        2. 1
          <span class="com"><span class="hljs-comment">#</span></span>
        3. 1
          <span class="com"><span class="hljs-comment"># AllowOverride controls what directives may be placed in .htaccess files.</span></span>
        4. 1
          <span class="com"><span class="hljs-comment"># It can be "All", "None", or any combination of the keywords:</span></span>
        5. 1
          <span class="com"><span class="hljs-comment"># Options FileInfo AuthConfig Limit</span></span>
        6. 1
          <span class="com"><span class="hljs-comment">#</span></span>
        7. 1
          <span class="typ">AllowOverride</span> <span class="typ">None</span>
    4. 按 
      1
      Esc

       键退出编辑,并输入 

      1
      :wq

       保存并退出。

  4. 查看/var/log/mysqld.log文件,获取安装MySQL时自动设置的root用户密码。
    1. 1
      <span class="com"><span class="hljs-comment"># grep 'temporary password' /var/log/mysqld.log</span></span>
    2. 1
      <span class="lit">2016</span><span class="pun">-</span><span class="lit">12</span><span class="pun">-</span><span class="lit">13T14</span><span class="pun">:</span><span class="lit">57</span><span class="pun">:</span><span class="lit">47.535748Z</span> <span class="lit">1</span> <span class="pun">[</span><span class="typ">Note</span><span class="pun">]</span><span class="pln"> A temporary password is generated </span><span class="kwd"><span class="hljs-keyword">for</span></span><span class="pln"> root@localhost</span><span class="pun">:</span><span class="pln"> p0</span><span class="pun">/</span><span class="pln">G28g</span><span class="pun">&gt;</span><span class="pln">lsHD</span>
  5. 运行下面的命令可以从如下4个方面提高MySQL的安全性:
    • 设置root账号密码
    • 禁止root账号远程登录
    • 删除匿名用户账号
    • 删除test库以及对test库的访问权限
      详细说明可参见 官方文档

      1. 1
        <span class="com"><span class="hljs-comment"># mysql_secure_installation</span></span>
      2. 1
        <span class="typ">Securing</span><span class="pln"> the </span><span class="typ">MySQL</span><span class="pln"> server deployment</span><span class="pun">.</span>
      3. 1
        <span class="typ">Enter</span><span class="pln"> password </span><span class="kwd"><span class="hljs-keyword">for</span></span><span class="pln"> user root</span><span class="pun">:</span> <span class="com"><span class="hljs-comment">#输入第4步中获取的root用户密码</span></span>
      4. 1
        <span class="typ">The</span> <span class="str"><span class="hljs-string">'validate_password'</span></span><span class="pln"> plugin is installed on the server</span><span class="pun">.</span>
      5. 1
        <span class="typ">The</span><span class="pln"> subsequent steps will run with the existing configuration of the plugin</span><span class="pun">.</span>
      6. 1
        <span class="typ">Using</span><span class="pln"> existing password </span><span class="kwd"><span class="hljs-keyword">for</span></span><span class="pln"> root</span><span class="pun">.</span>
      7. 1
        <span class="typ">Estimated</span><span class="pln"> strength of the password</span><span class="pun">:</span> <span class="lit">100</span>
      8. 1
        <span class="typ">Change</span><span class="pln"> the password </span><span class="kwd"><span class="hljs-keyword">for</span></span><span class="pln"> root </span><span class="pun">?</span> <span class="pun">((</span><span class="typ">Press</span><span class="pln"> y</span><span class="pun">|</span><span class="pln">Y </span><span class="kwd"><span class="hljs-keyword">for</span></span> <span class="typ">Yes</span><span class="pun">,</span><span class="pln"> any other key </span><span class="kwd"><span class="hljs-keyword">for</span></span> <span class="typ">No</span><span class="pun">)</span> <span class="pun">:</span><span class="pln"> Y </span><span class="com"><span class="hljs-comment">#是否更改root用户密码,输入Y</span></span>
      9. 1
        <span class="typ">New</span><span class="pln"> password</span><span class="pun">:</span> <span class="com"><span class="hljs-comment">#输入密码</span></span>
      10. 1
        <span class="typ">Re</span><span class="pun">-</span><span class="pln">enter new password</span><span class="pun">:</span> <span class="com"><span class="hljs-comment">#再次输入密码</span></span>
      11. 1
        <span class="typ">Estimated</span><span class="pln"> strength of the password</span><span class="pun">:</span> <span class="lit">100</span>
      12. 1
        <span class="typ">Do</span><span class="pln"> you wish to </span><span class="kwd"><span class="hljs-built_in">continue</span></span><span class="pln"> with the password provided</span><span class="pun">?(</span><span class="typ">Press</span><span class="pln"> y</span><span class="pun">|</span><span class="pln">Y </span><span class="kwd"><span class="hljs-keyword">for</span></span> <span class="typ">Yes</span><span class="pun">,</span><span class="pln"> any other key </span><span class="kwd"><span class="hljs-keyword">for</span></span> <span class="typ">No</span><span class="pun">)</span> <span class="pun">:</span><span class="pln"> Y</span>
      13. 1
        <span class="typ">By</span><span class="pln"> default</span><span class="pun">,</span><span class="pln"> a </span><span class="typ">MySQL</span><span class="pln"> installation has an anonymous user</span><span class="pun">,</span><span class="pln"> allowing anyone to <span class="hljs-built_in">log</span> into </span><span class="typ">MySQL</span><span class="pln"> without having to have a user account created </span><span class="kwd"><span class="hljs-keyword">for</span></span><span class="pln"> them</span><span class="pun">.</span> <span class="typ">This</span><span class="pln"> is intended only </span><span class="kwd"><span class="hljs-keyword">for</span></span><span class="pln"> testing</span><span class="pun">,</span><span class="pln"> and to make the installation go a bit smoother</span><span class="pun">.</span> <span class="typ">You</span><span class="pln"> should remove them before moving into a production environment</span><span class="pun">.</span>
      14. 1
        <span class="typ">Remove</span><span class="pln"> anonymous users</span><span class="pun">?</span> <span class="pun">(</span><span class="typ">Press</span><span class="pln"> y</span><span class="pun">|</span><span class="pln">Y </span><span class="kwd"><span class="hljs-keyword">for</span></span> <span class="typ">Yes</span><span class="pun">,</span><span class="pln"> any other key </span><span class="kwd"><span class="hljs-keyword">for</span></span> <span class="typ">No</span><span class="pun">)</span> <span class="pun">:</span><span class="pln"> Y </span><span class="com"><span class="hljs-comment">#是否删除匿名用户,输入Y</span></span>
      15. 1
        <span class="typ">Success</span><span class="pun">.</span>
      16. 1
        <span class="typ">Normally</span><span class="pun">,</span><span class="pln"> root should only be allowed to connect from </span><span class="str"><span class="hljs-string">'localhost'</span></span><span class="pun">.</span>
      17. 1
        <span class="typ">This</span><span class="pln"> ensures that someone cannot guess at the root password from the network</span><span class="pun">.</span>
      18. 1
        <span class="typ">Disallow</span><span class="pln"> root login remotely</span><span class="pun">?</span> <span class="pun">(</span><span class="typ">Press</span><span class="pln"> y</span><span class="pun">|</span><span class="pln">Y </span><span class="kwd"><span class="hljs-keyword">for</span></span> <span class="typ">Yes</span><span class="pun">,</span><span class="pln"> any other key </span><span class="kwd"><span class="hljs-keyword">for</span></span> <span class="typ">No</span><span class="pun">)</span> <span class="pun">:</span><span class="pln"> Y </span><span class="com"><span class="hljs-comment">#禁止root远程登录,输入Y</span></span>
      19. 1
        <span class="typ">Success</span><span class="pun">.</span>
      20. 1
        <span class="typ">By</span><span class="pln"> default</span><span class="pun">,</span> <span class="typ">MySQL</span><span class="pln"> comes with a database named </span><span class="str"><span class="hljs-string">'test'</span></span><span class="pln"> that anyone can access</span><span class="pun">.</span>
      21. 1
        <span class="typ">This</span><span class="pln"> is also intended only </span><span class="kwd"><span class="hljs-keyword">for</span></span><span class="pln"> testing</span><span class="pun">,</span><span class="pln"> and should be removed before moving into a production</span>
      22. 1
        <span class="pln">environment</span><span class="pun">.</span>
      23. 1
        <span class="typ">Remove</span><span class="pln"> <span class="hljs-built_in">test</span> database and access to it</span><span class="pun">?</span> <span class="pun">(</span><span class="typ">Press</span><span class="pln"> y</span><span class="pun">|</span><span class="pln">Y </span><span class="kwd"><span class="hljs-keyword">for</span></span> <span class="typ">Yes</span><span class="pun">,</span><span class="pln"> any other key </span><span class="kwd"><span class="hljs-keyword">for</span></span> <span class="typ">No</span><span class="pun">)</span> <span class="pun">:</span><span class="pln"> Y </span><span class="com"><span class="hljs-comment">#是否删除test库和对它的访问权限,输入Y</span></span>
      24. 1
        <span class="pun">-</span> <span class="typ">Dropping</span><span class="pln"> <span class="hljs-built_in">test</span> database</span><span class="pun">...</span>
      25. 1
        <span class="typ">Success</span><span class="pun">.</span>
      26. 1
        <span class="pun">-</span> <span class="typ">Removing</span><span class="pln"> privileges on <span class="hljs-built_in">test</span> database</span><span class="pun">...</span>
      27. 1
        <span class="typ">Success</span><span class="pun">.</span>
      28. 1
        <span class="typ">Reloading</span><span class="pln"> the privilege tables will ensure that all changes</span>
      29. 1
        <span class="pln">made so far will take effect immediately</span><span class="pun">.</span>
      30. 1
        <span class="typ">Reload</span><span class="pln"> privilege tables now</span><span class="pun">?</span> <span class="pun">(</span><span class="typ">Press</span><span class="pln"> y</span><span class="pun">|</span><span class="pln">Y </span><span class="kwd"><span class="hljs-keyword">for</span></span> <span class="typ">Yes</span><span class="pun">,</span><span class="pln"> any other key </span><span class="kwd"><span class="hljs-keyword">for</span></span> <span class="typ">No</span><span class="pun">)</span> <span class="pun">:</span><span class="pln"> Y </span><span class="com"><span class="hljs-comment">#是否重新加载授权表,输入Y</span></span>
      31. 1
        <span class="typ">Success</span><span class="pun">.</span>
      32. 1
        <span class="typ">All</span> <span class="kwd"><span class="hljs-keyword">done</span></span><span class="pun">!</span>
  6. 依次运行以下命令,安装PHP 7和一些所需的额外PHP扩展。
    1. 1
      <span class="com"><span class="hljs-comment"># yum install -y http://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/ius-release-1.0-14.ius.centos7.noarch.rpm</span></span>
    2. 1
      <span class="com"><span class="hljs-comment"># yum -y update</span></span>
    3. 1
      <span class="com"><span class="hljs-comment"># yum -y install php70u php70u-pdo php70u-mysqlnd php70u-opcache php70u-xml php70u-gd php70u-mcrypt php70u-devel php70u-intl php70u-mbstring php70u-bcmath php70u-json php70u-iconv</span></span>
  7. 查看PHP版本,以验证PHP是否已经成功安装。
    1. 1
      <span class="com"><span class="hljs-comment"># php -v</span></span>
    2. 1
      <span class="pln">PHP </span><span class="lit">7.0</span><span class="pun">.</span><span class="lit">13</span> <span class="pun">(</span><span class="pln">cli</span><span class="pun">)</span> <span class="pun">(</span><span class="pln">built</span><span class="pun">:</span> <span class="typ">Nov</span> <span class="lit">10</span> <span class="lit">2016</span> <span class="lit">08</span><span class="pun">:</span><span class="lit">44</span><span class="pun">:</span><span class="lit">18</span><span class="pun">)</span> <span class="pun">(</span><span class="pln"> NTS </span><span class="pun">)</span>
    3. 1
      <span class="typ">Copyright</span> <span class="pun">(</span><span class="pln">c</span><span class="pun">)</span> <span class="lit">1997</span><span class="pun">-</span><span class="lit">2016</span> <span class="typ">The</span><span class="pln"> PHP </span><span class="typ">Group</span>
    4. 1
      <span class="typ">Zend</span> <span class="typ">Engine</span><span class="pln"> v3</span><span class="pun">.</span><span class="lit">0.0</span><span class="pun">,</span> <span class="typ">Copyright</span> <span class="pun">(</span><span class="pln">c</span><span class="pun">)</span> <span class="lit">1998</span><span class="pun">-</span><span class="lit">2016</span> <span class="typ">Zend</span> <span class="typ">Technologies</span>
    5. 1
      <span class="pln"> with </span><span class="typ">Zend</span> <span class="typ">OPcache</span><span class="pln"> v7</span><span class="pun">.</span><span class="lit">0.13</span><span class="pun">,</span> <span class="typ">Copyright</span> <span class="pun">(</span><span class="pln">c</span><span class="pun">)</span> <span class="lit">1999</span><span class="pun">-</span><span class="lit">2016</span><span class="pun">,</span><span class="pln"> by </span><span class="typ">Zend</span> <span class="typ">Technologies</span>
  8. 编辑配置文件/etc/php.ini:
    1. 运行命令 
      1
      vim /etc/php.ini

    2. 按 
      1
      i

       进入编辑模式。

    3. 在文件最后添加以下配置:
      1. 1
        <span class="pln">memory_limit </span><span class="pun">=</span> <span class="lit">128M</span> <span class="com"><span class="hljs-comment">#根据实际情况增加内存限制</span></span>
      2. 1
        <span class="pln">date</span><span class="pun">.</span><span class="pln">timezone </span><span class="pun">=</span> <span class="typ">Asia</span><span class="pun">/</span><span class="typ">Shanghai</span> <span class="com"><span class="hljs-comment">#设置时区为上海。</span></span>
  9. 重启Web服务进程。
    1. 1
      <span class="com"><span class="hljs-comment"># systemctl restart httpd</span></span>

步骤2. 创建数据库

按以下步骤创建数据库。

  1. 创建数据库及用户:为Magento数据创建一个数据库和一个数据库用户,数据库和用户名可根据实际情况修改。
    1. 1
      <span class="com"><span class="hljs-comment"># mysql -u root -p</span></span>
    2. 1
      <span class="typ">Enter</span><span class="pln"> password</span><span class="pun">:</span>
    3. 1
      <span class="pln">mysql</span><span class="pun">&gt;</span><span class="pln"> CREATE DATABASE magento</span><span class="pun">;</span> <span class="com"><span class="hljs-comment">#根据实例情况替换magento</span></span>
    4. 1
      <span class="typ">Query</span><span class="pln"> OK</span><span class="pun">,</span> <span class="lit">1</span><span class="pln"> row affected </span><span class="pun">(</span><span class="lit">0.00</span><span class="pln"> sec</span><span class="pun">)</span>
    5. 1
      <span class="pln">mysql</span><span class="pun">&gt;</span><span class="pln"> GRANT ALL ON magento</span><span class="pun">.*</span><span class="pln"> TO </span><span class="typ">YourUser@localhost</span><span class="pln"> IDENTIFIED BY </span><span class="str"><span class="hljs-string">'YourPass'</span></span><span class="pun">;</span> <span class="com"><span class="hljs-comment">#根据实际情况替换YourUser和YourPass</span></span>
    6. 1
      <span class="typ">Query</span><span class="pln"> OK</span><span class="pun">,</span> <span class="lit">0</span><span class="pln"> rows affected</span><span class="pun">,</span> <span class="lit">1</span><span class="pln"> warning </span><span class="pun">(</span><span class="lit">0.00</span><span class="pln"> sec</span><span class="pun">)</span>
    7. 1
      <span class="pln">mysql</span><span class="pun">&gt;</span><span class="pln"> FLUSH PRIVILEGES</span><span class="pun">;</span>
    8. 1
      <span class="typ">Query</span><span class="pln"> OK</span><span class="pun">,</span> <span class="lit">0</span><span class="pln"> rows affected </span><span class="pun">(</span><span class="lit">0.00</span><span class="pln"> sec</span><span class="pun">)</span>
  2. 运行 
    1
    exit

     退出MySQL。

  3. (可选)验证新建的Magento数据库和用户是否可用。
    1. 1
      <span class="com"><span class="hljs-comment"># mysql -u YourUser -p</span></span>
    2. 1
      <span class="pln">mysql</span><span class="pun">&gt;</span><span class="pln"> show databases</span><span class="pun">;</span>
    3. 1
      <span class="pun">+--------------------+</span>
    4. 1
      <span class="pun">|</span> <span class="typ">Database</span>           <span class="pun">|</span>
    5. 1
      <span class="pun">+--------------------+</span>
    6. 1
      <span class="pun">|</span><span class="pln"> information_schema </span><span class="pun">|</span>
    7. 1
      <span class="pun">|</span><span class="pln"> magento            </span><span class="pun">|</span>
    8. 1
      <span class="pun">+--------------------+</span>
    9. 1
      <span class="lit">2</span><span class="pln"> rows </span><span class="kwd"><span class="hljs-keyword">in</span></span> <span class="kwd"><span class="hljs-built_in">set</span></span> <span class="pun">(</span><span class="lit">0.00</span><span class="pln"> sec</span><span class="pun">)</span>
    10. 1
      <span class="pln">mysql</span><span class="pun">&gt;</span><span class="pln"> <span class="hljs-built_in">exit</span></span>

步骤3. 安装配置Composer

Composer是PHP一个包管理和包依赖管理的工具。按以下步骤安装配置Composer。

  1. 安装Composer。
    1. 1
      <span class="com"><span class="hljs-comment"># curl -sS https://getcomposer.org/installer | php</span></span>
    2. 1
      <span class="typ">All</span><span class="pln"> settings correct </span><span class="kwd"><span class="hljs-keyword">for</span></span><span class="pln"> using </span><span class="typ">Composer</span>
    3. 1
      <span class="typ">Downloading</span> <span class="lit">1.2</span><span class="pun">.</span><span class="lit">4.</span><span class="pun">..</span>
    4. 1
      <span class="typ">Composer</span><span class="pln"> successfully installed to</span><span class="pun">:</span> <span class="pun">/</span><span class="pln">root</span><span class="pun">/</span><span class="pln">composer</span><span class="pun">.</span><span class="pln">phar</span>
    5. 1
      <span class="typ">Use</span><span class="pln"> it</span><span class="pun">:</span><span class="pln"> php composer</span><span class="pun">.</span><span class="pln">phar</span>
  2. 配置Composer全局使用。
    1. 1
      <span class="com"><span class="hljs-comment"># mv /root/composer.phar /usr/bin/composer</span></span>
  3. 测试命令是否可用。
    1. 1
      <span class="com"><span class="hljs-comment"># composer -v</span></span>
    2. 1
      <span class="pln">______</span>
    3. 1
      <span class="pun">/</span><span class="pln"> ____</span><span class="pun">/</span><span class="pln">___  ____ ___  ____  ____  ________  _____</span>
    4. 1
      <span class="pun">/</span> <span class="pun">/</span>   <span class="pun">/</span><span class="pln"> __ \/ __ </span><span class="str">`__ \/ __ \/ __ \/ ___/ _ \/ ___/</span>
    5. 1
      <span class="str">/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /</span>
    6. 1
      <span class="str">\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/</span>
    7. 1
      <span class="str">                 /_/</span>
    8. 1
      <span class="str">Composer version 1.2.4 2016-12-06 22:00:51</span>

步骤4. 安装配置Magento

您可以使用不同的方法安装Magento,也可以选择是否安装示例数据。如果安装Magento仅用于测试,您可以选择安装示例数据。如果是在生产环境中安装Magento,建议您安装全新的Magento,从头开始配置。

本部分介绍如何使用git下载Magento,然后使用Composer安装Magento。

  1. 依次运行以下命令,通过 
    1
    git clone

     下载Magento。

    1. 1
      <span class="com"><span class="hljs-comment"># yum -y install git</span></span>
    2. 1
      <span class="com"><span class="hljs-comment"># cd /var/www/html/</span></span>
    3. 1
      <span class="com"><span class="hljs-comment"># git clone https://github.com/magento/magento2.git</span></span>
  2. (可选)将Magento切换到稳定版本。
    默认情况git下载安装Magento是一个最新的开发版本。如果您在生产环境中使用,建议切换到稳定版本,否则未来将无法升级安装。

    1. 1
      <span class="com"><span class="hljs-comment"># cd magento2 &amp;&amp;  git checkout tags/2.1.0 -b 2.1.0</span></span>
    2. 1
      <span class="typ">Switched</span><span class="pln"> to a new branch </span><span class="str"><span class="hljs-string">'2.1.0'</span></span>
  3. 将安装文件移到Web服务器根目录下。否则,您只能通过 
    1
    http://[ECS实例公网IP地址]/magento2

     访问您的Magento站点。

    1. 1
      <span class="com"><span class="hljs-comment"># shopt -s dotglob nullglob &amp;&amp; mv /var/www/html/magento2/* /var/www/html/ &amp;&amp; cd ..</span></span>
  4. 设置Magento文件适当的权限。
    1. 1
      <span class="com"><span class="hljs-comment"># chown -R :apache /var/www/html</span></span>
    2. 1
      <span class="com"><span class="hljs-comment"># find /var/www/html -type f -print0 | xargs -r0 chmod 640</span></span>
    3. 1
      <span class="com"><span class="hljs-comment"># find /var/www/html -type d -print0 | xargs -r0 chmod 750</span></span>
    4. 1
      <span class="com"><span class="hljs-comment"># chmod -R g+w /var/www/html/{pub,var}</span></span>
    5. 1
      <span class="com"><span class="hljs-comment"># chmod -R g+w /var/www/html/{app/etc,vendor}</span></span>
    6. 1
      <span class="com"><span class="hljs-comment"># chmod 750 /var/www/html/bin/magento</span></span>
  5. 运行 
    1
    composer install

     安装Magento。

  6. 测试:在浏览器中访问 
    1
    http://[ECS实例公网IP地址]

    ,如果出现以下页面,说明Magento安装成功。
    Magento安装成功

  7. 单击 Agree and Setup Magento 开始配置Magento:按实际情况填写连接数据库信息、Web访问设置、定制商店、创建管理员账号。出现如下图所示的界面时,说明Magento配置完成。
    Magento配置完成

步骤5. 添加cron作业

  1. 运行 
    1
    crontab -u apache -e

     设置cron运行调度工作。

  2. 添加以下内容。
    1. 1
      <span class="pun">*/</span><span class="lit">10</span> <span class="pun">*</span> <span class="pun">*</span> <span class="pun">*</span> <span class="pun">*</span><span class="pln"> php </span><span class="pun">-</span><span class="pln">c </span><span class="pun">/</span><span class="pln">etc </span><span class="pun">/</span><span class="pln">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">magento cron</span><span class="pun">:</span><span class="pln">run</span>
    2. 1
      <span class="pun">*/</span><span class="lit">10</span> <span class="pun">*</span> <span class="pun">*</span> <span class="pun">*</span> <span class="pun">*</span><span class="pln"> php </span><span class="pun">-</span><span class="pln">c </span><span class="pun">/</span><span class="pln">etc </span><span class="pun">/</span><span class="pln">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="pln">update</span><span class="pun">/</span><span class="pln">cron</span><span class="pun">.</span><span class="pln">php</span>
    3. 1
      <span class="pun">*/</span><span class="lit">10</span> <span class="pun">*</span> <span class="pun">*</span> <span class="pun">*</span> <span class="pun">*</span><span class="pln"> php </span><span class="pun">-</span><span class="pln">c </span><span class="pun">/</span><span class="pln">etc </span><span class="pun">/</span><span class="pln">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">magento setup</span><span class="pun">:</span><span class="pln">cron</span><span class="pun">:</span><span class="pln">run</span>

关于Magento上使用cron作业,请参见 Magento官方文档

后续操作

访问 

1
http://[ECS实例公网IP]

 可以看到如下图所示的默认主页。
Magento_首页

访问 

1
http://[ECS实例公网IP]/admin

,使用您在安装过程中设置的用户名和密码,成功登录管理面板后可看到如下界面。
Magento_管理面板

更多Magento配置信息,请参见 Magento官方文档

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: