How to Install Shopware Community Edition on nixOS Latest

Shopware is an open-source e-commerce platform used by businesses to create online storefronts. Shopware Community Edition is a free alternative that comes with a host of features to help businesses set up online stores with ease. This tutorial outlines step-by-step instructions on how to install Shopware Community Edition on the latest nixOS.

Prerequisites

Before you start, make sure your system meets the following requirements:

Step 1 - Update the System

Update the system using the following command:

# nixos-rebuild switch --upgrade

This command updates nixOS's package manager to the latest available version.

Step 2 - Install PHP and Apache

Run the following command to install PHP and Apache:

# nix-env -iA nixos.apacheHttpd nixos.php

This command installs Apache as your web server and PHP, a server-side scripting language that enables the webserver to process dynamic content.

Step 3 - Set up the Database

Shopware requires a database to store its data. For this tutorial, we will use MySQL. Run the following command to install MySQL:

# nix-env -iA nixos.mysql

After installation, start the database using this command:

# systemctl start mysql

And then secure the installation:

# mysql_secure_installation

The command initiates a series of prompts where you set the root password, remove anonymous users, remove remote root login, and remove test databases.

Step 4 - Create the Database

We now create a new database and a database user for the Shopware application. Here's how:

# mysql -u root -p

Enter password:

mysql> CREATE DATABASE shopware;

mysql> CREATE USER 'shopware_user'@'localhost' IDENTIFIED BY 'password';

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

mysql> FLUSH PRIVILEGES;

mysql> exit

The shopware user should now be able to access the database.

Step 5 - Download and Install Shopware

Download the latest version of Shopware Community Edition from the official download page. You can use either the .zip or .tar format.

After you have downloaded the file, follow these steps to install it:

If you installed Apache version 2.4, the document root path will be /var/www/html. If you have Apache version 2.2, the document root path is /var/www/.

Step 6 - Create a Virtual Host for Shopware

This step involves creating a virtual host for Shopware in Apache. Open the Apache configuration file using your preferred text editor:

# vim /etc/nixos/configuration.nix

Add the following code at the end of the file:

services.httpd.virtualHosts."shopware.local" = {
      enableSSL = false;
      documentRoot = "/var/www/html/shopware/public";
      serverAliases = [ "www.shopware.local" ];
      extraConfig = ''
        ErrorLog "/var/log/apache2/shopware-error_log"
        CustomLog "/var/log/apache2/shopware-access_log" common
        <Directory "/var/www/html/shopware/public">
              AllowOverride All
              Require all granted
        </Directory>
      '';
};

This configuration will create a virtual host for Shopware, set the document root to /var/www/html/shopware/public, log errors to /var/log/apache2/shopware-error_log, and give you access to the configuration file located in /var/www/html/shopware/public`.

Replace shopware.local with the domain name you prefer, and update the paths accordingly.

Run the following command to activate the virtual host configuration:

# nixos-rebuild switch

Step 7 - Access the Shopware Installation

You are now ready to start using Shopware Community Edition to create an online store.

Conclusion

In conclusion, we have seen how to set up a web server, create a new database, download and install the latest version of Shopware community edition and finally configure the web server to accept connections to the newly created web application. Take a minute to verify everything is working correctly. You should now be fully equipped to set up a Shopware Community Edition instance on nixOS.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!