云服务器 ECS 建站教程:搭建Magento电子商务网站(CentOS7)

简介:


搭建Magento电子商务网站(CentOS7)

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

适用对象

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

基本流程

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

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

步骤一:安装配置LAMP平台

本文主要说明手动安装LAMP平台的操作步骤,您也可以在云市场购买LAMP镜像直接启动ECS,以便快速建站。

1、更新包和存储库

安装 Apache web server 和 MySQL server。

# 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

2、启动服务并设置开机自启。

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

3、编辑Apache配置文件

# vim /etc/httpd/conf/httpd.conf

找到以下内容,

Include conf.modules.d/*.conf

在上面一行之后添加以下内容,

LoadModule rewrite_module modules/mod_rewrite.so

继续找到以下内容,

   Options Indexes FollowSymLinks
    #
    # 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

将此处的AllowOverride None修改为AllowOverride all。

4、获取密码

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

# 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

5、mysql安全配置

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

  • 设置root账号密码
  • 禁止root账号远程登录
  • 删除匿名用户账号
  • 删除test库和对test库的访问权限

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

http://dev.mysql.com/doc/refman/5.7/en/mysql-secure-installation.html

# mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root: 输入第4步中获取到的密码
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) : N
是否更改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
禁止roo远程登录,输入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!

6、安装PHP 7和一些所需的额外PHP扩展。

# 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

7、验证的版本PHP安装。

# 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

8、编辑配置文件

根据实际情况增加内存限制。

memory_limit = 128M

设置时区为上海。

date.timezone = Asia/Shanghai

9、重启web服务进程。

# systemctl restart httpd

步骤二:创建数据库

1、创建数据库及用户

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

# mysql -u root -p
Enter password: 
mysql> CREATE DATABASE magento;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL ON magento.* TO YourUser@localhost IDENTIFIED BY 'YourPass';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

2、测试可用性

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

# mysql -u magentouser -p
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| magento            |
+--------------------+
2 rows in set (0.00 sec)
mysql> exit

步骤三:安装配置Composer

注:Composer是PHP编程语言软件包管理器提供的一个标准格式的管理所需PHP软件和库的依赖关系。

1、安装Composer。

# 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

2、配置 composer全局使用。

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

3、测试命令是否可用。

# composer -v
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 1.2.4 2016-12-06 22:00:51

步骤四:安装配置Magento

注:可以使用许多不同的方法安装magento,也可以选择是否安装示例数据。测试目的安装Magento,您可以选择安装示例数据;生产环境中安装Magento,建议选择安装全新的Magento,从头开始配置。安装Magento的最好方法是使用Git下载Magento clone,然后使用composer安装。

1、下载安装Magento

通过安装git clone下载安装Magento 。

# yum -y install git
# cd /var/www/html/
# git clone https://github.com/magento/magento2.git

2、切换到稳定版本

默认情况git下载安装Magento是一个最新的开发版本,生产环境中如果没有使用稳定版,那么未来将无法升级安装。

# cd magento2 &&  git checkout tags/2.1.0 -b 2.1.0
Switched to a new branch '2.1.0'

3、移动安装文件到web服务器根目录下

如果不移动则需访问:http://Your-Server-IP/magento2

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

4、设置magento文件适当的权限。

# 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

5、安装Magento。

# composer install

6、完成配置

基于web接口通过浏览器访问:http://Your-Server-IP

按实际情况填写连接数据库信息,web访问设置,定制商店,创建管理员账号。


image
image

完成后访问:http://Your-Server-IP

可看到默认主页。

image


访问:http://Your-Server-IP/admin

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


image


步骤五:添加cron作业

1、设置cron运行调度工作。

# crontab -u apache -e

2、添加以下内容。

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

原文链接

相关实践学习
基于ECS搭建云上博客
本实验教您如何在ECS云服务器(Alibaba Cloud Linux 3)的环境下,通过部署LAMP环境并安装WordPress快速搭建个人博客。
7天玩转云服务器
云服务器ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,可降低 IT 成本,提升运维效率。本课程手把手带你了解ECS、掌握基本操作、动手实操快照管理、镜像管理等。了解产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
弹性计算 搜索推荐 异构计算
阿里云服务器多少钱一年?亲自整理ECS、轻量和GPU服务器租赁价格表
2025年阿里云服务器优惠汇总:轻量应用服务器2核2G 38元/年起,ECS 2核2G 99元/年,2核4G 199元/年,4核16G 89元/月,8核32G 160元/月,香港轻量25元/月起,新老用户同享,续费同价。
2574 158
|
弹性计算 运维 安全
阿里云轻量应用服务器与云服务器ECS啥区别?新手帮助教程
阿里云轻量应用服务器适合个人开发者搭建博客、测试环境等低流量场景,操作简单、成本低;ECS适用于企业级高负载业务,功能强大、灵活可扩展。二者在性能、网络、镜像及运维管理上差异显著,用户应根据实际需求选择。
1091 10
|
弹性计算 运维 安全
区别及选择指南:阿里云轻量应用服务器与ECS云服务器有什么区别?
阿里云轻量应用服务器适合个人开发者、学生搭建博客、测试环境,易用且性价比高;ECS功能更强大,适合企业级应用如大数据、高流量网站。根据需求选择:轻量入门首选,ECS专业之选。
919 2
|
弹性计算 ice
阿里云4核8G云服务器配置价格:热门ECS实例及CPU处理器型号说明
阿里云2025年4核8G服务器配置价格汇总,涵盖经济型e实例、计算型c9i等热门ECS实例,CPU含Intel Xeon及AMD EPYC系列,月费159元起,年付低至1578元,按小时计费0.45元起,实际购买享折扣优惠。
4376 1
|
弹性计算
学生申请阿里云服务器流程,云工开物免费领取云服务器
学生可免费领取或低价购买阿里云服务器。通过“云工开物”计划,学生可申领300元无门槛代金券,用于购买指定云服务器产品。新用户可选38元/年的轻量应用服务器,老用户可选99元/年的ECS服务器,续费同价。具体优惠及操作流程可参考阿里云官方页面。
|
弹性计算 运维 安全
阿里云轻量应用服务器38元1年和云服务器99元1年怎么选?二者性能区别及选择参考
在阿里云当下的活动中,38元/年的轻量应用服务器与99元/年的云服务器ECS成为众多新用户的关注焦点。但是有部分用户并不是很清楚二者之间的区别,因此就不知道应该如何选择。接下来,笔者将为您详细剖析ECS云服务器与轻量应用服务器的差异,以供您参考和选择。
1136 4
阿里云轻量应用服务器38元1年和云服务器99元1年怎么选?二者性能区别及选择参考
|
弹性计算 网络协议 Linux
阿里云服务器简介及使用教程,附送云服务器ECS自定义创建流程
阿里云ECS是安全可靠、弹性灵活的云计算服务,支持多种实例规格与操作系统,可快速创建和管理云服务器。本文详解ECS介绍、购买流程及使用教程,涵盖配置选择、网络设置、安全组规则等,助您轻松上手。
873 16
|
存储 弹性计算 网络协议
超详细的阿里云服务器购买流程,ECS自定义购买配置教程
本文详细图解阿里云ECS服务器自定义购买全流程,涵盖付费模式、地域选择、网络配置、实例规格、镜像、存储、安全组及登录设置等核心步骤,助您轻松掌握专业级云服务器搭建方法。
|
自然语言处理 监控 数据可视化
如何建设网站:使用阿里云的服务器网站建设5大步骤
企业用阿里云服务器建网站,无需复杂技术,按五步骤即可。先规划需求明确网站功能;再选入门级服务器并初始化;接着部署 PageAdmin CMS,可视化操作易上手;然后选模板填内容搭建网站;最后测试适配与稳定性,绑定域名备案后上线。PageAdmin 还方便后期维护调整。
1111 10