溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

在Linux實(shí)例上搭建Magento電子商務(wù)網(wǎng)站的方法

發(fā)布時(shí)間:2020-08-27 14:09:48 來(lái)源:億速云 閱讀:246 作者:小新 欄目:建站服務(wù)器

這篇文章給大家分享的是有關(guān)在Linux實(shí)例上搭建Magento電子商務(wù)網(wǎng)站的方法的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧。

在Linux實(shí)例上搭建Magento電子商務(wù)網(wǎng)站

Magento是一款開(kāi)源電商網(wǎng)站框架,其豐富的模塊化架構(gòu)體系及拓展功能可為大中型站點(diǎn)提供解決方案。它使用PHP開(kāi)發(fā),支持版本范圍從PHP 5.6到PHP 7.1,并使用MySQL存儲(chǔ)數(shù)據(jù)。本文主要說(shuō)明如何在阿里云ECS實(shí)例上搭建Magento電子商務(wù)網(wǎng)站,使用的操作系統(tǒng)為L(zhǎng)inux CentOS 7.2 64位。

適用對(duì)象

適用于熟悉ECS,熟悉Linux系統(tǒng),剛開(kāi)始使用阿里云進(jìn)行建站的用戶。

資源

本文描述的操作涉及的Linux ECS實(shí)例配置包括:2 vCPU、4 GiB內(nèi)存、Cent OS 7.2 64位操作系統(tǒng)、VPC網(wǎng)絡(luò)、分配的公網(wǎng)IP地址。

說(shuō)明:用于搭建Magento 2的服務(wù)器,內(nèi)存不能小于2 GiB。

根據(jù)本文搭建的Magento電子商務(wù)網(wǎng)站,使用的軟件版本信息如下:

MySQL 5.7

PHP 7.0

Magento 2.1

前提條件

您已經(jīng)創(chuàng)建了一臺(tái)VPC網(wǎng)絡(luò)類型的Linux ECS實(shí)例,詳細(xì)操作,請(qǐng)參見(jiàn) 創(chuàng)建ECS實(shí)例。配置包括:2 vCPU、4 GiB內(nèi)存、Cent OS 7.2 64位操作系統(tǒng)、VPC網(wǎng)絡(luò)、分配公網(wǎng)IP地址。

ECS實(shí)例所在安全組中已經(jīng)添加了如下表所示的安全組規(guī)則。詳細(xì)操作,請(qǐng)參見(jiàn) 創(chuàng)建ECS實(shí)例 和 添加安全組規(guī)則。

在Linux實(shí)例上搭建Magento電子商務(wù)網(wǎng)站的方法

操作步驟

使用云服務(wù)器ECS搭建Magento網(wǎng)站的操作步驟如下:

步驟1. 安裝配置LAMP平臺(tái)

步驟2. 創(chuàng)建數(shù)據(jù)庫(kù)

步驟3. 安裝配置Composer

步驟4. 安裝配置Magento

步驟5. 添加cron作業(yè)

步驟1. 安裝配置LAMP平臺(tái)

本部分內(nèi)容說(shuō)明如何手動(dòng)安裝LAMP平臺(tái)。您也可以在 云市場(chǎng) 購(gòu)買LAMP鏡像直接啟動(dòng)ECS實(shí)例,以便快速建站。

依次運(yùn)行以下命令更新包和存儲(chǔ)庫(kù),并安裝Apache Web服務(wù)器和MySQL服務(wù)器。

# 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

啟動(dòng)HTTP和MySQL服務(wù)并設(shè)置開(kāi)機(jī)自啟動(dòng)。

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

編輯Apache配置文件:

運(yùn)行命令vim /etc/httpd/conf/httpd.conf。

按 i 鍵進(jìn)入編輯模式。

做以下修改:

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

將以下內(nèi)容的 AllowOverride None 改為 AllowOverride all。

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

按 Esc 鍵退出編輯,并輸入 :wq 保存并退出。

查看/var/log/mysqld.log文件,獲取安裝MySQL時(shí)自動(dòng)設(shè)置的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

運(yùn)行下面的命令可以從如下4個(gè)方面提高M(jìn)ySQL的安全性:

設(shè)置root賬號(hào)密碼

禁止root賬號(hào)遠(yuǎn)程登錄

刪除匿名用戶賬號(hào)

刪除test庫(kù)以及對(duì)test庫(kù)的訪問(wèn)權(quán)限

詳細(xì)說(shuō)明可參見(jiàn) 官方文檔。

# 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遠(yuǎn)程登錄,輸入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庫(kù)和對(duì)它的訪問(wèn)權(quán)限,輸入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 #是否重新加載授權(quán)表,輸入Y
Success.
All done!

依次運(yùn)行以下命令,安裝PHP 7和一些所需的額外PHP擴(kuò)展。

# 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版本,以驗(yàn)證PHP是否已經(jīng)成功安裝。

# 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:

運(yùn)行命令 vim /etc/php.ini。

按 i 進(jìn)入編輯模式。

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

memory_limit = 128M #根據(jù)實(shí)際情況增加內(nèi)存限制

date.timezone = Asia/Shanghai #設(shè)置時(shí)區(qū)為上海。

重啟Web服務(wù)進(jìn)程。

# systemctl restart httpd

步驟2. 創(chuàng)建數(shù)據(jù)庫(kù)

按以下步驟創(chuàng)建數(shù)據(jù)庫(kù)。

創(chuàng)建數(shù)據(jù)庫(kù)及用戶:為Magento數(shù)據(jù)創(chuàng)建一個(gè)數(shù)據(jù)庫(kù)和一個(gè)數(shù)據(jù)庫(kù)用戶,數(shù)據(jù)庫(kù)和用戶名可根據(jù)實(shí)際情況修改。

# mysql -u root -p
Enter password: 
mysql> CREATE DATABASE magento; #根據(jù)實(shí)例情況替換magento
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL ON magento.* TO YourUser@localhost IDENTIFIED BY 'YourPass'; #根據(jù)實(shí)際情況替換YourUser和YourPass
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

運(yùn)行 exit 退出MySQL。

(可選)驗(yàn)證新建的Magento數(shù)據(jù)庫(kù)和用戶是否可用。

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

步驟3. 安裝配置Composer

Composer是PHP一個(gè)包管理和包依賴管理的工具。按以下步驟安裝配置Composer。

安裝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

配置Composer全局使用。

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

測(cè)試命令是否可用。

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

步驟4. 安裝配置Magento

您可以使用不同的方法安裝Magento,也可以選擇是否安裝示例數(shù)據(jù)。如果安裝Magento僅用于測(cè)試,您可以選擇安裝示例數(shù)據(jù)。如果是在生產(chǎn)環(huán)境中安裝Magento,建議您安裝全新的Magento,從頭開(kāi)始配置。

本部分介紹如何使用git下載Magento,然后使用Composer安裝Magento。

依次運(yùn)行以下命令,通過(guò) git clone 下載Magento。

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

(可選)將Magento切換到穩(wěn)定版本。

默認(rèn)情況git下載安裝Magento是一個(gè)最新的開(kāi)發(fā)版本。如果您在生產(chǎn)環(huán)境中使用,建議切換到穩(wěn)定版本,否則未來(lái)將無(wú)法升級(jí)安裝。

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

將安裝文件移到Web服務(wù)器根目錄下。否則,您只能通過(guò) http://[ECS實(shí)例公網(wǎng)IP地址]/magento2 訪問(wèn)您的Magento站點(diǎn)。

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

設(shè)置Magento文件適當(dāng)?shù)臋?quán)限。

# 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

運(yùn)行 composer install 安裝Magento。

測(cè)試:在瀏覽器中訪問(wèn) http://[ECS實(shí)例公網(wǎng)IP地址],如果出現(xiàn)以下頁(yè)面,說(shuō)明Magento安裝成功。

在Linux實(shí)例上搭建Magento電子商務(wù)網(wǎng)站的方法

單擊 Agree and Setup Magento 開(kāi)始配置Magento:按實(shí)際情況填寫連接數(shù)據(jù)庫(kù)信息、Web訪問(wèn)設(shè)置、定制商店、創(chuàng)建管理員賬號(hào)。出現(xiàn)如下圖所示的界面時(shí),說(shuō)明Magento配置完成

在Linux實(shí)例上搭建Magento電子商務(wù)網(wǎng)站的方法

步驟5. 添加cron作業(yè)

運(yùn)行 crontab -u apache -e 設(shè)置cron運(yùn)行調(diào)度工作。

添加以下內(nèi)容。

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

感謝各位的閱讀!關(guān)于在Linux實(shí)例上搭建Magento電子商務(wù)網(wǎng)站的方法就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI