如何使用NGINX安裝Shopware 6並加密到CentOS 8
如何使用NGINX安裝Shopware 6並加密到CentOS 8
Shopware是一個免費的開源平台,可以幫助您啟動自己的電子商務網站以增強在線業務。它提供了許多有用的工具來幫助您構建和定製完全響應的在線商店。 與Magento非常相似。 與Magento相比,Shopware是一個功能強大,易於使用且靈活的應用程序。使用現代化的用戶界面,可以從任何設備輕鬆創建和管理內容和產品。
本教程顯示了如何使用Nginx和Let’s Encrypt SSL在CentOS 8上安裝Shopware。
先決條件
- 運行CentOS的服務器8。
- 指向服務器IP的有效域名。
- 根密碼由服務器組成。
安裝LEMP服務器
Shopware在Web服務器上運行,使用Symfony和Zend組件在PHP上構建,並使用MySQL或MariaDB作為數據庫後端。因此,您需要在服務器上安裝Nginx,MariaDB,PHP和其他擴展。您可以使用以下命令將它們全部安裝:
dnf install nginx mariadb-server php php-cli php-intl php-fpm php-common php-mysqli php-curl php-json php-zip php-gd php-xml php-mbstring php-opcache unzip -y
安裝完所有軟件包後,使用以下命令啟動Nginx,MariaDB和PHP-FPM服務,以便可以在系統重新引導時啟動它們。
systemctl start mariadbsystemctl enable mariadbsystemctl start nginxsystemctl start php-fpmsystemctl enable nginxsystemctl enable php-fpm
完成後,您可以繼續下一步。
配置PHP-FPM
默認情況下,PHP-FPM配置為以apache用戶和組身份運行。因此,應將其配置為以Nginx用戶和組身份運行。您可以通過編輯文件/etc/php-fpm.d/www.conf來實現:
nano /etc/php-fpm.d/www.conf
更改以下行。
user = nginx group = nginx
保存並關閉文件,然後創建會話目錄並使用以下命令設置適當的所有權:
mkdir -p /var/lib/php/session chown -R nginx:nginx /var/lib/php/session
然後編輯php.ini文件並調整一些推薦設置。
nano /etc/php.ini
更改以下行。
memory_limit = 512M upload_max_filesize = 20M date.timezone = Asia/Kolkata
保存並關閉文件,然後重新啟動PHP-FPM服務以應用更改。
systemctl restart php-fpm
創建一個商店數據庫
接下來,您需要創建Shopware數據庫和用戶。首先,使用以下命令連接到MariaDB:
mysql
連接後,使用以下命令創建數據庫和用戶。
MariaDB [(none)]> CREATE DATABASE shopware;MariaDB [(none)]> GRANT ALL ON shopware.* TO 'shopware' IDENTIFIED BY 'password';
然後刷新特權並使用以下命令退出MariaDB:
MariaDB [(none)]> FLUSH PRIVILEGES;MariaDB [(none)]> EXIT;
完成後,您可以繼續下一步。
下載商店
接下來,您需要為官方網站下載最新版本的Shopware。首先,在Nginx根目錄內創建一個Shopware目錄。
mkdir /var/www/html/shopware
然後使用以下命令下載購物軟件:
wget https://www.shopware.com/en/Download/redirect/version/sw6/file/install_v6.3.5.0_ba08dbfc07784b5cefe7837f2abbda69dbf5b8b7.zip -O shopware.zip
下載完成後,將下載的文件解壓縮到您的shopware目錄。
unzip shopware.zip -d /var/www/html/shopware
然後使用以下命令設置適當的權限和所有權。
chown -R nginx:nginx /var/www/html/shopwarechmod -R 775 /var/www/html/shopware
完成後,您可以繼續下一步。廣告
配置Nginx for shopware
然後使用以下命令創建Shopware Nginx虛擬主機配置文件。
nano /etc/nginx/conf.d/shopware.conf
添加以下行。
server { listen 80; # Handle / to index.php index index.php; # Our server name server_name shopware.example.com; # Where the code is located root /var/www/html/shopware/public; # Needed for Shopware install / update location /recovery/install { index index.php; try_files $uri /recovery/install/index.php$is_args$args; } location /recovery/update/ { if (!-e $request_filename){ rewrite . /recovery/update/index.php last; } } # Forward any not found file to index.php. Also allows to have beautiful urls like /homemade-products/ location / { try_files $uri /index.php$is_args$args; } # Let php-fpm handle .php files location ~ .php$ { fastcgi_split_path_info ^(.+.php)(/.+)$; include fastcgi.conf; fastcgi_param HTTP_PROXY ""; fastcgi_buffers 8 16k; fastcgi_buffer_size 32k; fastcgi_read_timeout 300s; client_body_buffer_size 128k; fastcgi_pass unix:/run/php-fpm/www.sock; http2_push_preload on; } }
保存並關閉文件,然後使用以下命令檢查Nginx的語法錯誤:
nginx -t
您應該獲得以下輸出:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
然後重新啟動Nginx服務以應用您的更改。
systemctl restart nginx
您還可以使用以下命令檢查Nginx的狀態:
systemctl status nginx
您應該獲得以下輸出:
? nginx.service - The nginx HTTP and reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled) Drop-In: /usr/lib/systemd/system/nginx.service.d ??php-fpm.conf Active: active (running) since Tue 2021-02-02 00:40:04 EST; 19s ago Process: 76059 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS) Process: 76057 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS) Process: 76054 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS) Main PID: 76060 (nginx) Tasks: 3 (limit: 12523) Memory: 5.5M CGroup: /system.slice/nginx.service ??76060 nginx: master process /usr/sbin/nginx ??76061 nginx: worker process ??76062 nginx: worker process Feb 02 00:40:04 centos8 systemd[1]: Stopped The nginx HTTP and reverse proxy server. Feb 02 00:40:04 centos8 systemd[1]: Starting The nginx HTTP and reverse proxy server... Feb 02 00:40:04 centos8 nginx[76057]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok Feb 02 00:40:04 centos8 nginx[76057]: nginx: configuration file /etc/nginx/nginx.conf test is successful Feb 02 00:40:04 centos8 systemd[1]: Started The nginx HTTP and reverse proxy server.
配置SELinux和防火牆
默認情況下,CentOS 8上啟用了SELinux,因此您需要配置Shopware的SELinux上下文。可以使用以下命令進行配置:
setsebool httpd_can_network_connect on -Pchcon -R -u system_u -t httpd_sys_rw_content_t -r object_r /var/www/html/shopware
然後,使用以下命令允許端口80和443通過Firewalld。
firewall-cmd --permanent --add-service=httpfirewall-cmd --permanent --add-service=httpsfirewall-cmd --reload
完成後,您可以繼續下一步。
訪問Shopware Web界面
然後打開網絡瀏覽器並輸入URL http://shopware.example.com..
選擇一種語言, 下一個 按鈕。確保滿足所有要求,然後 下一個 按鈕。顯示下一頁。
同意GTC, 下一個 按鈕。顯示下一頁。
輸入您的數據庫,用戶名和密碼,然後單擊 開始 安裝 按鈕。安裝完成後,將顯示下一頁。
單擊下一頁。系統將提示您輸入商店名稱,電子郵件地址,貨幣,國家/地區,管理員用戶名和密碼,然後單擊。 下一個 按鈕。 您將被重定向到Shopware儀錶板。
輸入所有信息,然後[次へ]點擊按鈕。顯示下一頁。
安裝所需的語言插件, 下一個 按鈕。顯示下一頁。
安裝演示數據或跳過此操作,然後 下一個 按鈕。顯示下一頁。
請點擊 配置,設置 之後..顯示下一頁。
請點擊 跳過 按鈕。顯示下一頁。
請點擊 下一個 按鈕。顯示下一頁。
請點擊 跳過 按鈕。顯示下一頁。
請點擊 結尾 按鈕。 顯示Shopware歡迎頁面。
讓我們加密SSL安全的購物軟件
接下來,您需要在系統上安裝Certbot實用程序,以下載和安裝Let’s Chat域的Let’s Encrypt SSL。
您可以使用以下命令安裝Certbot客戶端:
wget https://dl.eff.org/certbot-automv certbot-auto /usr/local/bin/certbot-autochown root /usr/local/bin/certbot-autochmod 0755 /usr/local/bin/certbot-auto
然後使用以下命令獲取並安裝let域的SSL證書。
certbot-auto --nginx -d shopware.example.com
上面的命令將首先在服務器上安裝所有必需的依賴項。安裝後,將提示您輸入電子郵件地址並接受使用條款,如下所示。
Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator nginx, Installer nginx Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): [email protected] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must agree in order to register with the ACME server at https://acme-v02.api.letsencrypt.org/directory - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (A)gree/(C)ancel: A - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Would you be willing to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'd like to send you email about our work encrypting the web, EFF news, campaigns, and ways to support digital freedom. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: Y Obtaining a new certificate Performing the following challenges: http-01 challenge for shopware.example.com Waiting for verification... Cleaning up challenges Deploying Certificate to VirtualHost /etc/nginx/conf.d/shopware.conf
然後選擇是否將HTTP流量重定向到HTTPS,如下所示。
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: No redirect - Make no further changes to the webserver configuration. 2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for new sites, or if you're confident your site works on HTTPS. You can undo this change by editing your web server's configuration. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
輸入2並按Enter繼續。安裝完成後,您將看到以下輸出:
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/shopware.conf - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Congratulations! You have successfully enabled https://shopware.example.com You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=shopware.example.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/shopware.example.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/shopware.example.com/privkey.pem Your cert will expire on 2021-04-2. To obtain a new or tweaked version of this certificate in the future, simply run certbot-auto again with the "certonly" option. To non-interactively renew *all* of your certificates, run "certbot-auto renew" - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le
您現在可以使用URL https://shopware.example.com安全地訪問Shopware。
結論
恭喜!您已經使用Nginx和Let’s Encrypt SSL在CentOS 8上成功安裝和配置了Shopware。現在,您可以使用Shopware輕鬆託管自己的在線商店。如有任何疑問,請隨時與我們聯繫。