306
汽車大全
雲服務器 ECS 建站教程:搭建Magento電子商務網站(CentOS7)
Magento是一款開源電商網站框架,其豐富的模塊化架構體係及拓展功能可為大中型站點提供解決方案。它使用PHP開發,支持版本範圍從PHP 5.6到PHP 7.1,並使用MySQL存儲其數據。本文主要說明如何在阿裏雲ECS上搭建Magento電子商務網站。使用的操作係統為Linux CentOS 7. 2 64位。
適用對象
適用於熟悉ECS,熟悉Linux係統,剛開始使用阿裏雲進行建站的用戶。
基本流程
使用雲服務器 ECS 搭建Magento網站的操作步驟如下:
- 安裝配置LAMP平台
- 創建數據庫
- 安裝配置Composer
- 安裝配置Magento
- 添加cron作業
步驟一:安裝配置LAMP平台
本文主要說明手動安裝LAMP平台的操作步驟,您也可以在雲市場購買LAMP鏡像直接啟動ECS,以便快速建站。
1、更新包和存儲庫
安裝 Apache web server 和 MySQL server。
# yum -y update
# yum -y install httpd
# rpm -Uvh https://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庫的訪問權限
詳細說明可參見官方文檔:
https://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
https://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服務器根目錄下
如果不移動則需訪問:https://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接口通過瀏覽器訪問:https://Your-Server-IP
按實際情況填寫連接數據庫信息,web訪問設置,定製商店,創建管理員賬號。
完成後訪問:https://Your-Server-IP
訪問:https://Your-Server-IP/admin
使用您在安裝過程中設置的用戶名和密碼,成功登錄管理麵板後可看到如下界麵。
步驟五:添加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
最後更新:2017-08-13 22:27:50