[内部部署]{class="badge informative" title="仅适用于Adobe Commerce本地项目。"}
安装Apache以进行内部部署 apache
本指南将指导您完成为Adobe Commerce内部部署安装Apache以及配置Commerce所需的Apache设置。 它包括共享的Apache要求以及Ubuntu和CentOS特定于操作系统的过程。 Adobe建议遵循本指南中提供的配置说明,以保留Commerce应用程序的功能和安全性。
Adobe支持您的Adobe Commerce版本的系统要求中列出的Apache版本。 支持的版本因版本而异。 Apache还需要支持的PHP配置。 有关相关的PHP要求,请参阅PHP设置。
从与您的环境匹配的部分开始:
- 如果已安装Apache,请首先查看Apache要求。
- 如果需要在Ubuntu上安装或升级Apache,请转到在Ubuntu上安装或升级Apache。
- 如果需要在CentOS上安装Apache,请转到在CentOS上安装Apache。
查看Apache要求
在托管Adobe Commerce的任何Apache Server上完成这些要求。
配置必需指令
在服务器配置(全局)或虚拟主机配置中设置AllowEncodedSlashes,以避免解码可能导致URL问题的编码斜杠。 例如,当通过API在SKU中检索具有斜杠的产品时,不希望转换斜杠。 以下示例块不完整,需要其他指令。
<VirtualHost *:443>
# Allow encoded slashes
AllowEncodedSlashes NoDecode
</VirtualHost>
配置rewrites和.htaccess apache-rewrites-and-htaccess
使用此部分启用Apache重写并配置分布式.htaccess文件。 Adobe Commerce使用服务器重写和.htaccess为Apache提供目录级说明。
.htaccess中定义的Adobe Commerce安全保护。-
启用Apache重写模块:
code language-bash a2enmod rewrite -
启用应用程序以使用分布式
.htaccess配置文件。-
在Ubuntu上,编辑
/etc/apache2/sites-available/000-default.conf。 有关其他Apache布局或如果需要其他参数,请参阅Apache文档和Apache访问控制文档。 -
为计划安装Adobe Commerce的目录添加或更新
AllowOverride指令。
例如,如果在默认
docroot中安装Adobe Commerce,请将以下块添加到000-default.conf:code language-conf <Directory "/var/www/html"> AllowOverride All </Directory>note note NOTE 如果您从较早的Apache版本升级,请先在 <Directory "/var/www/html">中查找现有的<Directory "/var/www">或000-default.conf块。 如果在其他docroot中安装Adobe Commerce,请更新该路径对应的<Directory>块。 -
-
重新启动Apache以应用更改:
code language-bash service apache2 restart
安装所需模块
Adobe Commerce需要安装以下Apache模块:
验证是否已安装Apache
要验证是否已安装Apache并查看当前版本,请输入:
apache2 -v
结果将显示与以下内容类似的信息:
Server version: Apache/<installed-version>
Server built: <build-date>
-
如果Apache是未安装,请参阅:
在Ubuntu上安装或升级Apache installing-or-upgrading-apache-on-ubuntu
在Ubuntu上安装和配置Apache的过程分为三步:
- 安装软件。
- 启用重写。
- 指定
.htaccess指令。
在配置Apache Server重写时,必须指定可在.htaccess中使用的指令类型,应用程序将使用该指令指定重写规则和安全保护。
在Ubuntu上安装Apache
-
安装Apache(如果尚未安装):
code language-bash apt-get -y install apache2 -
验证安装:
code language-bash apache2 -v类似于以下内容的消息显示以确认安装成功:
code language-text Server version: Apache/<installed-version> Server built: <build-date> -
继续下一部分。
note note NOTE 即使Apache默认随Ubuntu提供,请参阅以下部分以配置它。
在Ubuntu上升级Apache
如果已安装Apache并且您使用的版本低于2.4,请升级到Apache 2.4或您部署的Adobe Commerce版本支持的最新版本。 请参阅系统要求。
-
更新包信息:
code language-bash apt-get -y update -
如果需要,添加为您的环境提供受支持Apache版本的存储库。
-
安装或升级Apache:
code language-bash apt-get install -y apache2note note NOTE 如果 apt-get install命令因未满足的依赖项而失败,请查阅操作系统包文档或分发支持资源。 -
验证安装:
code language-bash apache2 -v -
在系统要求中,确认安装的版本与Adobe Commerce版本支持的版本匹配。
-
为Ubuntu启用
.htaccess重写和。
为Ubuntu启用重写和.htaccess
-
打开
/etc/apache2/sites-available/000-default.conf文件进行编辑:code language-bash vim /etc/apache2/sites-available/000-default.conf -
找到以下列开头的块:
code language-conf <Directory "/var/www/html"> -
将
AllowOverride的值更改为All。例如:
code language-conf <Directory "/var/www/html"> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny Allow from all </Directory> -
保存文件并退出文本编辑器。
-
配置Apache以使用
mod_rewrite模块:code language-bash cd /etc/apache2/mods-enabledcode language-bash ln -s ../mods-available/rewrite.load -
重新启动Apache以应用更改:
code language-bash service apache2 restart
.htaccess中定义的Adobe Commerce安全保护。在CentOS上安装Apache installing-apache-on-centos
在CentOS上安装和配置Apache的过程分为三步:
- 安装软件
- 启用重写
- 指定
.htaccess指令。
在配置Apache Server重写时,必须指定可在.htaccess中使用的指令类型,应用程序将使用该指令指定重写规则和安全保护。
安装Apache
-
安装Apache(如果尚未安装)。
code language-bash yum -y install httpd -
验证安装:
code language-bash httpd -v类似于以下内容的消息显示以确认安装成功:
code language-text Server version: Apache/<installed-version> Server built: <build-date> -
继续下一部分。
note note NOTE 即使Apache默认随CentOS提供,请参阅以下部分以配置它。
为CentOS启用重写和.htaccess
-
打开
/etc/httpd/conf/httpd.conf文件进行编辑:code language-bash vim /etc/httpd/conf/httpd.conf -
找到以下列开头的块:
code language-conf <Directory "/var/www/html"> -
将
AllowOverride的值更改为All。例如:
code language-conf <Directory "/var/www/"> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny Allow from all </Directory>note note NOTE Order的前述值可能并非在所有情况下都有效。 有关详细信息,请参阅Apache文档。 -
保存文件并退出文本编辑器。
-
要应用Apache设置,请重新启动Apache。
code language-bash systemctl restart httpd
.htaccess中定义的Adobe Commerce安全保护。解决403(禁止)错误
如果您在尝试访问站点时遇到403禁止错误,则可以更新Apache配置或虚拟主机配置以启用站点的访客:
解决Apache的403禁止错误
若要使网站访客能够访问您的网站,请使用Require指令之一。
例如:
<Directory "/var/www/">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Require all granted
</Directory>
Order的前述值可能并非在所有情况下都有效。 有关详细信息,请参阅Apache文档。