天天看點

如何使用Linux雲伺服器搭建Magento電子商務網站

Magento (麥進鬥) 是一套專業開源的電子商務系統。Magento設計得非常靈活,具有子產品化架構體系和豐富的功能。易于與第三方應用系統無縫內建。其面向企業級應用,可處理各方面的需求,以及建設一個多種用途和适用面的電子商務網站。 包括購物、航運、産品評論等等,充分利用開源的特性,提供代碼庫的開發,非正常範的标準,易于與第三方應用系統無縫內建。

準備工作

雲伺服器一台,沒有的可以先到

阿裡雲購買 ,放行安全組的入方向端口80和3306。 阿裡雲新使用者代金券

一、安裝配置Apache

安裝Apache:

先更新軟體包和存儲庫

yum update -y        

安裝Apache

yum install httpd -y        

檢視Apache是否安裝成功

httpd -v      

出現如下圖所示即安裝成功

<img src="https://www.serverblog.cn/usr/uploads/2019/11/3887736219.png" alt="Snipaste_2019-11-22_14-47-37.png" title="Snipaste_2019-11-22_14-47-37.png" /></p>           

打開Apache配置檔案

vim /etc/httpd/conf/httpd.conf        

在Include conf.modules.d/*.conf的下一行,添加LoadModule rewrite_module modules/mod_rewrite.so

将内容中的AllowOverride None更改為AllowOverride All

内容太多不好找可以按Shift+:輸入/AllowOverride controls what指令查找AllowOverride 所在位置,找到更改儲存。

啟動Apache服務

systemctl start httpd        

設定Apache服務開機自啟動

systemctl enable httpd        

二、安裝配置MySQL

添加MySQL YUM源

rpm -Uvh         http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm          

安裝MySQL

yum -y install mysql-community-server        

啟動MySQL服務并設定開機自啟動

啟動MySQL服務

systemctl start mysqld        

設定MySQL服務開機自啟動

systemctl enable mysqld        

配置MySQL

檢視/var/log/mysqld.log檔案,擷取并記錄root使用者的初始密碼

# grep 'temporary password' /var/log/mysqld.log        
說明 下一步重置root使用者密碼時,會使用該初始密碼。

設定root賬号密碼

mysql_secure_installation      

-

Enter password for user root: #輸入上一步中擷取的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: #輸入密碼,長度為8至30個字元,必須同時包含大小寫英文字母、數字和特殊符号。特殊符号可以是()` ~!@#$%^&*-+=|{}[]:;‘<>,.?/  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      

輸入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.        

輸入Y禁止root賬号遠端登入。

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y #禁止root遠端登入,輸入Y  Success.        

輸入Y删除test庫以及對test庫的通路權限。

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y #是否删除test庫和對它的通路權限,輸入Y  - Dropping test database...  Success.        

輸入Y重新加載授權表。

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y #是否重新加載授權表,輸入Y  Success.  All done!        

三、安裝配置PHP

安裝PHP YUM源

# yum install -y         http://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/ius-release-1.0-14.ius.centos7.noarch.rpm                 # rpm -Uvh         https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm                 # rpm -Uvh         https://mirror.webtatic.com/yum/el7/webtatic-release.rpm          

安裝PHP7及所需擴充

yum install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml php72w-ldap php72w-mcrypt        

檢視PHP版本

php -v        

傳回結果如下,說明PHP安裝成功

配置PHP

打開PHP配置檔案

vim /etc/php.ini        

在檔案最後添加以下配置。

memory_limit = 1024M #您可根據實際情況增加或減少記憶體限制  date.timezone = Asia/Shanghai #設定時區為上海。        

添加後如下圖所示。

按下Esc鍵後,輸入:wq并回車以儲存并關閉檔案。

重新開機Web服務程序。

systemctl restart httpd        

四、建立Magento資料庫

使用root使用者和密碼登入MySQL

mysql -u root -p        

建立magento資料庫

mysql> CREATE DATABASE magento; #根據實際情況将magento替換為您需要建立的資料庫名稱        

為magento資料庫建立使用者

mysql> GRANT ALL ON magento.* TO YourUser@localhost IDENTIFIED BY 'YourPass'; #替換YourUser和YourPass為你需要建立的賬号和密碼    mysql> FLUSH PRIVILEGES;        

例如,建立賬号為magentoUser、密碼為magentoUser1@3的使用者:

mysql> GRANT ALL ON magento.* TO magentoUser@localhost IDENTIFIED BY 'magentoUser1@3';  mysql> FLUSH PRIVILEGES;        

輸入exit并回車以退出MySQL

驗證建立的Magento資料庫和使用者是否可用。具體步驟如下:

運作以下指令使用建立賬号和密碼登入MySQL

mysql -u YourUser -p   #替換YourUser為您建立的賬号        

檢視建立的magento資料庫

mysql> show databases;  +--------------------+  | Database           |  +--------------------+  | information_schema |  | magento            |  +--------------------+  2 rows in set (0.00 sec)        

退出MySQL

mysql> exit        

五、安裝配置Composer

安裝Composer

curl -sS         https://getcomposer.org/installer                | php        

配置Composer全局使用

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

輸入指令composer -v檢視Composer版本

如下圖所示即安裝成功

六、安裝配置Magento

下載下傳Magento

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

将安裝檔案移到Web伺服器根目錄下

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

為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        

運作指令composer install安裝Magento

七、配置Magento用戶端

打開浏覽器,在浏覽器位址欄中輸入

https://yq.aliyun.com/go/articleRenderRedirect?url=http%3A%2F%2FIP http://IP

位址

如果出現以下界面,說明Magento安裝成功

單擊Agree and Setup Magento開始配置Magento

準備性檢查,單擊Start Readiness Check,檢查完成後,單擊Next

添加資料庫

輸入之前建立的資料庫使用者的賬号和密碼。本教程中建立的示例使用者賬号為magentoUser、密碼為magentoUser1@3

輸入之前建立的資料庫的名字。本教程中建立的示例資料庫名字為magento

單擊Next

填寫Web通路設定,并單擊Next

填寫定制商店,并單擊Next

填寫管理者賬号資訊,并單擊Next

單擊Install Now進行安裝

出現如下圖所示的界面時,說明Magento配置完成

八、添加cron作業

運作crontab -u apache -e設定cron運作排程工作

通路

https://yq.aliyun.com/go/articleRenderRedirect?url=http%3A%2F%2FIP

位址/ 可以看到如下圖所示的預設首頁

https://yq.aliyun.com/go/articleRenderRedirect?url=http%3A%2F%2FIP

位址/admin,輸入在安裝過程中設定的使用者名和密碼,成功登入管理面闆後可看到如下界面

原文位址:

如何使用Linux雲伺服器搭建Magento電子商務網站

阿裡雲伺服器: 活動位址

購買可領取: 阿裡雲代金券