如何在Linux实例上搭建Magento电子商务网站


本文摘自PHP中文网,作者坏嘻嘻,侵删。

本篇文章给大家带来的内容是关于如何在Linux实例上搭建Magento电子商务网站,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

在Linux实例上搭建Magento电子商务网站


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实例 和 添加安全组规则。

微信截图_20180919111210.png

操作步骤

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

步骤1. 安装配置LAMP平台

步骤2. 创建数据库

步骤3. 安装配置Composer

步骤4. 安装配置Magento

步骤5. 添加cron作业

步骤1. 安装配置LAMP平台

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

依次运行以下命令更新包和存储库,并安装Apache Web服务器和MySQL服务器。

1

2

3

4

# 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

启动HTTP和MySQL服务并设置开机自启动。

1

2

3

4

# systemctl start httpd

# systemctl enable httpd

# systemctl start mysqld

# systemctl enable mysqld

编辑Apache配置文件:

运行命令vim /etc/httpd/conf/httpd.conf。

按 i 键进入编辑模式。

做以下修改:

在 Include conf.modules.d/*.conf 之后添加 LoadModule rewrite_module modules/mod_rewrite.so。

将以下内容的 AllowOverride None 改为 AllowOverride all。

Options Indexes FollowSymLinks

1

2

3

4

5

# AllowOverride controls what directives may be placed in .htaccess files.

# It can be "All", "None", or any combination of the keywords:

# Options FileInfo AuthConfig Limit

#

AllowOverride None

按 Esc 键退出编辑,并输入 :wq 保存并退出。

查看/var/log/mysqld.log文件,获取安装MySQL时自动设置的root用户密码。

1

2

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

2016-12-13T14:57:47.535748Z 1 [Note] A temporary password is generated for root@localhost: p0/G28g>lsHD

运行下面的命令可以从如下4个方面提高MySQL的安全性:

设置root账号密码

禁止root账号远程登录

删除匿名用户账号

删除test库以及对test库的访问权限

详细说明可参见 官方文档。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

# mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: #输入第4步中获取的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) : Y #是否更改root用户密码,输入Y

New 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 #是否删除匿名用户,输入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 #禁止root远程登录,输入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 #是否删除test库和对它的访问权限,输入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 #是否重新加载授权表,输入Y

Success.

All done!

依次运行以下命令,安装PHP 7和一些所需的额外PHP扩展。

1

2

3

# 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-gd php70u-mcrypt php70u-devel php70u-intl php70u-mbstring php70u-bcmath php70u-json php70u-iconv

查看PHP版本,以验证PHP是否已经成功安装。

1

2

3

4

5

# php -v

PHP 7.0.13 (cli) (built: Nov 10 2016 08:44:18) ( NTS )

Copyright (c) 1997-2016 The PHP Group

Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies

 with Zend OPcache v7.0.13, Copyright (c) 1999-2016, by Zend Technologies

编辑配置文件/etc/php.ini:

运行命令 vim /etc/php.ini。

按 i 进入编辑模式。

在文件最后添加以下配置:

memory_limit = 128M #根据实际情况增加内存限制

date.timezone = Asia/Shanghai #设置时区为上海。

重启Web服务进程。

1

# systemctl restart httpd

步骤2. 创建数据库

按以下步骤创建数据库。

创建数据库及用户:为Magento数据创建一个数据库和一个数据库用户,数据库和用户名可根据实际情况修改。

1

2

3

4

5

6

7

8

# mysql -u root -p

Enter password:

mysql> CREATE DATABASE magento; #根据实例情况替换magento

Query OK, 1 row affected (0.00 sec)

mysql> GRANT ALL ON magento.* TO YourUser@localhost IDENTIFIED BY 'YourPass'; #根据实际情况替换YourUser和YourPass

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

运行 exit 退出MySQL。

(可选)验证新建的Magento数据库和用户是否可用。

1

2

3

4

5

6

7

8

9

10

# mysql -u YourUser -p

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| magento            |

+--------------------+

2 rows in set (0.00 sec)

mysql> exit

步骤3. 安装配置Composer

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

安装Composer。

1

2

3

4

5

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

All settings correct for using Composer

Downloading 1.2.4...

Composer successfully installed to: /root/composer.phar

Use it: php composer.phar

配置Composer全局使用。

1

# mv /root/composer.phar /usr/bin/composer

测试命令是否可用。

1

2

3

4

5

6

7

8

# composer -v

______

/ ____/___  ____ ___  ____  ____  ________  _____

/ /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/

/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /

\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/

                 /_/

Composer version 1.2.4 2016-12-06 22:00:51

步骤4. 安装配置Magento

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

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

依次运行以下命令,通过 git clone 下载Magento。

1

2

3

# yum -y install git

# cd /var/www/html/

# git clone https://github.com/magento/magento2.git

(可选)将Magento切换到稳定版本。

默认情况git下载安装Magento是一个最新的开发版本。如果您在生产环境中使用,建议切换到稳定版本,否则未来将无法升级安装。

1

2

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

Switched to a new branch '2.1.0'

将安装文件移到Web服务器根目录下。否则,您只能通过 http://[ECS实例公网IP地址]/magento2 访问您的Magento站点。

1

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

设置Magento文件适当的权限。

1

2

3

4

5

6

# 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

运行 composer install 安装Magento。

测试:在浏览器中访问 http://[ECS实例公网IP地址],如果出现以下页面,说明Magento安装成功。

微信截图_20180919111257.png

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

微信截图_20180919111309.png

步骤5. 添加cron作业

运行 crontab -u apache -e 设置cron运行调度工作。

添加以下内容。

1

2

3

*/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

以上就是如何在Linux实例上搭建Magento电子商务网站的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

Linux 挂载什么意思

常用的Linux命令

Linux连不上网

Linux怎么查看防火墙是否关闭了

抢占式实例的最高出价和抢占式实例当前市场价格的关系

lamp是什么意思

Linux如何开启root权限

Linux中命令无法使用

Linux之关于sort命令的使用详解

Linux怎么查看硬盘信息

更多相关阅读请进入《Linux》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...