安装 Magento 必备组件 - MariaDB

Magento 需要 MariaDB 10.x ,这在默认的 yum 存储库中不可用。

因此,我们需要按如下方式添加 MariaDB yum 存储库。

[root@magento-server-01 ~]# cat > /etc/yum.repos.d/mariadb.repo << EOF
> [mariadb]
> name=MariaDB
> baseurl=http://yum.mariadb.org/10.3/centos7-amd64
> gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
> gpgcheck=1
> enabled=1
> EOF

在 CentOS 7 中导入 GPG 公钥。

[root@magento-server-01 ~]# rpm --import https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

为新添加的存储库构建 yum 缓存。

[root@magento-server-01 ~]# yum makecache fast

使用 yum 命令安装 MariaDB 10.3.16.

[root@magento-server-01 ~]# yum install -y mariadb-server

启用并启动 MariaDB 服务。

[root@magento-server-01 ~]# systemctl enable mariadb.service
[root@magento-server-01 ~]# systemctl start mariadb.service

如下配置 MariaDB 数据库实例。

[root@magento-server-01 ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n] 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? [Y/n] Y
 ... Success!
By default, MariaDB 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? [Y/n] 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? [Y/n] Y
 ... Success!
Cleaning up...
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!

连接 MariaDB 数据库实例。

[root@magento-server-01 ~]# mysql -u root -p123
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.16-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>

为 Magento 软件创建用户和数据库。

MariaDB [(none)]> create database magento;
Query OK, 1 row affected (0.026 sec)
MariaDB [(none)]> create user magento@localhost identified by '123';
Query OK, 0 rows affected (0.120 sec)
MariaDB [(none)]> grant all privileges on magento.* to magento@localhost identified by '123';
Query OK, 0 rows affected (0.035 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.064 sec)
MariaDB [(none)]> exit
Bye

在 CentOS 7 上安装 Magento 开源版

目前,Magento Open Source 2.3 可在 Magento 下载页面获得。

我们需要在 Magento 站点上创建一个用户帐户才能下载 Magento 软件。

下载 Magento Open Source 2.3 后,将其传输到我们的 Magento 服务器并将其复制到 /tmp 目录中。

在 /var/www/html/magento 目录中提取 Magento-CE-2.3.1_sample_data-2019-03-18-07-26-52.tar.bz2 文件的内容。

[root@magento-server-01 ~]# cd /tmp
[root@magento-server-01 tmp]# mkdir /var/www/html/magento
[root@magento-server-01 tmp]# tar xvf Magento-CE-2.3.1_sample_data-2019-03-18-07-26-52.tar -C /var/www/html/magento/

授予 magento 目录的文件权限,如 Magento 2.3 文档中所述。

[root@magento-server-01 tmp]# cd /var/www/html/magento
[root@magento-server-01 magento]# chown -R apache:apache .
[root@magento-server-01 magento]# find var generated vendor pub/static pub/media app/etc -type f -exec chmod u+w {} +
[root@magento-server-01 magento]# find var generated vendor pub/static pub/media app/etc -type d -exec chmod u+w {} +
[root@magento-server-01 magento]# chmod u+x bin/magento

调整 SELinux 文件上下文。

[root@magento-server-01 magento]# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/magento/var(/.*)?'
[root@magento-server-01 magento]# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/magento/generated(/.*)?'
[root@magento-server-01 magento]# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/magento/vendor(/.*)?'
[root@magento-server-01 magento]# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/magento/pub/static(/.*)?'
[root@magento-server-01 magento]# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/magento/pub/media(/.*)?'
[root@magento-server-01 magento]# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/magento/app/etc(/.*)?'
[root@magento-server-01 magento]# restorecon -R .

如果我们没有 semanage 命令,那么我们必须安装 policycoreutils-python 包。

使用客户端浏览器浏览 URL http://magento-01.onitroad.com/。

我们被重定向到 Magento 许可协议页面。

单击同意并设置 Magento。

单击开始准备检查。

如果任何检查失败,那么我们必须在继续之前纠正它。

对我们来说,没有失败。
因此,单击下一步。

我们处于添加数据库步骤。
添加我们在上面创建的数据库和用户,然后单击下一步。

根据上面的屏幕截图调整设置,然后单击下一步。

在此处设置时区和语言,然后单击下一步。

创建一个新的管理员帐户,然后单击下一步。

单击立即安装。

安装程序需要一段时间才能在 CentOS 7 服务器上设置 Magento。

Magento 安装已完成。

出于安全目的,从 app/etc 目录撤销写入权限。

[root@magento-server-01 ~]# chmod -w /var/www/html/magento/app/etc
[root@magento-server-01 ~]# semanage fcontext -d -t httpd_sys_rw_content_t '/app/etc(/.*)?'
[root@magento-server-01 ~]# restorecon -R /var/www/html/magento/app/etc

单击启动 Magento 管理员。

以 jackli 用户身份登录。

将进入 jackli 用户的仪表板。

我们已经在 CentOS 7 上成功安装了 Magento Open Source。

安装 Magento 必备组件 - Apache 2.4

以 root 用户身份使用 ssh 连接 magento-server-01.onitroad.com。

使用 yum 命令安装 Apache Web 服务器。

[root@magento-server-01 ~]# yum install -y httpd

在 Linux 防火墙中允许 Apache Web 服务。

[root@magento-server-01 ~]# firewall-cmd --permanent --add-service=http
success
[root@magento-server-01 ~]# firewall-cmd --reload
success

启用并启动 Apache Web 服务。

[root@magento-server-01 ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@magento-server-01 ~]# systemctl start httpd

在 /etc/httpd/conf/httpd.conf 中查找和设置 /var/www/html 目录的指令,如下所示。

<Directory /var/www/html>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
</Directory>
之路 on it Road.com

安装 Magento 必备组件 - PHP

Magento 需要 PHP 7.3.1 或者 7.2.0 ,这在默认的 yum 存储库中不可用。

因此,我们正在安装第三方 yum 存储库 Webtatic 来安装 PHP 7.2.

首先,我们必须添加EPEL(Extra Packages for Enterprise Linux)作为Webtatic yum 存储库的准备工作。

[root@magento-server-01 ~]# yum install -y epel-release
...
Installed:
  epel-release.noarch 0:7-11
Complete!

安装 Webtatic yum 存储库如下。

[root@magento-server-01 ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
Retrieving https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
warning: /var/tmp/rpm-tmp.fN84oh: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:webtatic-release-7-3             ################################# [100%]

为 webtatic 存储库构建 yum 缓存。

[root@magento-server-01 ~]# yum makecache fast

使用 yum 命令安装 PHP 7.2 和所需的 PHP 扩展。

[root@magento-server-01 ~]# yum install php72w php72w-bcmath php72w-ctype php72w-curl php72w-dom php72w-gd php72w-hash php72w-iconv php72w-intl php72w-mbstring php72w-openssl php72w-pdo_mysql php72w-simplexml php72w-soap php72w-spl php72w-xsl php72w-zip php72w-pecl libxml2

根据 Magento 的要求配置 PHP 设置。

[root@magento-server-01 ~]# vi /etc/php.ini

查找并更新以下参数。

date.timezone = Asia/Karachi
memory_limit= 756M
max_input_time = 30

重新启动 Apache Web 服务。

[root@magento-server-01 ~]# systemctl restart httpd
在 CentOS 7 上安装 Magento 2 开源版

Magento 是一个开源电子商务平台,最初由 Varien, Inc 开发,目前由 Magento, Inc 的开发人员维护。

Magento 于 2008 年 3 月 31 日首次发布。
Magento 是用 PHP 编写的,它需要一个 LAMP 服务器来部署。

Magento 是一个灵活的开源平台,使商家能够创造创新的购物体验以吸引新客户。
Magento 拥有丰富的、开箱即用的功能集,并结合了数以千计的现成扩展。

在本文中,我们将在 CentOS 7 上安装 Magento Open Source。

日期:2020-09-17 00:16:40 来源:oir作者:oir