Apache

Adobe Commerce supports Apache 2.4.x.

Apache required directives

  1. Set AllowEncodedSlashes in the server config (globally) or in the virtual host configurations to avoid decoding the encoded slashes that may cause issues for URLs. For instance, when retrieving products with a slash in the SKU via the API, you do not want that converted. The sample block is not complete and other directives are required.

    code language-conf
    <VirtualHost *:443>
      # Allow encoded slashes
      AllowEncodedSlashes NoDecode
    </VirtualHost>
    

Apache rewrites and htaccess

This topic discusses how to enable Apache 2.4 rewrites and specify a setting for the distributed configuration file, .htaccess.

Adobe Commerce and Magento Open Source use server rewrites and .htaccess to provide directory-level instructions for Apache. The following instructions are included in all other sections in this topic as well.

Use this section to enable Apache 2.4 rewrites and specify a setting for the distributed configuration file, .htaccess

Adobe Commerce and Magento Open Source use server rewrites and .htaccess to provide directory-level instructions for Apache.

NOTE
Failure to enable these settings typically results in no styles displaying on your storefront or Admin.
  1. Enable the Apache rewrite module:

    code language-bash
    a2enmod rewrite
    
  2. To enable the application to use the distributed .htaccess configuration file, see the guidelines in the Apache 2.4 documentation.

    note tip
    TIP
    In Apache 2.4, the server’s default site configuration file is /etc/apache2/sites-available/000-default.conf.

    For example, you can add the following to the end of 000-default.conf:

    code language-terminal
    <Directory "/var/www/html">
        AllowOverride All
    </Directory>
    
    note note
    NOTE
    Sometimes, additional parameters might be required. For more information, see the Apache 2.4 documentation.
  3. If you changed Apache settings, restart Apache:

    code language-bash
    service apache2 restart
    
    note note
    NOTE
    • If you upgraded from an earlier Apache version, first look for <Directory "/var/www/html"> or <Directory "/var/www"> in 000-default.conf.
    • You must change the value of AllowOverride in the directive for the directory to which you expect to install the Adobe Commerce or Magento Open Source software. For example, to install in the web server docroot, edit the directive in <Directory /var/www>.
NOTE
Failure to enable these settings typically results in styles not displaying on the storefront or Admin.

Apache required modules

Adobe Commerce and Magento Open Source require the following Apache modules to be installed:

Verify the Apache version

To verify the Apache version that you’re currently running, enter:

apache2 -v

The result displays similar to the following:

Server version: Apache/2.4.04 (Ubuntu)
Server built: Jul 22 2020 14:35:32

Installing or upgrading Apache on Ubuntu

The following sections discuss how to install or upgrade Apache:

  • Install Apache
  • Upgrade to Apache 2.4 on Ubuntu to use PHP 7.4.

Installing Apache on Ubuntu

To install the default version of Apache:

  1. Install Apache

    code language-bash
    apt-get -y install apache2
    
  2. Verify the installation.

    code language-bash
    apache2 -v
    

    The result displays similar to the following:

    code language-terminal
    Server version: Apache/2.4.18 (Ubuntu)
    Server built: 2020-04-15T18:00:57
    
  3. Enable rewrites and .htaccess.

Upgrading Apache on Ubuntu

To upgrade to Apache 2.4:

  1. Add the ppa:ondrej repository, which has Apache 2.4:

    code language-bash
    apt-get -y update
    
    code language-bash
    apt-add-repository ppa:ondrej/apache2
    
    code language-bash
    apt-get -y update
    
  2. Install Apache 2.4:

    code language-bash
    apt-get install -y apache2
    
    note note
    NOTE
    If the ‘apt-get install’ command fails because of unmet dependencies, consult a resource like https://askubuntu.com/.
  3. Verify the installation.

    code language-bash
    apache2 -v
    

    Messages similar to the following should display:

    code language-terminal
    Server version: Apache/2.4.10 (Ubuntu)
    Server built: Jul 22 2020 22:46:25
    
  4. Enable rewrites and .htaccess.

Installing Apache on CentOS

Adobe Commerce and Magento Open Source require Apache use server rewrites. You must also specify the type of directives that can be used in .htaccess, which the application uses to specify rewrite rules.

Installing and configuring Apache is basically a three-step process: install the software, enable rewrites, and specify .htaccess directives.

Installing Apache

  1. Install Apache 2.4 if you have not already done so.

    code language-bash
    yum -y install httpd
    
  2. Verify the installation:

    code language-bash
    httpd -v
    

    Messages similar to the following display to confirm that the installation was successful:

    code language-terminal
    Server version: Apache/2.4.40 (Unix)
    Server built: Oct 16 2020 14:48:21
    
  3. Continue with the next section.

    note note
    NOTE
    Even if Apache 2.4 is provided by default with CentOS, see the following section to configure it.

Enable rewrites and .htaccess for CentOS

  1. Open /etc/httpd/conf/httpd.conf file for editing:

    code language-bash
    vim /etc/httpd/conf/httpd.conf`
    
  2. Locate the block that starts with:

    code language-conf
    <Directory "/var/www/html">
    
  3. Change the value of AllowOverride to All.

    For example,

    code language-conf
    <Directory "/var/www/">
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
      Order allow,deny
      Allow from all
    </Directory>
    
    note note
    NOTE
    The preceding values for Order might not work in all cases. For more information, see the Apache documentation (2.4).
  4. Save the file and exit the text editor.

  5. To apply Apache settings, restart Apache.

    code language-bash
    service apache2 restart
    
NOTE
Failure to enable these settings typically results in no styles displaying on your storefront or Admin.

Enable rewrites and .htaccess for Ubuntu

  1. Open /etc/apache2/sites-available/default file for editing:

    code language-bash
    vim /etc/apache2/sites-available/default
    
  2. Locate the block that starts with:

    <Directory "/var/www/html">

  3. Change the value of AllowOverride to All.

    For example:

    code language-conf
    <Directory "/var/www/html">
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
      Order allow,deny
      Allow from all
    </Directory>
    
  4. Save the file and exit the text editor.

  5. Configure Apache to use the mod_rewrite module:

    code language-bash
    cd /etc/apache2/mods-enabled
    
    code language-bash
    ln -s ../mods-available/rewrite.load
    
  6. Restart Apache to apply changes:

    code language-bash
    service apache2 restart
    

Solving 403 (Forbidden) errors

If you encounter 403 Forbidden errors when trying to access the site, you can update your Apache configuration or your virtual host configuration to enable visitors to the site:

Solving 403 Forbidden errors for Apache 2.4

To enable website visitors to access your site, use one of the Require directives.

For example:

<Directory "/var/www/">
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  Require all granted
</Directory>
NOTE
The preceding values for Order might not work in all cases. For more information, see the Apache documentation.
recommendation-more-help
0f8e7db5-0e9c-4002-a5b8-a0088077d995