• 阿里云河南授权服务中心--[ 阿里云精英级合作伙伴 ]
  • 阿里云河南授权服务中心电话 :0371-56982772

搭建Magento电子商务网站(CentOS7)_建站教程
发布时间:2017-08-31 17:03

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。

  1. # yum -y update
  2. # yum -y install httpd
  3. # rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
  4. # yum -y install mysql-community-server

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

  1. # systemctl start httpd
  2. # systemctl enable httpd
  3. # systemctl start mysqld
  4. # systemctl enable mysqld

3、编辑Apache配置文件
# vim /etc/httpd/conf/httpd.conf
找到以下内容,
Include conf.modules.d/*.conf
在上面一行之后添加以下内容,
LoadModule rewrite_module modules/mod_rewrite.so
继续找到以下内容,

  1. OptionsIndexesFollowSymLinks
  2. #
  3. # AllowOverride controls what directives may be placed in .htaccess files.
  4. # It can be "All", "None", or any combination of the keywords:
  5. # Options FileInfo AuthConfig Limit
  6. #
  7. AllowOverrideNone

将此处的AllowOverride None修改为AllowOverride all。
4、获取密码
查看/var/log/mysqld.log文件,获取安装mysql时自动设置的root用户密码。

  1. # grep 'temporary password' /var/log/mysqld.log
  2. 2016-12-13T14:57:47.535748Z1[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

  1. # mysql_secure_installation
  2. Securing the MySQL server deployment.
  3. Enter password for user root:输入第4步中获取到的密码
  4. The'validate_password' plugin is installed on the server.
  5. The subsequent steps will run with the existing configuration of the plugin.
  6. Using existing password for root.
  7. Estimated strength of the password:100
  8. Change the password for root ?((Press y|Y forYes, any other key forNo): N
  9. 是否更改root用户密码,输入Y
  10. New password:输入密码
  11. Re-enter new password:再次输入密码
  12. Estimated strength of the password:100
  13. Do you wish to continue with the password provided?(Press y|Y forYes, any other key forNo): Y
  14. 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.
  15. Remove anonymous users?(Press y|Y forYes, any other key forNo): Y
  16. 是否删除匿名用户,输入Y
  17. Success.
  18. Normally, root should only be allowed to connect from 'localhost'.
  19. This ensures that someone cannot guess at the root password from the network.
  20. Disallow root login remotely?(Press y|Y forYes, any other key forNo): Y
  21. 禁止roo远程登录,输入Y
  22. Success.
  23. By default,MySQL comes with a database named 'test' that anyone can access.
  24. This is also intended only for testing, and should be removed before moving into a production
  25. environment.
  26. Remove test database and access to it?(Press y|Y forYes, any other key forNo): Y
  27. 是否删除test库和对它的访问权限,输入Y
  28. -Dropping test database...
  29. Success.
  30. -Removing privileges on test database...
  31. Success.
  32. Reloading the privilege tables will ensure that all changes
  33. made so far will take effect immediately.
  34. Reload privilege tables now?(Press y|Y forYes, any other key forNo): Y
  35. 是否重新加载授权表,输入Y
  36. Success.
  37. Alldone!

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

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

7、验证的版本PHP安装。

  1. # php -v
  2. PHP 7.0.13(cli)(built:Nov10201608:44:18)( NTS )
  3. Copyright(c)1997-2016The PHP Group
  4. ZendEngine v3.0.0,Copyright(c)1998-2016ZendTechnologies
  5. with ZendOPcache v7.0.13,Copyright(c)1999-2016, by ZendTechnologies

8、编辑配置文件
根据实际情况增加内存限制。
memory_limit = 128M
设置时区为上海。
date.timezone = Asia/Shanghai
9、重启web服务进程。
# systemctl restart httpd
步骤二:创建数据库
1、创建数据库及用户
为Magento Data创建一个数据库和一个数据库用户,数据库和用户名可根据实际情况修改。

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

2、测试可用性
验证新建的Magento数据库和用户是否可用【可选】。

  1. # mysql -u magentouser -p
  2. mysql> show databases;
  3. +--------------------+
  4. |Database|
  5. +--------------------+
  6. | information_schema |
  7. | magento |
  8. +--------------------+
  9. 2 rows inset(0.00 sec)
  10. mysql> exit

步骤三:安装配置Composer
注:Composer是PHP编程语言软件包管理器提供的一个标准格式的管理所需PHP软件和库的依赖关系。
1、安装Composer。

  1. # curl -sS https://getcomposer.org/installer | php
  2. All settings correct for using Composer
  3. Downloading1.2.4...
  4. Composer successfully installed to:/root/composer.phar
  5. Use it: php composer.phar

2、配置 composer全局使用。
# mv /root/composer.phar /usr/bin/composer
3、测试命令是否可用。

  1. # composer -v
  2. ______
  3. / ____/___ ____ ___ ____ ____ ________ _____
  4. /// __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
  5. / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
  6. \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
  7. /_/
  8. 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 。

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

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

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

3、移动安装文件到web服务器根目录下
如果不移动则需访问:http://Your-Server-IP/magento2

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

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

  1. # chown -R :apache /var/www/html
  2. # find /var/www/html -type f -print0 | xargs -r0 chmod 640
  3. # find /var/www/html -type d -print0 | xargs -r0 chmod 750
  4. # chmod -R g+w /var/www/html/{pub,var}
  5. # chmod -R g+w /var/www/html/{app/etc,vendor}
  6. # chmod 750 /var/www/html/bin/magento

5、安装Magento。
# composer install
6、完成配置
基于web接口通过浏览器访问:http://Your-Server-IP
按实际情况填写连接数据库信息,web访问设置,定制商店,创建管理员账号。


完成后访问:http://Your-Server-IP
可看到默认主页。

访问:http://Your-Server-IP/admin
使用您在安装过程中设置的用户名和密码,成功登录管理面板后可看到如下界面。


步骤五:添加cron作业

1、设置cron运行调度工作。
# crontab -u apache -e
2、添加以下内容。

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

相关资讯

  • OSS服务签名及验证签名的方法

    用户可以在 HTTP 请求中增加 Authorization(授权)的 Head 来包含签名 (Signature)信息,表明这个消息已被授权。...
  • OSS怎么更改Object元数据信息?

    OSS的Object包括很多的元数据,包括Key值(目录、名称)、http头信息和user自定义元数据。用户在上传Object或者在后续使用的过程中是可能需要修...

售前咨询:

0371-56982772