In this tutorial, we will deploy Sylius eCommerce on Ubuntu 20.04. We will install PHP, MySQL as a database, and Nginx, Yarn and Node.js.
Sylius provides modern software and development practices that encode a customer-centric approach and agility in your team’s processes and technology.
Prerequisites
Let’s start with the installation.
Step 1 – Keep the server up to date
# apt update -y
# apt upgrade -y
Step 2 – Install required packages
# apt install -y unzip socat
Step 3 – Install and configure PHP
# apt install -y php php-cli php-fpm php-common php-mysql php-gd php-intl php-zip php-curl php-xml php-mbstring
Verify the PHP installation:
# php -v
Output:
PHP 7.4.3 (cli) (built: Oct 6 2020 15:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
Modify memory_limit and set date.timezone
Open php.ini file and find memory_limit and date.timezone
# vi /etc/php/7.4/fpm/php.ini
Set memory_limit to 1024M and set date.timezone according to your Region and city.
memory_limit = 1024M
date.timezone = Region/City
Restart PHP-FPM
# systemctl restart php7.4-fpm.service
Step 4 – Install MySQL and create a database
Install MySQL.
# apt install -y mysql-server
Check the version.
# mysql –version
Run mysql_secure installation script to improve MySQL security and set the password for MySQL root user.
# mysql_secure_installation
and follow these steps
Would you like to setup VALIDATE PASSWORD plugin? N
Please set the password for root here.
New password:
Re-enter new password:
Remove anonymous users? Y
Disallow root login remotely? Y
Remove test database and access to it? Y
Reload privilege tables now? Y
Success.
Connect to MySQL shell as the root user.
# mysql -u root -p
Create an empty MySQL database and user for Sylius, and remember the credentials.
CREATE DATABASE dbname;
GRANT ALL ON dbname.* TO ‘username’ IDENTIFIED BY ‘password’;
FLUSH PRIVILEGES;
exit
NOTE: Replace dbname and username with appropriate names for your setup. Replace password with a strong password.
Step 5 – Install and configure Nginx
# apt install -y nginx
Check the version.
# nginx -v
Create one Nginx configuration file for Sylius.
# vi /etc/nginx/sites-available/sylius.conf
Add following lines in the file.
server {
listen 80;
server_name example.com;
root /var/www/sylius/public;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass unix:/run/php/php7.2-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;
}
client_max_body_size 6m;
}
Save and exit
Activate the new sylius.conf configuration by linking the file to the sites-enabled directory.
# ln -s /etc/nginx/sites-available/sylius.conf /etc/nginx/sites-enabled/
Test the configuration.
# nginx -t
Start and enable Nginx.
# systemctl start nginx.service
# systemctl enable nginx.service
Step 6 – Install Composer
Install Composer globally.
# php -r “copy(‘https://getcomposer.org/installer’, ‘composer-setup.php’);”
# php composer-setup.php
# php -r “unlink(‘composer-setup.php’);”
# mv composer.phar /usr/local/bin/composer
Check the version.
# composer –version
Step 7 – Install Node.js
# curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash –
# apt install -y nodejs
Check the version.
# node –version
Step 8 – Install Yarn
Install the Yarn package manager.
# curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add –
# echo “deb https://dl.yarnpkg.com/debian/ stable main” | sudo tee /etc/apt/sources.list.d/yarn.list
# apt-get update && sudo apt-get install yarn
Check the version.
# yarn –version
Step 9 – Install Sylius
Create a document root directory.
# mkdir -p /var/www/sylius
Navigate to the document directory.
# cd /var/www/sylius
Initiate a new Sylius project by running this command:
# composer create-project sylius/sylius-standard .
Run vi .env.local to enter database details and to run Sylius in an environment of choice.
APP_ENV=prod
DATABASE_URL=mysql://username:password@127.0.0.1/dbname
Note: Replace username, password and dbname with your database details.
After everything is in place, run the following command to install Sylius:
# php bin/console sylius:install -e prod
In order to see a fully functional frontend, you will need to install its assets. Sylius uses Gulp to build frontend assets using Yarn as a JavaScript package manager. Having Yarn installed, go to your project directory to install the dependencies.
# yarn install
Then build the frontend assets by running:
# yarn build
Change ownership of the /var/www/sylius directory to www-data.
# chown -R www-data:www-data /var/www/sylius
The Sylius e-commerce platform is installed. By default, administration panel routes to /admin.
In this tutorial, we have seen how to deploy Sylius eCommerce on Ubuntu 20.04.