HowtoForge

How to Install Shopware with Nginx and Free Let's Encrypt SSL on Ubuntu 22.04

Shopware community edition is a free and open-source shopping cart platform used that allows you to start your own online shop on the web. It is written in Symfony and Vue.js and based on a modern technology stack. It is an alternative solution to other eCommerce applications, like Magento. It offers a beautiful and user-friendly web UI used for managing clients and orders. It allows you to manage the prices of products, change or update themes, design email templates for marketing your products, and generate statistical results.

In this tutorial, we will show you how to install Shopware CE with Nginx and Let's Encrypt on Ubuntu 22.04.

Prerequisites

Install Nginx and MariaDB

First, install the Nginx web server and the MariaDB database server using the following command:

apt-get install nginx mariadb-server -y

Once both package are installed, start Nginx and MariaDB service, and enable them to start at system boot:

systemctl start nginx
systemctl start mariadb
systemctl enable nginx
systemctl enable mariadb

Install PHP and Other Components

Shopware 6 supports PHP versions between 7.2 to 7.3. So you will need to install PHP along with other libraries in your system.

First, add the PHP repository to your system with the following command:

apt-get install software-properties-common -y
add-apt-repository ppa:ondrej/php

Once the repository is added, install PHP with other libraries using the following command:

apt-get install php7.2 php7.2-cli php7.2-fpm php7.2-common php7.2-mysql php7.2-curl php7.2-json php7.2-zip php7.2-gd php7.2-xml php7.2-mbstring php7.2-intl php7.2-opcache git unzip socat curl bash-completion -y

Once all the packages are installed, edit the php.ini file and tweak some desired settings:

nano /etc/php/7.2/fpm/php.ini

Change the following lines:

memory_limit = 512M
upload_max_filesize = 20M
max_execution_time = 300

Save and close the file when you are finished.

Next, you will need to install the IonCube loader in your system.

First, download it with the following command:

wget https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz

Once downloaded, extract the downloaded file with the following command:

tar xfz ioncube_loaders_lin_x86-64.tar.gz

Next, locate the path of the PHP extension directory:

php -i | grep extension_dir

You should see the following output:

extension_dir => /usr/lib/php/20170718 => /usr/lib/php/20170718

Next, copy the IonCube loader to the PHP extension directory:

cp ioncube/ioncube_loader_lin_7.2.so /usr/lib/php/20170718/

Next, edit the php.ini file and define the IonCube loader:

nano /etc/php/7.2/fpm/php.ini

Add the following line inside the [PHP] section:

zend_extension = /usr/lib/php/20170718/ioncube_loader_lin_7.2.so

Save and close the file, then restart the PHP-FPM service to apply the changes.

systemctl restart php7.2-fpm

Configure MariaDB Database

First, secure the MariaDB installation and set the root password using the following script:

mysql_secure_installation

Answer all the questions as shown below:

Enter current password for root (enter for none): 
Set root password? [Y/n] Y
New password: 
Re-enter new password: 
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Once you are done, log in to the MariaDB shell with the following command:

mysql -u root -p

Provide your MariaDB root password, then create a database and user for Shopware:

MariaDB [(none)]> CREATE DATABASE shopwaredb;
MariaDB [(none)]> GRANT ALL ON shopwaredb.* TO 'shopware'@'localhost' IDENTIFIED BY 'password';

Next, flush the privileges and exit from the MariaDB using the following command:

MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;

Once you are finished, you can proceed to the next step.

Download Shopware

First, create a directory for Shopware inside the Nginx web root directory:

mkdir /var/www/html/shopware

Next, change the directory to shopware and download the latest version of Shopware using the following command:

cd /var/www/html/shopware
wget http://releases.s3.shopware.com.s3.amazonaws.com/install_5.4.5_6847c0845f0f97230aa05c7294fa726a96dda3ff.zip?_ga=2.133696968.774684214.1529926951-1771999509.1528830594 -O shopware.zip

Once downloaded, unzip the downloaded file with the following command:

unzip shopware.zip

Next, change the ownership of the shopware directory and give proper permissions using the following command:

chown -R www-data:www-data /var/www/html/shopware
chmod -R 755 /var/www/html/shopware

Once you are done, you can proceed to the next step.

Configure Nginx for Shopware

First, create a new Nginx virtual host configuration file for Shopware:

nano /etc/nginx/sites-available/shopware.conf

Add the following lines:

server {
    listen 80;

    server_name shopware.example.com; # Check this
    root /var/www/html/shopware; # Check this

    index shopware.php index.php;

    location / {
        try_files $uri $uri/ /shopware.php$is_args$args;
    }

    location /recovery/install {
      index index.php;
      try_files $uri /recovery/install/index.php$is_args$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; # Check this
    }
}

Save and close the file, then enable the Shopware virtual host file with the following command:

ln -s /etc/nginx/sites-available/shopware.conf /etc/nginx/sites-enabled/

Next, check the Nginx for any syntax error using the following command:

nginx -t

You should get the following output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Next, restart the Nginx service to apply the changes:

systemctl reload nginx

To check the Nginx status, run the following command:

systemctl status nginx

You should get the following output:

? nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2022-09-12 05:03:41 UTC; 5min ago
       Docs: man:nginx(8)
    Process: 29668 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s reload (code=exited, status=0/SUCCESS)
   Main PID: 17628 (nginx)
      Tasks: 3 (limit: 4579)
     Memory: 5.7M
        CPU: 63ms
     CGroup: /system.slice/nginx.service
             ??17628 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             ??29669 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ??29670 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Sep 12 05:03:41 ubuntu2204 systemd[1]: Starting A high performance web server and a reverse proxy server...
Sep 12 05:03:41 ubuntu2204 systemd[1]: Started A high performance web server and a reverse proxy server.
Sep 12 05:09:28 ubuntu2204 systemd[1]: Reloading A high performance web server and a reverse proxy server...
Sep 12 05:09:28 ubuntu2204 systemd[1]: Reloaded A high performance web server and a reverse proxy server.

Access Shopware Installation Wizard

At this point, Shopware is installed in your system. Now, open your web browser and type the URL http://shopware.example.com. You should see the Shopware web installation wizard:

Select your language and click on the Next button. You should see the following screen:

Make sure all required dependencies are installed, then click on the Next button. You should see the following screen:

Accept the terms and conditions, and click on the Next button. You should see the following screen:

Provide your database details and click on the Start Installation button. Once the installation has been completed successfully, you should see the following screen:

Now, click on the Start Installation button. You should see the following screen:

Click on the Next button. You should see the following page:

Select your desired option and click on the Next button. You should see the following screen:

Provide your shop name, email, country, admin email, admin username, password, and click on the Next button. You will be redirected to the Shopware dashboard screen:

Click on the Go to shop backend button. You should see the following screen:

Provide your login username, password and click on the Login button. You should see the following page:

Now, complete your shop set up and start selling online using the Shopware platform.

Secure Shopware with Let's Encrypt

Before starting, you will need to install the Certbot client in your system to install and manage the Let's Encrypt SSL. You can install it using the following command:

apt-get install certbot python3-certbot-nginx -y

Once the Certbot client is installed, run the following command to download and install Let's Encrypt SSL for your website:

certbot --nginx -d shopware.example.com

Provide your email address and accept the term of service as shown below:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): hitjethva@gmail.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for shopware.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/shopware.conf

Select whether or not to redirect HTTP traffic to HTTPS:

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Type 2 and hit enter to start the process. Once the installation is completed, you should see the following output:

Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/shopware.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://shopware.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=shopware.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/shopware.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/shopware.example.com/privkey.pem
   Your cert will expire on 2022-09-12. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

At this point, your Shopware website is secured with Let's Encrypt SSL. You can now access your website securely using the URL https://shopware.example.com.

Conclusion

Congratulations! you have successfully installed Shopware with Nginx and Let's Encrypt SSL on Ubuntu 22.04. You can now start setting up your own online business using Shopware. Feel free to ask me if you have any questions.

How to Install Shopware with Nginx and Free Let's Encrypt SSL on Ubuntu 22.04