Get Rewarded! We will reward you with up to €50 credit on your account for every tutorial that you write and we publish!

Installation and configuration of Shopware 6

profile picture
Author
shyim
Published
2020-06-17
Time to read
7 minutes reading time

Introduction

Shopware is a trendsetting ecommerce platform to power your online business. It offers a combination of beauty & brains needed to build and customize a fully responsive online store. In this tutorial, we will learn how to install and configure Shopware 6 with Nginx on Ubuntu 22.04.

Prerequisites

  • Make sure you are logged in with a user with sudo access to the server.
    • It is not possible to follow this tutorial on a Hetzner managed server.
  • A registered domain with the required records as follows:
    • A record with example.com and a reference to the server's IP address
    • A record with www.example.com and a reference to the server's IP address (optional)

Note: example.com is your domain address (for example hetzner.com)

Step 1 - Installing Nginx, MySQL and PHP-FPM

Before we begin with the installation of packages, we will add the Ubuntu PPA to install newer PHP versions:

sudo add-apt-repository ppa:ondrej/php

We can now install Nginx, MySQL and PHP-FPM with the following command:

sudo apt install unzip nginx php8.3-fpm php8.3-mysql php8.3-curl php8.3-gd php8.3-xml php8.3-zip php8.3-opcache php8.3-mbstring php8.3-intl php8.3-cli mysql-server-8.0

To confirm the installation, press enter and then all related packages will be installed.

Step 2 - Creating a database and user for the Shopware database

Shopware will need credentials to connect to the database. We will create a new MySQL user and a new MySQL Database. With the command sudo mysql we start a new mysql session. In this MySQL session we create a new database named shopware using the following query:

CREATE DATABASE shopware;

Next we will create a new MySQL user shopware using the following query:

CREATE USER 'shopware'@'localhost' IDENTIFIED BY 'my-strong-password-here';

As a last step we will need to give the new user privilege to access our new database using the follow query:

GRANT ALL PRIVILEGES ON shopware.* TO 'shopware'@'localhost';

We can end the mysql session by entering exit.

Step 3 - Configuring PHP/PHP-FPM

To match the requirements of Shopware 6, we will need to adjust some php.ini settings. The php.ini used by PHP-FPM can be found under /etc/php/8.3/fpm/php.ini. We can open it with an editor like nano:

sudo nano /etc/php/8.3/fpm/php.ini

We then search with CTRL + W for memory_limit = and set the value from 128 to 512.

Next we will change the upload limits for files. Search again, this time for post_max_size = and upload_max_filesize = using STRG + W and replace the values with 32M.

This will allow us to upload larger files to the media manager. We can save the file with STRG + O and leave the editor with STRG + X.

After configuring, we can restart the PHP-FPM server using the command:

sudo systemctl restart php8.3-fpm

It should be also marked to start on boot:

sudo systemctl enable php8.3-fpm

Step 4 - Configuring Nginx

The default vhost configuration can be found under /etc/nginx/sites-enabled/default. We will edit it to add the Shopware vhost configuration:

sudo nano /etc/nginx/sites-enabled/default

Replace the content with:

Replace example.com with your own domain.

server {
    listen 80;

    # Handle / to index.php
    index index.php;

    # Our server name
    server_name example.com;

    # Should be equal to post_max_size
    client_max_body_size 32M;

    # Where the code is located
    root /var/www/html/public;

    location /recovery/update/ {
        location /recovery/update/assets {
        }
        if (!-e $request_filename){
            rewrite . /recovery/update/index.php last;
        }
    }

    # Forward any not found file to index.php. Allows to have beautiful urls like /homemade-products/
    location / {
        try_files $uri /index.php$is_args$args;
    }

    # Let php-fpm handle .php files
    location ~ ^/(index|shopware-installer\.phar)\.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/php8.3-fpm.sock;
    }
}

Now we can restart nginx and mark it to start on boot:

sudo systemctl restart nginx
sudo systemctl enable nginx

Step 5 - Installing Shopware 6

After configuring MySQL, PHP and Nginx we start the installation of Shopware. We will install it to /var/www/html.

First we install the Composer package manager by downloading it to /usr/local/bin:

sudo wget https://getcomposer.org/download/latest-stable/composer.phar -O /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer

After installing Composer, we switch to the www-data user to install Shopware using Composer.

sudo chown -R www-data:www-data /var/www/html
sudo -u www-data bash
cd /var/www/html

Remove default file in this folder:

rm index.nginx-debian.html

Download Shopware 6 :

composer create-project shopware/production .

Now we can access the installation wizard using our domain. For example:

https://example.com/

Wizard Start Page

In the Database Configuration we can use the configured credentials:

Database Configuration

After finishing the wizard and the first run wizard, the Shop is ready for use.

Administration

Step 6 - Configuring background queue worker

In the default configuration, Shopware 6 will run a browser worker to consume all background tasks. This will block PHP-FPM processes for 30s. When multiple tabs / users are working at the same time in the administration, it will slow down page speed. To fix these issues, we will configure a background worker using systemd.

To disable the current browser worker, we will create a new file config/packages/shopware.yaml:

sudo nano /var/www/html/config/packages/shopware.yaml

Then disable it with the following config:

shopware:
    admin_worker:
        enable_admin_worker: false

To activate the config, we need to clear the cache:

sudo -u www-data php bin/console cache:clear

Now we can create a new systemd unit which interacts as worker. For that we have to create these two new files:

File name Description
/etc/systemd/system/shopware_consumer.service Consumes messages from queue
/etc/systemd/system/shopware_scheduled_task.service Runs scheduled tasks
  • Add the first file:
    sudo nano /etc/systemd/system/shopware_consumer.service
    Add the following unit there:
    [Unit]
    Description=Shopware Consumer
    After=mysql.service
    
    [Service]
    Type=simple
    User=www-data
    Restart=always
    ExecStart=/usr/bin/php /var/www/html/bin/console messenger:consume --time-limit=60 --memory-limit=512M

  • Now we set up the shopware scheduled tasks runner:
    sudo nano /etc/systemd/system/shopware_scheduled_task.service
    Add the following unit there:
    [Unit]
    Description=Shopware Scheduled Task
    After=mysql.service
    
    [Service]
    Type=simple
    User=www-data
    Restart=always
    ExecStart=/usr/bin/php /var/www/html/bin/console scheduled-task:run --time-limit=60 --memory-limit=512M

The processes will have a time limit of 60s and memory limit of 512m. After reaching a limit it will stop and the unit will restart the process.

Now we can start the workers with following commands:

sudo systemctl start shopware_consumer
sudo systemctl start shopware_scheduled_task
sudo systemctl enable shopware_consumer
sudo systemctl enable shopware_scheduled_task

Step 7 - Configuring Let's Encrypt

To configure Let's Encrypt for our new virtual host in Nginx, please follow the Install and Secure Nginx with Let's Encrypt tutorial.

Conclusion

By following this tutorial you will have a shop running with Shopware 6. The next steps would be to start adding products and configuring payment providers. To login as admin, you can go to example.com/admin.

Want to contribute?

Get Rewarded: Get up to €50 in credit! Be a part of the community and contribute. Do it for the money. Do it for the bragging rights. And do it to teach others!

Report Issue
Try Hetzner Cloud

Get €20/$20 free credit!

Valid until: 31 December 2024 Valid for: 3 months and only for new customers
Get started
Want to contribute?

Get Rewarded: Get up to €50 credit on your account for every tutorial you write and we publish!

Find out more