How to install Sylius on nixOS Latest

Sylius is an open-source eCommerce platform that is built on top of Symfony, one of the most widely used PHP frameworks. In this tutorial, we will show you how to install Sylius on nixOS Latest.

Step 1: Install Nix Package Manager

To install Sylius on nixOS Latest, we need to install the Nix package manager. Nix is a cross-platform package manager that provides a simple and reproducible way of managing packages and dependencies.

To install Nix, open your terminal and run the following command:

curl https://nixos.org/nix/install | sh

After installing Nix, restart your terminal and type the following command to ensure that Nix is installed correctly:

nix-shell -p cowsay

If Nix is installed correctly, you should see an ASCII-art cow in your terminal.

Step 2: Install PHP and PHP Extensions

Sylius requires PHP to run, so we need to install PHP and its extensions.

To install PHP on nixOS Latest, run the following command:

nix-env -iA nixos.php

After installing PHP, we need to install the required PHP extensions. Sylius requires the following PHP extensions:

To install these extensions, create a php-packages.nix file with the following content:

{ config, lib, pkgs, ... }:

{
  environment.systemPackages = with pkgs; [
    (php.extensions.pdo_mysql.override { enable = true; })
    php.extensions.mbstring
    php.extensions.curl
    php.extensions.gd
    php.extensions.intl
  ];
}

Save the file and run the following command to install the PHP extensions:

nix-shell -E 'with import <nixpkgs> { }; pkgs.callPackage ./php-packages.nix {}'

Step 3: Install MariaDB

Sylius requires a database to store its data. In this tutorial, we will use MariaDB as our database.

To install MariaDB on nixOS Latest, run the following command:

nix-env -iA nixos.mariadb

After installing MariaDB, start the MariaDB service by running the following command:

sudo systemctl start mariadb

You can check the status of the service by running the following command:

sudo systemctl status mariadb

Step 4: Install Composer

Composer is a dependency manager for PHP that is used to manage Sylius's dependencies.

To install Composer on nixOS Latest, run the following command:

nix-env -iA nixpkgs.composer

Step 5: Install Sylius

Now that we have installed all the required dependencies, we can install Sylius.

To install Sylius, create a sylius.nix file with the following content:

let
  sylius = pkgs.sylius;

in sylius.mkSylius {
  database = {
    host = "localhost";
    port = 3306;
    user = "root";
    password = "";
    name = "sylius";
  };
}

Save the file and run the following command:

nix-env -iA syliusLatest -f https://github.com/Sylius/sylius/archive/latest.tar.gz -I nixpkgs=channel:nixos-21.05 -I nixpkgs-overlays=https://github.com/ryantm/nixpkgs-overlays/archive/master.tar.gz -I nixpkgs-overlays=https://github.com/nix-community/nixpkgs-overlay/archive/master.tar.gz -I my-overlays=$PWD -I nixos-config=$HOME/.nixpkgs/config.nix

This command will install the latest version of Sylius along with its dependencies.

Step 6: Configure Sylius

To configure Sylius, run the following command:

cd /nix/store/<sylius-package-hash>/etc/sylius/
cp parameters.yml.dist parameters.yml

Open the parameters.yml file with your favorite text editor and edit the following lines:

database_host: localhost
database_port: 3306
database_name: sylius
database_user: root
database_password: ''

Save the file.

Step 7: Create Database

Before we can start using Sylius, we need to create a database and run the migrations.

To create a database, run the following command:

sudo mysql -u root -e "CREATE DATABASE sylius;"

After creating the database, run the following command to run the migrations:

php bin/console doctrine:migrations:status

If the output is No migrations to execute., then you can skip this step. Otherwise, run the following command to run the migrations:

php bin/console doctrine:migrations:migrate

Step 8: Start Sylius

To start Sylius, run the following command:

php bin/console server:start

You can now access Sylius by visiting http://localhost:8000 in your web browser.

Congratulations! You have successfully installed Sylius on nixOS Latest.

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!