centos 7 外贸商城 magento 2Community Edition

在CentOS 7上安装Magento 2 Community Edition

Magento是电子商务最流行的内容管理系统。它是用PHP编写的,并使用MySQL来存储它的数据。它是开源应用程序,被全球超过24万的商家使用。

在本教程中,我们将在运行CentOS 7.x的服务器上安装Magento 2 Community Edition。

要求

  • 运行CentOS 7.x的服务器。
  • 最小512MB内存,但推荐1GB或更多。
  • 根访问您的帐户。如果您以非root用户sudo su身份登录,请使用命令以root用户身份登录。

为Magento安装和配置LAMP

首先,使用以下命令更新系统中可用的软件包和存储库非常重要。

    yum -y update

更新软件包后,运行以下命令安装所需的软件包。

    yum -y install httpd
    rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
    yum -y install mysql-community-server

上述命令将在您的服务器上安装Apache Web服务器和MySQL服务器。现在启动Apache Web服务器和MySQL服务器也使它们能够使用以下命令在系统启动时自动启动。

    systemctl start httpd
    systemctl start mysqld
    systemctl enable httpd
    systemctl enable mysqld

现在mod_rewrite通过使用您最喜欢的编辑器编辑配置文件来配置Apache mod_rewrite由于Magento广泛使用重写来生成指向其静态资源的链接,因此启用该模块非常重要配置文件httpd可以在这里找到/etc/httpd/conf/httpd.conf在本教程中,我们将使用nano编辑器,但您可以使用您选择的任何编辑器。安装nano在你的服务器上运行yum -y install nano

    nano /etc/httpd/conf/httpd.conf

现在向下滚动并查找以下行。

    # LoadModule foo_module modules/mod_foo.so
    #
    Include conf.modules.d/*.conf

在这些行下面添加以下行:

    LoadModule rewrite_module modules/mod_rewrite.so

现在向下滚动以查找以下行:

     #
        # Possible values for the Options directive are "None", "All",
        # or any combination of:
        #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
        #
        # Note that "MultiViews" must be named *explicitly* --- "Options All"
        # doesn't give it to you.
        #
        # The Options directive is both complicated and important.  Please see
        # http://httpd.apache.org/docs/2.4/mod/core.html#options
        # for more information.
        #
        Options Indexes FollowSymLinks#
        # AllowOverride controls what directives may be placed in .htaccess files.
        # It can be "All", "None", or any combination of the keywords:
        #
        AllowOverride None

变化值AllowOverride NoneAllowOverride All

现在保存该文件并退出编辑器。

现在您需要确保MySQL安装的安全,但在此之前,您需要密码才能在安装过​​程中自动设置的MySQL root用户密码。运行以下命令以获取您的root密码。

    grep 'temporary password' /var/log/mysqld.log

你会看到下面的输出。

     [root@ip-172-31-32-19 ~]# grep 'temporary password' /var/log/mysqld.log
     2016-07-27T18:28:00.276357Z 1 [Note] A temporary password is generated for root@localhost: ;jldNGPIE3k0

在上面的示例输出中,您可以清楚地看到为您的root帐户生成的密码。现在运行以下命令来运行脚本来保护您的MySQL服务器安装。

    mysql_secure_installation

它会询问您当前的root用户密码,使用我们使用上述命令获得的相同密码。现在为MySQL根用户设置一个强有力的root密码,默认情况下,MySQL自带validate_password插件,因此您将被要求使用至少包含一个大写字母,一个小写字母,一个数字和一个特殊字符的密码,并且总密码长度至少为8个字符。然后它会问你一些配置问题,所有问题的建议答案是肯定的。

    Securing the MySQL server deployment.Enter password for user root:
    The 'validate_password' plugin is installed on the server.
    The subsequent steps will run with the existing configuration
    of the plugin.
    Using existing password for root.Estimated strength of the password: 100
    Change the password for root ? ((Press y|Y for Yes, any other key for No) : yNew password:Re-enter new password:Estimated strength of the password: 100
    Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
    By default, a MySQL installation has an anonymous user,
    allowing anyone to log into MySQL without having to have
    a user account created for them. This is intended only for
    testing, and to make the installation go a bit smoother.
    You should remove them before moving into a production
    environment.Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
    Success.Normally, root should only be allowed to connect from
    'localhost'. This ensures that someone cannot guess at
    the root password from the network.Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
    Success.By default, MySQL comes with a database named 'test' that
    anyone can access. This is also intended only for testing,
    and should be removed before moving into a production
    environment.Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
     - Dropping test database...
    Success.- Removing privileges on test database...
    Success.Reloading the privilege tables will ensure that all changes
    made so far will take effect immediately.Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
    Success.All done!

Magento需要PHP来完成这项工作。Magento支持的PHP版本是从PHP 5.6到PHP 7.1。在本教程中,我们将安装PHP 7以及用于Magento安装的一些额外的必需PHP扩展。运行以下命令以在您的服务器中安装PHP 7。

    yum install -y http://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/ius-release-1.0-14.ius.centos7.noarch.rpm
    yum -y update
    yum -y install php70u php70u-pdo php70u-mysqlnd php70u-opcache php70u-xml php70u-mcrypt php70u-gd php70u-devel  php70u-intl php70u-mbstring php70u-bcmath php70u-json php70u-iconv

您可以使用以下命令验证您的PHP安装版本。

    php -v

你应该看到下面的输出。

    PHP 7.0.9 (cli) (built: Jul 21 2016 11:48:03) ( NTS )
    Copyright (c) 1997-2016 The PHP Group
    Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
        with Zend OPcache v7.0.9, Copyright (c) 1999-2016, by Zend Technologies

现在使用下面的命令编辑你的php配置文件。

    nano /etc/php.ini

向下滚动并查找以下行。

    ; Maximum amount of memory a script may consume (128MB)
    ; http://php.net/memory-limit
    memory_limit = 128M

根据服务器的RAM数量增加内存限制,例如,如果服务器中有2 GB RAM,则可能需要给它1GB。如果以兆字节为单位给出内存限制,则M在该值的末尾使用,还可以G在值的末尾使用字母指定以千兆字节为单位的此值。

向下滚动以查找以下行。

    [Date]
    ; Defines the default timezone used by the date functions
    ; http://php.net/date.timezone
    ;date.timezone =

您需要为PHP设置指定一个时区,否则稍后可能会收到警告。Magento使用PHP指定的时区。取消注释最后一行并根据您的偏好指定时区。它应该如下所示,只需Asia/Kolkata根据您的选择进行更换

    [Date]
    ; Defines the default timezone used by the date functions
    ; http://php.net/date.timezone
    date.timezone = Asia/Kolkata

最后使用以下命令重新启动您的Web服务器。

    systemctl restart httpd

由于我们已经安装并配置了Apache,MySQL和PHP 7,现在我们可以继续下一步安装过程,我们将为Magento Data创建数据库和数据库用户。

创建数据库

使用以下命令创建数据库登录到MySQL命令行。

    mysql -u root -p

现在输入您之前创建的MySQL根密码。你应该看到下面的输出。

    [root@ip-172-31-32-19 ~]# mysql -u root -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 2
    Server version: 5.7.13 MySQL Community Server (GPL)Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql>

现在运行以下查询来创建一个新的数据库。

    CREATE DATABASE magento;

上述命令将创建一个名为数据库的数据库magento。现在,您需要为此数据库创建数据库用户并为用户分配数据库的完全访问权限。对于相同的使用以下命令。

    GRANT ALL ON magento.* TO magentouser@localhost IDENTIFIED BY 'StrongPassword';
    FLUSH PRIVILEGES;

您可以magento根据您的选择将数据库名称重命名为任意名称,也可以将Magento DB用户名更改magentouser为任何您想要的名称。请确保在所使用的地方使用强密码StrongPassword,否则会出现密码不符合要求密码强度的错误。现在使用以下命令退出MySQL提示符。

    exit

您还可以使用以下命令验证数据库和用户是否已成功创建。

    mysql -u magentouser -p

它会提示您输入密码,一旦您登录,您可以使用以下命令查看数据库列表。

    SHOW DATABASES;

您应该看到以下输出。

    [root@ip-172-31-32-19 ~]# mysql -u magentouser -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 5
    Server version: 5.7.13 MySQL Community Server (GPL)Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | magento | +--------------------+ 2 rows in set (0.00 sec)

使用exit命令从MySQL命令行退出在我们配置完数据库后,我们继续安装Composer。

安装Composer

Composer是PHP编程语言的包管理器,提供管理PHP软件依赖和所需库的标准格式。要安装作曲家,请运行以下命令。

    curl -sS https://getcomposer.org/installer | php

上述命令将在您的服务器中安装最新版本的Composer,您将看到以下输出。

    All settings correct for using Composer
    Downloading 1.2.0...

Composer successfully installed to: /root/composer.phar Use it: php composer.phar

要全局使用作曲家,请运行以下命令。

    mv composer.phar /usr/bin/composer

您可以使用以下命令验证作曲家是否成功安装。

    composer -V

你会看到下面的输出。

    [root@ip-172-31-32-19 ~]# composer -V
    Composer version 1.2.0 2016-07-19 01:28:52

现在,当我们安装了作曲家时,我们可以继续安装Magento。

安装Magento

您可以使用许多不同的方法安装magento,也可以选择安装或不安装样本数据的Magento。如果您安装的是Magento以进行评估,您可以选择安装示例数据,如果您正在为生产环境安装Magento,则可以选择安装新的Magento并从头开始配置它。

安装Magento的最好方法是使用Git下载Magento克隆,然后使用composer进行安装。此方法是唯一的安装方法,您可能无需在Magento网站中创建帐户。使用以下命令下载git。

    yum -y install git

现在使用下面的命令使用git下载Magento克隆。

    cd /var/www/html/
    git clone https://github.com/magento/magento2.git

上述命令将创建一个名为magento2并存储安装文件的目录

上述命令会将最新版本的Magento软件安装到您的服务器中,默认情况下这是一个开发版本。切换到稳定版本非常重要,如果您不这样做,那么您将来无法升级安装。如果您希望切换到稳定版本,请运行以下命令。

    cd magento2 &&  git checkout tags/2.1.0 -b 2.1.0

上述命令会将目录更改为您的magento安装目录,并将结帐至稳定版本2.1.0您可以选择结账另一版本的Magento。

您可能想要将所有安装文件移动到Web服务器的文档根目录,因为如果您没有,那么您的magento将会安装http://your-server-IP/magento2

    shopt -s dotglob nullglob && mv /var/www/html/magento2/* /var/www/html/ && cd ..

现在您的magento将被安装在您的文档根目录下,并且可以直接访问http://Your-Server-IP,而不是在子文件夹中magento2

现在您需要为Magento的文件和文件夹设置适当的权限,请针对相同的命令运行以下命令。

    cd /var/www/html
    chown -R :apache /var/www/html
    find /var/www/html -type f -print0 | xargs -r0 chmod 640
    find /var/www/html -type d -print0 | xargs -r0 chmod 750
    chmod -R g+w /var/www/html/{pub,var}
    chmod -R g+w /var/www/html/{app/etc,vendor}
    chmod 750 /var/www/html/bin/magento

现在使用以下命令安装Magento。

    composer install

上述命令将通过安装必需的框架将Magento软件安装到您的服务器中。

安装权限报错 (解决办法在开始安装之前,建议关闭SELinux或将其设置为disabled,最好建议永久关闭SELinux:


# sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
重启系统:reboot,重启完成后查看SELinux
# /usr/sbin/sestatus -v )

完成安装

现在你可以选择使用基于Web的界面来安装Magento,方法是使用你喜欢的浏览器浏览到以下地址。

    http://your-server-IP

现在按照Web界面上提供的说明完成安装。或者您也可以使用命令行安装软件。使用以下命令完成Magento的安装。

确保您根据您的安装环境更改这些值。--base-url如果您已经配置了DNS,您还可以使用位于的域名。建议您使用一些随机词语--backend-frontname来加强Magento管理面板的安全性。

请注意,只要您的任何选项的值有空格或特殊字符,请用单引号或双引号括起来。

    /var/www/html/bin/magento setup:install 
    --admin-firstname=Liptan 
    --admin-lastname=Biswas 
    --admin-email=[email protected] 
    --admin-user=admin 
    --admin-password='StrongPassword' 
    --base-url='http://172.16.0.1/' 
    --backend-frontname=admin 
    --db-host=localhost 
    --db-name=magento 
    --db-user=magentouser 
    --db-password='mysqlDBpass' 
    --currency=GBP 
    --use-rewrites=1 
    --cleanup-database

上述命令需要一些时间才能完成安装,因为安装程序现在将数据写入数据库。安装完成后,您可以访问您的网站

    http://Your-server-IP

您将看到以下界面。

如果你的Magento网站没有显示,而是你得到error 500或者Internal Server Error,你将需要重置文件权限,使用下面的命令。

    chown -R :apache /var/www/html && find /var/www/html -type f -print0 | xargs -r0 chmod 640 && find /var/www/html -type d -print0 | xargs -r0 chmod 750 && chmod -R g+w /var/www/html/{pub,var} && chmod -R g+w /var/www/html/{app/etc,vendor}

再次检查您的网站,您必须看到您的Magento网站。您可以通过浏览以下链接登录到您的Magento管理仪表板。

    http://Your-Server-IP/admin

如果您已使用自定义值,--backend-frontname则使用该值而不是/admin

现在使用您在安装过程中使用的用户名和密码登录到管理面板。登录后,您将看到以下界面。

设置Cron

最后,你需要设置cron来运行预定的作业。要配置cron作业,请运行以下命令。

    crontab -u apache -e

以上命令将apache使用vi编辑器为用户打开cron配置文件如果你有错误说-bash: crontab: command not found运行以下命令进行安装crontab

    yum -y install cronie

现在,通过i在vi编辑器中按下,在文件的末尾添加这些行,一旦完成按esc按钮并:wq写入文件并退出编辑器。

    */10 * * * * php -c /etc /var/www/html/bin/magento cron:run
    */10 * * * * php -c /etc /var/www/html/update/cron.php
    */10 * * * * php -c /etc /var/www/html/bin/magento setup:cron:run 

安装示例数据

上述安装将为您的生产现场提供理想的平台。但是如果你想在制作你的制作网站之前评估Magento。您可以在最近安装的Magento网站中安装示例数据。

运行以下命令以克隆服务器中的示例数据。

    cd /var/www/html
    git clone https://github.com/magento/magento2-sample-data.git

现在运行以下命令来创建符号链接到Magento安装。

    php -f magento2-sample-data/dev/tools/build-sample-data.php -- --ce-source="/var/www/html"

你会看到下面的输出。

    All symlinks you can see at files:
    /var/www/html/magento2-sample-data/dev/tools/exclude.log

现在您需要清除使用以下命令生成的缓存和文件。

    rm -rf var/cache/* var/page_cache/* var/generation/*

现在您可以使用以下命令升级安装并安装示例数据。

    php bin/magento setup:upgrade
    php bin/magento setup:di:compile

安装完成后,您可以在您喜爱的浏览器中查看您的网站,并且您会看到您的店面已加载示例数据。

升级安装

将来如果您想将Magento版本升级到最新版本,可以使用以下命令来完成。

    cd /var/www/html
    composer update

要么

    git pull origin

结论

在本教程中,我们已经在CentOS 7.x上安装了Magento 2 Community Edition。您现在可以轻松部署Magento 2,以供生产使用或开发使用。除了上述安装方法外,您还可以通过从Magento网站下载安装程序归档文件来安装该软件您可以将安装程序上传和解压缩到您的服务器,然后使用Web界面来安装您的软件。

猜你喜欢

转载自blog.csdn.net/qq_37897490/article/details/79507523
今日推荐