How to Install Shopware with Nginx on Ubuntu 24.04

This article provides a detailed guide on installing Shopware, an open-source e-commerce platform, with Nginx on Ubuntu 24.04. It covers the installation of essential components like Nginx, MariaDB, and PHP, as well as setting up a Shopware database and configuring Nginx for optimal performance and security, including SSL/TLS installation.

This article explains how to install Shopware with Nginx on Ubuntu 24.04.

Shopware is an open-source e-commerce platform that allows businesses to create and manage online stores. It offers features such as product management, customer management, a variety of payment options, and extensibility through plugins and themes.

Nginx is known for its high performance and low resource consumption compared to other web servers like Apache. This can lead to faster load times for your e-commerce site, which is crucial for user experience and conversion rates.

By leveraging the strengths of Nginx and Ubuntu, you can create a powerful, efficient, and secure environment for your Shopware site.

Install Nginx HTTP server on Ubuntu

Shopware requires a web server. This post will install and use the Nginx web server to run Shopware.

To do that, open the Ubuntu terminal and run the commands below to install the Nginx web server.

sudo apt update
sudo apt install nginx

Once Nginx is installed, the commands below can start, stop, and enable the Nginx web server to start automatically when your server boots up.

sudo systemctl stop nginx
sudo systemctl start nginx
sudo systemctl enable nginx

You can test the Nginx web server by opening your web browser and browsing to the server’s localhost or IP address.

http://localhost

When you see the Welcome to nginx!, it means the Nginx HTTP server is successfully installed.

Additional help on installing Nginx on Ubuntu is in the link below.

How to install Nginx on Ubuntu

Install the MariaDB database server on Ubuntu

The next component required to run Shopware is a database server. This post will install and use the MariaDB database server.

To install and use the MariaDB database server, use the instructions below.

Open the Ubuntu terminal and run the commands below to install the MariaDB database server.

sudo apt update
sudo apt install mariadb-server

Once the MariaDB database server is installed, use the commands below to stop, start, and enable the MariaDB server to start automatically when the server boots.

sudo systemctl stop mariadb
sudo systemctl start mariadb
sudo systemctl enable mariadb

Run the following commands to validate and test if the MariaDB database server is installed successfully.

sudo mariadb

Once you run the commands above, it will log you onto the MariaDB console and display a message similar to the one below.

Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 32
Server version: 10.11.2-MariaDB-1 Ubuntu 23.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> 

The message tells you that the server is installed successfully.

Additional help on installing MariaDB.

Create a Shopware database

Upon successfully installing the MariaDB database server, create a blank database on the server specifically for the Shopware application.

As part of the setup, we will create a shopwaredb database and a user account called shopwaredbuser.

Finally, we’ll grant the shopwaredbuser full access to the shopwaredb database.

All the database steps above can be done using the commands below:

But first, log on to the MariaDB database server:

sudo mariadb

Then run the commands below to complete the steps:

CREATE DATABASE shopwaredb CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER shopwaredbuser@localhost IDENTIFIED BY 'type_your_password_here';
GRANT ALL ON shopwaredb.* TO shopwaredbuser@localhost WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit

Ensure to replace ‘type_your_password_here ‘with your password.

Install PHP on Ubuntu Linux

The last component you will need to run Shopware is PHP. The Shopware application is PHP-based and supports the latest versions of PHP.

Then, run the commands below to install the latest PHP version.

sudo apt install php-fpm php-intl php-mysql php-curl php-cli php-zip php-xml php-gd php-common php-mbstring php-xmlrpc php-bcmath php-json php-sqlite3 php-soap php-zip

Additional help on installing PHP

How to install PHP on Ubuntu Linux

Download Shopware files

Let’s begin downloading and configuring the Shopware files on Ubuntu Linux.

To always install the latest version, check the download page for Shopware. Get the download link and download the archived package to your computer. Then, extract it.

First, create a Shopware root folder and download the Shopware files.

The final step is to change the permissions. This will allow the Nginx web server to interact safely with the files, ensuring a secure environment for your Shopware installation.

sudo mkdir -p /var/www/shopware
cd /var/www/shopware
sudo wget https://github.com/shopware/web-recovery/releases/latest/download/shopware-installer.phar.php
sudo chown -R www-data:www-data /var/www/shopware/

Once you have completed all the above steps, continue configuring the Nginx web server below to serve the Shopware content.

Run the commands below to create a Nginx virtual host file for Shopware.

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

Then, copy and paste the content block below into the Nginx server block.

server {
listen 80;
listen [::]:80;
root /var/www/shopware;
index index.php;
server_name shopware.example.com;

access_log /var/log/nginx/example.com.access.log;
error_log /var/log/nginx/example.com.error.log;

# Shopware install / update
location /shopware-installer.phar.php {
try_files $uri /shopware-installer.phar.php$is_args$args;
}

location ~ ^/shopware-installer\.phar\.php/.+\.(?:css|js|png|svg|woff)$ {
try_files $uri /shopware-installer.phar.php$is_args$args;
}

# Deny access to . (dot) files
location ~ /\. {
deny all;
}

# Deny access to .php files in public directories
location ~ ^/(media|thumbnail|theme|bundles|sitemap).*\.php$ {
deny all;
}

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

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

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

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

}

Save the file.

Then, run the commands below to enable the virtual host and restart the Nginx server.

sudo ln -s /etc/nginx/sites-available/shopware.conf /etc/nginx/sites-enabled/
sudo systemctl restart nginx.service

Setup Let’s Encrypt SSL/TLS for Shopware

You may want to install an SSL/TLS certificate to secure your Shopware site. Secure your Shopware installation with HTTPS from Let’s Encrypt.

Please read the post below for additional resources on installing and creating Let’s Encrypt SSL certificates for Nginx.

How to set up Let’s Encrypt SSL certificate for Nginx on Ubuntu Linux

Once you have restarted the Nginx web server, open your browser and browse to the server hostname or IP address defined in the Nginx server block.

http://shopware.example.com/shopware-installer.phar.php

Shopware installation wizard should appear.

Select the installation language and continue.

Select the default PHP library path and continue.

Download the latest version.

After downloading, start the installation and type in the database details created above.

Next, configure your store name and create an admin account.

Shopware should be installed and ready to use.

After the installation, reopen the Nginx virtual host file and change the root path from /var/www/shopware to /var/www/shopware/public.

Reload Nginx to apply the changes.

sudo nano /etc/nginx/sites-available/shopware.conf
sudo systemctl reload nginx

That should do it!

Conclusion:

Installing Shopware with Nginx on Ubuntu 24.04 can enhance your e-commerce platform’s performance and security. Here are the key takeaways:

  • Efficient Setup: The combination of Nginx and Ubuntu provides a robust environment for Shopware.
  • Database Management: MariaDB is a powerful database solution for handling e-commerce data.
  • PHP Compatibility: Ensuring that the latest PHP version is installed provides optimal functionality for Shopware.
  • Safe Environment: Proper configuration and permission settings enhance the security of your installation.
  • SSL Security: Implementing Let’s Encrypt SSL/TLS certificates secures your site and builds customer trust.
  • User-Friendly Installation: The installation wizard simplifies the process, making it accessible even for those with limited technical expertise.

Following these steps, you can fully leverage Shopware’s capabilities to create a successful online store.

Richard Avatar

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *