Nginx

Adobe Commerce支援nginx 1.x (或 最新主線版本)。 您也必須安裝最新版本的 php-fpm.

安裝指示會因您使用的作業系統而異。 另請參閱 PHP 以取得相關資訊。

烏本圖

以下章節說明如何使用nginx、PHP和MySQL在Ubuntu上安裝Adobe Commerce 2.x。

安裝nginx

sudo apt -y install nginx

您也可以 從來源建置nginx

完成下列各節並安裝應用程式後,我們將使用範例組態檔來 設定nginx.

安裝和配置php-fpm

Adobe Commerce需要數個 PHP擴充功能 以正常運作。 除了這些擴充功能外,您還必須安裝並設定 php-fpm 擴充功能(若您使用nginx)。

安裝及設定 php-fpm

  1. 安裝 php-fpmphp-cli

    code language-bash
    apt-get -y install php7.2-fpm php7.2-cli
    
    note note
    NOTE
    這個指令會安裝最新可用的PHP 7.2.X版本。另請參閱 系統需求 支援的PHP版本。
  2. 開啟 php.ini 編輯器中的檔案:

    code language-bash
    vim /etc/php/7.2/fpm/php.ini
    
    code language-bash
    vim /etc/php/7.2/cli/php.ini
    
  3. 編輯這兩個檔案以符合以下行:

    code language-conf
    memory_limit = 2G
    max_execution_time = 1800
    zlib.output_compression = On
    
    note note
    NOTE
    測試Adobe Commerce時,建議將記憶體限制設為2 G。 請參閱 必要的PHP設定 以取得詳細資訊。
  4. 儲存並退出編輯器。

  5. 重新啟動 php-fpm 服務:

    code language-bash
    systemctl restart php7.2-fpm
    

安裝及設定MySQL

請參閱 MySQL 以取得詳細資訊。

安裝與設定

有數種方式可下載Adobe Commerce,包括:

此範例顯示使用命令列的Composer型安裝。

  1. 作為 檔案系統擁有者,登入您的應用程式伺服器。

  2. 變更至Web伺服器docroot目錄,或您設定為虛擬主機docroot的目錄。 在此範例中,我們使用Ubuntu預設值 /var/www/html.

    code language-bash
    cd /var/www/html
    
  3. 全域安裝撰寫器。 安裝Adobe Commerce之前需要撰寫器更新相依性:

    code language-bash
    curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/bin --filename=composer
    
  4. 使用Adobe Commerce中繼資料建立撰寫器專案。

    Magento Open Source

    code language-bash
    composer create-project --repository=https://repo.magento.com/ magento/project-community-edition <install-directory-name>
    

    Adobe Commerce

    code language-bash
    composer create-project --repository=https://repo.magento.com/ magento/project-enterprise-edition <install-directory-name>
    

    出現提示時,輸入您的 驗證金鑰. 您的 公開金鑰 是您的使用者名稱;您的 私密金鑰 是您的密碼。

  5. 安裝應用程式之前,請先設定網頁伺服器群組的讀寫許可權。 這是必要的,以便命令列可以將檔案寫入檔案系統。

    code language-bash
    cd /var/www/html/<magento install directory>
    
    code language-bash
    find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
    
    code language-bash
    find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
    
    code language-bash
    chown -R :www-data . # Ubuntu
    
    code language-bash
    chmod u+x bin/magento
    
  6. 從安裝 命令列. 此範例假設安裝目錄名為 magento2ee,則 db-host 在同一部電腦上(localhost),且 db-namedb-user、和 db-password 全部 magento

    code language-bash
    bin/magento setup:install \
    --base-url=http://localhost/magento2ee \
    --db-host=localhost \
    --db-name=magento \
    --db-user=magento \
    --db-password=magento \
    --backend-frontname=admin \
    --admin-firstname=admin \
    --admin-lastname=admin \
    --admin-email=admin@admin.com \
    --admin-user=admin \
    --admin-password=admin123 \
    --language=en_US \
    --currency=USD \
    --timezone=America/Chicago \
    --use-rewrites=1 \
    --search-engine=elasticsearch7 \
    --elasticsearch-host=es-host.example.com \
    --elasticsearch-port=9200
    
  7. 切換到開發人員模式:

    code language-bash
    cd /var/www/html/magento2/bin
    
    code language-bash
    ./magento deploy:mode:set developer
    

設定nginx

我們建議使用 nginx.conf.sample 安裝目錄和nginx虛擬主機中提供的組態檔。

這些指示假設您使用的是nginx虛擬主機的Ubuntu預設位置(例如 /etc/nginx/sites-available)和Ubuntu預設docroot (例如, /var/www/html),但您可以變更這些位置以符合您的環境。

  1. 為您的網站建立新的虛擬主機:

    code language-bash
    vim /etc/nginx/sites-available/magento
    
  2. 新增下列設定:

    code language-conf
    upstream fastcgi_backend {
      server  unix:/run/php/php7.2-fpm.sock;
    }
    
    server {
    
      listen 80;
      server_name www.magento-dev.com;
      set $MAGE_ROOT /var/www/html/magento2;
      include /var/www/html/magento2/nginx.conf.sample;
    }
    
    note note
    NOTE
    include 指示必須指向安裝目錄中的nginx組態檔範例。
  3. 取代 www.magento-dev.com 使用您的網域名稱。 這必須符合您在安裝Adobe Commerce時指定的基底URL。

  4. 儲存並退出編輯器。

  5. 於中建立指向新建立的虛擬主機的符號連結,以啟動該虛擬主機。 /etc/nginx/sites-enabled 目錄:

    code language-bash
    ln -s /etc/nginx/sites-available/magento /etc/nginx/sites-enabled
    
  6. 請確認語法正確:

    code language-bash
    nginx -t
    
  7. 重新啟動nginx:

    code language-bash
    systemctl restart nginx
    

驗證安裝

開啟網頁瀏覽器,並導覽至您網站的基底URL,以 驗證安裝.

CentOS 7

以下章節說明如何使用nginx、PHP和MySQL在CentOS 7上安裝Adobe Commerce 2.x。

安裝nginx

yum -y install epel-release
yum -y install nginx

安裝完成後,請啟動nginx並將它設定為在開機時啟動:

systemctl start nginx
systemctl enable nginx

完成下列章節並安裝應用程式後,我們將使用範例組態檔來設定nginx。

安裝和配置php-fpm

Adobe Commerce需要數個 PHP 擴充功能正常運作。 除了這些擴充功能外,您還必須安裝並設定 php-fpm 擴充功能(若您使用nginx)。

  1. 安裝 php-fpm

    code language-bash
    yum -y install php70w-fpm
    
  2. 開啟 /etc/php.ini 編輯器中儲存的檔案。

  3. 取消註解 cgi.fix_pathinfo 行並將值變更為 0.

  4. 編輯檔案以符合下列各行:

    code language-conf
    memory_limit = 2G
    max_execution_time = 1800
    zlib.output_compression = On
    
    note note
    NOTE
    測試Adobe Commerce時,建議將記憶體限制設為2 G。 請參閱 必要的PHP設定 以取得詳細資訊。
  5. 取消註解工作階段路徑目錄並設定路徑:

    code language-conf
    session.save_path = "/var/lib/php/session"
    
  6. 儲存並退出編輯器。

  7. 開啟 /etc/php-fpm.d/www.conf 在編輯器中。

  8. 編輯檔案以符合下列各行:

    code language-conf
    user = nginx
    group = nginx
    listen = /run/php-fpm/php-fpm.sock
    listen.owner = nginx
    listen.group = nginx
    listen.mode = 0660
    
  9. 取消環境行的註解:

    code language-conf
    env[HOSTNAME] = $HOSTNAME
    env[PATH] = /usr/local/bin:/usr/bin:/bin
    env[TMP] = /tmp
    env[TMPDIR] = /tmp
    env[TEMP] = /tmp
    
  10. 儲存並退出編輯器。

  11. 建立PHP階段作業路徑的目錄,並將擁有者變更為 apache 使用者和群組:

    code language-bash
    mkdir -p /var/lib/php/session/
    
    code language-bash
    chown -R apache:apache /var/lib/php/
    
  12. 建立PHP階段作業路徑的目錄,並將擁有者變更為 apache 使用者和群組:

    code language-bash
    mkdir -p /run/php-fpm/
    
    code language-bash
    chown -R apache:apache /run/php-fpm/
    
  13. 開始 php-fpm 服務,並將其設定為在開機時啟動:

    code language-bash
    systemctl start php-fpm
    
    code language-bash
    systemctl enable php-fpm
    
  14. 確認 php-fpm 服務正在執行:

    code language-bash
    netstat -pl | grep php-fpm.sock
    

安裝及設定MySQL

請參閱 MySQL 以取得詳細資訊。

安裝與設定

有數種方式可下載Adobe Commerce,包括:

此範例顯示使用命令列的Composer型安裝。

  1. 作為 檔案系統擁有者,登入您的應用程式伺服器。

  2. 變更至Web伺服器docroot目錄,或您設定為虛擬主機docroot的目錄。 在此範例中,我們使用Ubuntu預設值 /var/www/html.

    code language-bash
    cd /var/www/html
    
  3. 全域安裝撰寫器。 安裝Adobe Commerce之前需要撰寫器更新相依性:

    code language-bash
    curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/bin --filename=composer
    
  4. 使用Adobe Commerce中繼資料建立撰寫器專案。

    Magento Open Source

    code language-bash
    composer create-project --repository=https://repo.magento.com/ magento/project-community-edition <install-directory-name>
    

    Adobe Commerce

    code language-bash
    composer create-project --repository=https://repo.magento.com/ magento/project-enterprise-edition <install-directory-name>
    

    出現提示時,輸入您的 驗證金鑰. 您的 公開金鑰 是您的使用者名稱;您的 私密金鑰 是您的密碼。

  5. 安裝應用程式之前,請先設定網頁伺服器群組的讀寫許可權。 這是必要的,以便命令列可以將檔案寫入檔案系統。

    code language-bash
    cd /var/www/html/<magento install directory>
    
    code language-bash
    find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
    
    code language-bash
    find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
    
    code language-bash
    chown -R :www-data . # Ubuntu
    
    code language-bash
    chmod u+x bin/magento
    
  6. 從安裝 命令列. 此範例假設安裝目錄名為 magento2ee,則 db-host 在同一部電腦上(localhost),且 db-namedb-user、和 db-password 全部 magento

    code language-bash
    bin/magento setup:install \
    --base-url=http://localhost/magento2ee \
    --db-host=localhost \
    --db-name=magento \
    --db-user=magento \
    --db-password=magento \
    --backend-frontname=admin \
    --admin-firstname=admin \
    --admin-lastname=admin \
    --admin-email=admin@admin.com \
    --admin-user=admin \
    --admin-password=admin123 \
    --language=en_US \
    --currency=USD \
    --timezone=America/Chicago \
    --use-rewrites=1
    
  7. 切換到開發人員模式:

    code language-bash
    cd /var/www/html/magento2/bin
    
    code language-bash
    ./magento deploy:mode:set developer
    

設定nginx

我們建議使用 nginx.conf.sample 安裝目錄和nginx虛擬主機中提供的組態檔。

這些指示假設您使用的是nginx虛擬主機的CentOS預設位置(例如 /etc/nginx/conf.d)和預設docroot (例如, /usr/share/nginx/html),但您可以變更這些位置以符合您的環境。

  1. 為您的網站建立新的虛擬主機:

    code language-bash
    vim /etc/nginx/conf.d/magento.conf
    
  2. 新增下列設定:

    code language-conf
    upstream fastcgi_backend {
      server  unix:/run/php-fpm/php-fpm.sock;
    }
    
    server {
    
      listen 80;
      server_name www.magento-dev.com;
      set $MAGE_ROOT /usr/share/nginx/html/magento2;
      include /usr/share/nginx/html/magento2/nginx.conf.sample;
    }
    
    note note
    NOTE
    include 指示必須指向安裝目錄中的nginx組態檔範例。
  3. 取代 www.magento-dev.com 使用您的網域名稱。

  4. 儲存並退出編輯器。

  5. 請確認語法正確:

    code language-bash
    nginx -t
    
  6. 重新啟動nginx:

    code language-bash
    systemctl restart nginx
    

設定SELinux和Firewald

CentOS 7預設啟用SELinux。 使用以下命令檢視它是否正在執行:

sestatus

若要設定SELinux與firewald:

  1. 安裝SELinux管理工具:

    code language-bash
    yum -y install policycoreutils-python
    
  2. 執行以下命令來變更安裝目錄的安全性內容:

    code language-bash
    semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/magento2/app/etc(/.*)?'
    
    code language-bash
    semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/magento2/var(/.*)?'
    
    code language-bash
    semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/magento2/pub/media(/.*)?'
    
    code language-bash
    semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/magento2/pub/static(/.*)?'
    
    code language-bash
    restorecon -Rv '/usr/share/nginx/html/magento2/'
    
  3. 安裝防火牆套件:

    code language-bash
    yum -y install firewalld
    
  4. 啟動防火牆服務,並將它設定為在開機時啟動:

    code language-bash
    systemctl start firewalld
    
    code language-bash
    systemctl enable firewalld
    
  5. 執行以下命令來開啟HTTP和HTTPS的連線埠,以便您可以從網頁瀏覽器存取基本URL:

    code language-bash
    firewall-cmd --permanent --add-service=http
    
    code language-bash
    firewall-cmd --permanent --add-service=https
    
    code language-bash
    firewall-cmd --reload
    

驗證安裝

開啟網頁瀏覽器,並導覽至您網站的基底URL,以 驗證安裝.

recommendation-more-help
0f8e7db5-0e9c-4002-a5b8-a0088077d995