Before you begin

To complete this tutorial, you need access to a working installation running on a LAMP stack:

  • Linux
  • Apache (2.4+)
  • MySQL (5.7+)
  • PHP (7.4)
  • Elasticsearch (7.x) or OpenSearch (1.2)
  • Adobe Commerce (2.4+)
NOTE
Refer to Prerequisites and the Installation Guide for more information.

1. Edit your server configuration

The name and location of your virtual host file depends on which version of Apache that you are running. This example shows the name and location of the virtual host file on Apache v2.4.

  1. Log in to your application server.

  2. Edit your virtual host file:

    vim /etc/apache2/sites-available/000-default.conf
    
  3. Add the path to your pub/ directory to the DocumentRoot directive:

    <VirtualHost *:80>
    
             ServerAdmin webmaster@localhost
             DocumentRoot /var/www/html/magento2ce/pub
    
             ErrorLog ${APACHE_LOG_DIR}/error.log
             CustomLog ${APACHE_LOG_DIR}/access.log combined
    
             <Directory "/var/www/html">
                         AllowOverride all
             </Directory>
     </VirtualHost>
    
  4. Restart Apache:

    systemctl restart apache2
    

2. Update your base URL

If you appended a directory name to your server’s hostname or IP address to create the base URL when you installed the application (for example http://192.168.33.10/magento2), you need to remove it.

NOTE
Replace 192.168.33.10 with your server’s hostname.
  1. Log in to the database:

    mysql -u <user> -p
    
  2. Specify the database that you created when you installed the application:

    use <database-name>
    
  3. Update the base URL:

    UPDATE core_config_data SET value='http://192.168.33.10' WHERE path='web/unsecure/base_url';
    

3. Update the env.php file

Append the following node to the env.php file.

'directories' => [
    'document_root_is_pub' => true
]

Refer to the env.php reference for more information.

4. Switch modes

Application modes, which include production and developer, are designed to improve security and make development easier. As the names suggest, you should switch to developer mode when extending or customizing the application and switch to production mode when running in a live environment.

Switching between modes is an important step in verifying that your server configuration is working properly. You can switch between modes using the CLI tool:

  1. Go to your installation directory.

  2. Switch to production mode.

    bin/magento deploy:mode:set production
    
    bin/magento cache:flush
    
  3. Refresh your browser and verify that the storefront displays properly.

  4. Switch to developer mode.

    bin/magento deploy:mode:set developer
    
    bin/magento cache:flush
    
  5. Refresh your browser and verify that the storefront displays properly.

5. Verify the storefront

Go to the storefront in a web browser to verify that everything is working.

  1. Open a web browser and enter your server’s hostname or IP address in the address bar. For example, http://192.168.33.10.

    The following figure shows a sample storefront page. If it displays as follows, your installation was a success!

    Storefront which verifies a successful installation

    Refer to the troubleshooting section if the page displays a 404 (Not Found) or fails to load other assets like images, CSS, and JS.

  2. Try accessing an application directory from a browser. Append the directory name to your server’s hostname or IP address in the address bar:

    If you see a 404 or the “Access denied” message, you’ve successfully restricted access to the file system.

    Access denied

Previous pageInstall Commerce
Next pageUninstall language packages