How to Install Sylius eCommerce Platform on CentOS 7
Sylius is a modern e-commerce platform for PHP, based on the Symfony Framework. Sylius source code is hosted on GitHub.
This guide will walk you through the Sylius installation process on a fresh CentOS 7 Vultr instance using PHP, MariaDB as a database, and Nginx as a web server.
Requirements
To be able to install Sylius you will need:
- Vultr server instance with at least 2048 MB of memory.
- Nginx or Apache. In this guide, we use Nginx.
- PHP version 7.2 or greater with some specific PHP extensions:
gd
,exif
,fileinfo
,intl
- PHP configuration settings:
memory_limit
equal to or greater than1024M
,date.timezone
- MySQL version 5.7 or 8.0 or MariaDB equivalent
- Composer
- Node.js
- Yarn
Before you begin
Check the CentOS version.
cat /etc/centos-release
# CentOS Linux release 7.6.1810 (Core)
Create a new non-root
user account with sudo
access and switch to it.
useradd -c "John Doe" johndoe && passwd johndoe
usermod -aG wheel johndoe
su - johndoe
NOTE: Replace johndoe
with your username.
Set up the timezone.
timedatectl list-timezones
sudo timedatectl set-timezone 'Region/City'
Ensure that your system is up to date.
sudo yum update
Install the needed packages.
sudo yum install -y socat git wget unzip vim
Disable SELinux and Firewall.
sudo setenforce 0 ; sudo systemctl stop firewalld ; sudo systemctl disable firewalld
Install PHP
Setup the Webtatic YUM repo.
sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
Install PHP and required PHP extensions.
sudo yum install -y php72w-cli php72w-fpm php72w-common php72w-mysqlnd php72w-gd php72w-intl php72w-zip php72w-curl php72w-xml php72w-mbstring php72w-json
Check the version.
php --version
# PHP 7.2.21 (cli) (built: Aug 4 2019 08:42:27) ( NTS )
Start and enable PHP-FPM.
sudo systemctl start php-fpm.service
sudo systemctl enable php-fpm.service
Run sudo vim /etc/php.ini
and set memory_limit
to 1024M
or more, and set up date.timezone
.
memory_limit = 1024M
date.timezone = Region/City
Restart PHP-FPM.
sudo systemctl restart php-fpm.service
Install MariaDB and create a database
Install MariaDB database server.
sudo vi /etc/yum.repos.d/MariaDB.repo
# Copy/paste this to the /etc/yum.repos.d/MariaDB.repo file
[mariadb]
name = MariaDB
baseurl = https://yum.mariadb.org/10.2/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
sudo yum install -y MariaDB-server MariaDB-client
Check the version.
mysql --version
# mysql Ver 15.1 Distrib 10.2.16-MariaDB, for Linux (x86_64) using readline 5.1
Start and enable MariaDB.
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
Run mysql_secure installation
script to improve MariaDB security and set the password for MariaDB root
user.
sudo mysql_secure_installation
Connect to MariaDB shell as the root user.
sudo mysql -u root -p
# Enter password
Create an empty MariaDB 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.
Install Nginx
Install Nginx.
sudo yum install -y nginx
Check the version.
nginx -v
# nginx version: nginx/1.12.2
Start and enable Nginx.
sudo systemctl start nginx.service
sudo systemctl enable nginx.service
Configure Nginx for Sylius. Run sudo vim /etc/nginx/conf.d/sylius.conf
and populate the file with the following configuration.
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 127.0.0.1:9000;
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 the file and exit with Colon+W+Q.
Test the configuration.
sudo nginx -t
Reload Nginx.
sudo systemctl reload nginx.service
Install Composer
Install Composer globally.
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer
Check the version.
composer --version
# Composer version 1.9.0 2019-08-02 20:55:32
Install Node.js
Install Node.js.
sudo yum install -y gcc-c++ make
sudo -s
curl -sL https://rpm.nodesource.com/setup_10.x | bash -
exit
sudo yum install -y nodejs
Check the version.
node --version
# v10.16.3
Install Yarn
Install the Yarn package manager.
curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
sudo yum install -y yarn
Check the version.
yarn --version
# 1.17.3
Install Sylius
Create a document root directory.
sudo mkdir -p /var/www/sylius
Change ownership of the /var/www/sylius
directory to johndoe
.
sudo chown -R johndoe:johndoe /var/www/sylius
Navigate to the document root folder.
cd /var/www/sylius
Initiate a new Sylius project by running this command:
composer create-project sylius/sylius-standard .
Run vim .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 front-end, you will need to install its assets. Sylius uses Gulp to build front-end 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 front-end assets by running:
yarn build
Change ownership of the /var/www/sylius
directory to nginx
.
sudo chown -R nginx:nginx /var/www/sylius
Run sudo vim /etc/php-fpm.d/www.conf
and set the user and group to nginx
. Initially, they will be set to apache.
sudo vi /etc/php-fpm.d/www.conf
# user = nginx
# group = nginx
Create /var/lib/php/session/
directory and change ownership to nginx
.
sudo mkdir -p /var/lib/php/session && sudo chown -R nginx:nginx /var/lib/php/session
Restart the PHP-FPM service.
sudo systemctl restart php-fpm.service
The Sylius e-commerce platform is installed. By default, administration panel routes to /admin
.