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

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介:


搭建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
AI 代码解读

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

# systemctl start httpd
# systemctl enable httpd
# systemctl start mysqld
# systemctl enable mysqld
AI 代码解读

3、编辑Apache配置文件

# vim /etc/httpd/conf/httpd.conf
AI 代码解读

找到以下内容,

Include conf.modules.d/*.conf
AI 代码解读

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

LoadModule rewrite_module modules/mod_rewrite.so
AI 代码解读

继续找到以下内容,

   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
AI 代码解读

将此处的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
AI 代码解读

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!
AI 代码解读

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
AI 代码解读

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
AI 代码解读

8、编辑配置文件

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

memory_limit = 128M
AI 代码解读

设置时区为上海。

date.timezone = Asia/Shanghai
AI 代码解读

9、重启web服务进程。

# systemctl restart httpd
AI 代码解读

步骤二:创建数据库

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)
AI 代码解读

2、测试可用性

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

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

步骤三:安装配置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
AI 代码解读

2、配置 composer全局使用。

# mv /root/composer.phar /usr/bin/composer
AI 代码解读

3、测试命令是否可用。

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

步骤四:安装配置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
AI 代码解读

2、切换到稳定版本

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

# cd magento2 &&  git checkout tags/2.1.0 -b 2.1.0
Switched to a new branch '2.1.0'
AI 代码解读

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

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

# shopt -s dotglob nullglob && mv /var/www/html/magento2/* /var/www/html/ && cd ..
AI 代码解读

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
AI 代码解读

5、安装Magento。

# composer install
AI 代码解读

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
AI 代码解读

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
AI 代码解读

原文链接

相关实践学习
快速体验PolarDB开源数据库
本实验环境已内置PostgreSQL数据库以及PolarDB开源数据库:PolarDB PostgreSQL版和PolarDB分布式版,支持一键拉起使用,方便各位开发者学习使用。
7天玩转云服务器
云服务器ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,可降低 IT 成本,提升运维效率。本课程手把手带你了解ECS、掌握基本操作、动手实操快照管理、镜像管理等。了解产品详情: https://www.aliyun.com/product/ecs
目录
打赏
0
0
0
0
355
分享
相关文章
在阿里云服务器上如何搭建网站,网址怎么建站图文教程详解案例及步骤.
做好一个网站不仅需要我们对站点装修及内容发布,也需要我们学会对网站运营,如进行站长推送,将我们内容快速推送到各大搜索平台,有效的让用户能搜索到我们内容,或者需要在谷歌推广就必须对网站添加SSL证书,这样搜索域名的时候搜索框不会出现<不安全>字符在域名前面,以及运行网站要懂运维,出现BUG时要去及时解决查找原因.自始至终自身要不断学习网络相关知识,遇到问题方能迎刃而解. 本文结束,如还有不懂的同学可联系作者,倾力而为,祝您成功!
183 73
WordPress网站服务器性能优化方法,站长必备。
最后,当你将这些方法组合起来并实施时,您将发现你的WordPress网站性能有了显著的提高。别忘了,这不是一次性的任务,要定期执行,保持你的车(网站)始终在轨道上飞驰。
51 21
2025年阿里云服务器租用价格参考:云服务器ECS最新收费标准及活动价格表
2025年,阿里云服务器ECS的租用价格再次迎来更新,1月22日12:00开始,阿里云又开启新一轮的降价政策,部分实例规格的云服务器收费标准有所变化,同时为了进一步降低了用户上云的成本,阿里云还会不定期推出各种活动。现在月付和年付租用阿里云服务器均有优惠了,本文为大家整理汇总了截止目前阿里云服务器最新的租用收费标准及活动价格表,以供了解与参考选择。
124 10
阿里云服务器迁移中心SMC实战指南:跨平台业务迁移教程参考
现在越来越多的个人和企业用户选择将其他云平台或者服务商的业务迁移到阿里云,但是如何快速且安全完成迁移是很多用户比较关注的问题,我们可以选择使用阿里云提供的服务器迁移中心(Server Migration Center,简称SMC),这个产品是阿里云提供给您的迁移平台,专注于提供能力普惠、体验一致、效率至上的迁移服务,满足您在阿里云的迁移需求。本文为大家展示使用阿里云服务器迁移中心SMC将其他云平台业务迁移至阿里云的教程,以供参考。
分享一个纯净无广、原版操作系统、开发人员工具、服务器等资源免费下载的网站
分享一个纯净无广、原版操作系统、开发人员工具、服务器等资源免费下载的网站
阿里云服务器搭建幻兽帕鲁【Palworld】游戏服详细教程,2025最新附价格表
阿里云提供2025年最新幻兽帕鲁游戏服务器申请与一键开服教程。支持4核16G(8人)和8核32G(20人)两种配置,系统自动部署游戏程序,本地安装STEAM即可开始游戏。价格低至70元/月起,选择地域、时长及操作系统后,2-3分钟完成创建。通过Steam客户端输入服务器IP与端口8211,轻松加入多人游戏,开启冒险之旅!更多详情见阿里云幻兽帕鲁专区。
服务器如何设置可以提升网站打开速度?
首先关闭掉php版本中的输出详细错误信息功能;具体步骤为软件商店-对应php版本-设置-配置修改 找到“display_errors”参数,选择“关闭”保存即可。
50 0
阿里云ECS搭建禅道
由于最近换工作,发现新公司问题记录跟踪还在用excel,于是强烈建议使用项目管理工具,并获得批准,在比较了禅道和JIRA,还是选择了禅道,禅道的上下级联的层级关系可能更符合国人的使用习惯,秉承着谁出主意谁干活儿的国际惯例,这个事情也就落到我的头上,于是在阿里云从头开始搭建,这里作个记录。
583 0
阿里云ECS搭建禅道
阿里云特惠云服务器99元与199元配置与性能和适用场景解析:高性价比之选
2025年,阿里云长效特惠活动继续推出两款极具吸引力的特惠云服务器套餐:99元1年的经济型e实例2核2G云服务器和199元1年的通用算力型u1实例2核4G云服务器。这两款云服务器不仅价格亲民,而且性能稳定可靠,为入门级用户和普通企业级用户提供了理想的选择。本文将对这两款云服务器进行深度剖析,包括配置介绍、实例规格、使用场景、性能表现以及购买策略等方面,帮助用户更好地了解这两款云服务器,以供参考和选择。
DeepSeek服务器繁忙解决方法:使用阿里云一键部署DeepSeek个人网站!
通过阿里云一键部署DeepSeek个人网站,解决服务器繁忙问题。学生用户可领取300元代金券实现0成本部署,普通用户则可用99元/年的服务器。教程涵盖从选择套餐、设置密码到获取百炼API-KEY的全流程,助您快速搭建专属大模型主页,体验DeepSeek、Qwen-max、Llama等多款模型,无需代码,最快5分钟完成部署。支持绑定个人域名,共享亲友使用,日均成本仅约1元。
113 10
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等