Are you looking to get started with Sylius, the open-source eCommerce platform?

Sylius is a revolutionary open-source eCommerce platform that offers a wide range of features and customization options. With its powerful features, Sylius is an excellent choice for advanced projects.

In this blog post, we’ll go over the step-by-step process of installing Sylius so you can get your store up and running quickly and easily. From setting up your environment and configuring the database to running the Sylius commands, this guide will walk you through the entire process of setting up Sylius, so by the end of this blog post, you’ll have a fully-functional Sylius store ready to go! So let’s get started and get your Sylius installation up and running!

How to install Sylius?

Installing the Sylius platform on an Ubuntu server can seem a daunting task, but it can be relatively straightforward with the right steps. We’ll go over the steps necessary to prepare your Ubuntu 22.04 system for a Sylius project and start it.

⚠️ All instructions are for a clean system (Ubuntu 22.04) installation, on which nothing has been done before.


tl;dr

If you don’t feel like reading the entire article, just use this command in your terminal. The Sylius project will be accessible locally at the address http://localhost:8000/

⚠️ Running bash scripts from the internet is not safe. Always check what will be executed before running.

Ubuntu 22.04:

bash <(curl -Ls https://raw.githubusercontent.com/BitBagCommerce/HowToInstallSylius/main/Ubuntu2204.sh)

Windows 11 with Ubuntu 22.04 on WSL2:

bash <(curl -Ls https://raw.githubusercontent.com/BitBagCommerce/HowToInstallSylius/main/WSL2Ubuntu2204.sh)

What about Docker?

Can I use Docker instead of the instructions provided below?
Of course, you can! Docker can be a simpler and more efficient way to set up and run a Sylius project, but it’s important to have the knowledge and experience working with Docker before proceeding. You will not find any advice regarding the usage of Docker here.


Installation process

It’s important to note that all the hints and recommendations provided in the article are based on the assumption of using Ubuntu 22.04 as the operating system; therefore, it is strongly recommended to use that specific system to ensure the best performance, security, and compatibility of the website built with the Sylius framework.

These commands perform several tasks in order to set up and configure a Sylius eCommerce platform on a Ubuntu 22.04 system. The commands are as follows:

  1. sudo apt -y update updates the package list on the system. The -y flag automatically answers „yes” to any prompts, so the update process runs without any user interaction.
  2. sudo DEBIAN_FRONTEND=noninteractive apt -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade upgrades all of the system’s installed packages in non-interactive mode so that it doesn’t ask the user for any input.
  3. sudo curl -1sLf '<https://dl.cloudsmith.io/public/symfony/stable/setup.deb.sh>' | sudo -E bash downloads and runs a shell script from the given URL. The script installs the latest stable version of the Symfony framework on the system.
  4. sudo DEBIAN_FRONTEND=noninteractive apt -yq install composer mariadb-server php8.1-fpm php8.1-gd php8.1-mysql php8.1-curl php8.1-zip php8.1-xml symfony-cli npm installs a number of packages necessary for the Sylius platform to run. It installs Composer, MariaDB, the PHP 8.1 FPM and CLI, along with several PHP extensions.
  5. sudo npm install -y -g n && sudo n 18.13.0 installs the Node.js version manager 'n’ and then use it to install version 18.13.0 of Node.js.
  6. sudo npm install -y -g yarn installs the package manager Yarn globally.
  7. sudo sed -i 's/;date.timezone =/date.timezone = Europe\/Warsaw/g' /etc/php/8.1/cli/php.ini && sudo sed -i 's/;date.timezone =/date.timezone = Europe\/Warsaw/g' /etc/php/8.1/fpm/php.ini sets the timezone to 'Europe/Warsaw’ in the PHP configuration files for both CLI and FPM.
  8. sudo mysql -e "CREATE USER 'sylius'@'localhost' IDENTIFIED BY 'SyliusUserPasswordPleaseChangeIt';GRANT ALL privileges ON *.* TO 'sylius'@'localhost';FLUSH PRIVILEGES;" creates a new MySQL user named sylius with the password SyliusUserPasswordPleaseChangeIt and grants all privileges on all databases and tables to that user.
  9. sudo mkdir /var/www creates a new directory /var/www.
  10. cd /var/www changes the current directory to /var/www.
  11. sudo composer --no-interaction create-project sylius/sylius-standard sylius uses the Composer package manager to create a new project based on the sylius/sylius-standard package, and names the project directory sylius.
  12. cd /var/www/sylius changes the current directory to /var/www/sylius.
  13. sudo sed -i 's/root@/sylius:SyliusUserPasswordPleaseChangeIt@/g' /var/www/sylius/.env uses the sed command to find and replace string to have the correct data to connect to the database.
  14. sudo sed -i 's/.environment%/.environment%?serverVersion=mariadb-10.6.11/g' /var/www/sylius/.env uses the sed command to find and replace string in the .env file in the sylius directory; this tells Symfony what database we are using.
  15. sudo composer install --no-interaction uses the Composer package manager to install all of the dependencies for the Sylius project.
  16. sudo bin/console sylius:install runs the Sylius installer command, which sets up the database, assets and other necessary configurations.
  17. sudo yarn install installs all the package dependencies defined in the project’s package.json.
  18. sudo yarn build runs the build scripts defined in the project’s package.json.
  19. sudo chmod 777 -R /var/www/sylius/public/media/ changes the permissions of the /var/www/sylius/public/media directory, and all of its subdirectories and files, to allow read, write, and execute access for all users.
  20. sudo chmod 777 -R /var/www/sylius/var/ changes the permissions of the /var/www/sylius/var directory and all of its subdirectories and files to allow read, write, and execute access for all users.
  21. symfony server:start starts the web server and makes the Sylius application available at http://localhost:8000.

Prefer nginx over Symfony Server?

If you prefer to use nginx instead of the Symfony server, you can follow the instructions below to set it up.

Next, we’ll install and configure nginx as our web server. You can do this by running the following command:

sudo apt install nginx

Once nginx is installed, you’ll need to create a virtual host file for your Sylius project. This file will tell nginx how to handle requests for your project. You can create the file by running the following command:

sudo nano /etc/nginx/sites-available/sylius

You can use the following configuration as a template:

server {
	listen 443 ssl http2;
	listen [::]:443 ssl http2;
	
	ssl_certificate    /etc/ssl/YOUR_CERTIFICATE_FILENAME.crt;
	ssl_certificate_key    /etc/ssl/YOUR_CERTIFICATE_KEY_FILENAME.key;
	
	server_name YOUR_DOMAIN_NAME.com;
	root /var/www/sylius/public;
	
	index index.php;
	
	location / {
	    try_files $uri /index.php$is_args$args;
	}
	
	location ~ ^/index\.php(/|$) {
	    fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
	    fastcgi_split_path_info ^(.+\.php)(/.*)$;
	    include fastcgi_params;
	    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
	    fastcgi_param DOCUMENT_ROOT $realpath_root;
	    internal;
	}
	
	location ~ \.php$ {
	    return 404;
	}
	
	error_log /var/log/nginx/sylius.error.log;
	access_log /var/log/nginx/sylius.access.log;
}

Note that you’ll need to replace the values YOUR_DOMAIN_NAME, YOUR_CERTIFICATE_FILENAME, YOUR_CERTIFICATE_KEY_FILENAME to match your own project.

Once you’ve saved your virtual host file, you’ll need to enable it by creating a symbolic link to it in the sites-enabled directory and restarting nginx for the changes to take effect:

sudo ln -s /etc/nginx/sites-available/sylius /etc/nginx/sites-enabled/ && sudo service nginx restart

Congratulations! 🎉 Your own Sylius store running!


Are you looking for help to get your Sylius setup up and running quickly? We are here to help! With years of experience in Sylius development, our team of experts can help guide you through the entire process. Contact us today and get started on your Sylius journey!