11

How to Install Sylius eCommerce Platform on FreeBSD 12

 3 years ago
source link: https://www.vultr.com/docs/how-to-install-sylius-ecommerce-platform-on-freebsd-12
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
<?xml encoding="utf-8" ??>

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 FreeBSD 12 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 than 1024M, date.timezone
  • MySQL version 5.7 or 8.0 or MariaDB equivalent
  • Composer
  • Node.js
  • Yarn

Before you begin

Check the FreeBSD version.

uname -ro
# FreeBSD 12.0-RELEASE

Ensure that your FreeBSD system is up to date.

freebsd-update fetch install
pkg update && pkg upgrade -y

Install the necessary packages.

pkg install -y sudo vim unzip curl wget bash socat git

Create a new user account with your preferred username. We will use johndoe.

adduser

# Username: johndoe
# Full name: John Doe
# Uid (Leave empty for default): <Enter>
# Login group [johndoe]: <Enter>
# Login group is johndoe. Invite johndoe into other groups? []: wheel
# Login class [default]: <Enter>
# Shell (sh csh tcsh nologin) [sh]: bash
# Home directory [/home/johndoe]: <Enter>
# Home directory permissions (Leave empty for default): <Enter>
# Use password-based authentication? [yes]: <Enter>
# Use an empty password? (yes/no) [no]: <Enter>
# Use a random password? (yes/no) [no]: <Enter>
# Enter password: your_secure_password
# Enter password again: your_secure_password
# Lock out the account after creation? [no]: <Enter>
# OK? (yes/no): yes
# Add another user? (yes/no): no
# Goodbye!

Run the visudo command and uncomment the %wheel ALL=(ALL) ALL line, to allow members of the wheel group to execute any command.

visudo

# Uncomment by removing hash (#) sign
# %wheel ALL=(ALL) ALL

Now, switch to your newly created user with su.

su - johndoe

NOTE: Replace johndoe with your username.

Set up the timezone.

sudo tzsetup

Install PHP

Install PHP and required PHP extensions.

sudo pkg install -y php73 php73-mbstring php73-tokenizer php73-pdo php73-pdo_mysql php73-openssl php73-hash php73-json php73-phar php73-filter php73-zlib php73-dom php73-xml php73-xmlwriter php73-xmlreader php73-curl php73-session php73-ctype php73-iconv php73-gd php73-simplexml php73-zip php73-filter php73-tokenizer php73-calendar php73-fileinfo php73-intl php73-phar php73-soap php73-xmlrpc php73-opcache php73-mysqli php73-bcmath php73-gmp php73-exif

Check the version.

php --version
# PHP 7.3.8 (cli) (built: Aug  8 2019 01:28:36) ( NTS )

Soft-link php.ini-production to php.ini.

sudo ln -s /usr/local/etc/php.ini-production /usr/local/etc/php.ini

Enable and start PHP-FPM.

sudo sysrc php_fpm_enable=yes
sudo service php-fpm start

Run sudo vim /usr/local/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 service php-fpm restart

Install MariaDB and create a database

Install MariaDB.

sudo pkg install -y mariadb102-client mariadb102-server

Check the version.

mysql --version
# mysql  Ver 15.1 Distrib 10.2.25-MariaDB, for FreeBSD12.0 (amd64) using readline 5.1

Start and enable MariaDB.

sudo sysrc mysql_enable="yes" 
sudo service mysql-server start

Run the mysql_secure installation script to improve security and set the password for the root user.

sudo mysql_secure_installation

Connect to the shell as the root user.

sudo mysql -u root -p
# Enter password

Create an empty 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 pkg install -y nginx

Check the version.

nginx -v
# nginx version: nginx/1.16.1

Enable and start Nginx.

sudo sysrc nginx_enable=yes
sudo service nginx start

Configure Nginx for Sylius. Run sudo vim /usr/local/etc/nginx/sylius.conf and populate the file with the following configuration.

server {
  listen 80;
  server_name example.com;
  root /usr/local/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 :+W+Q.

Now we need to include sylius.conf in the main nginx.conf file.

Run sudo vim /usr/local/etc/nginx/nginx.conf and add the following line to the http {} block.

include sylius.conf;

Test the configuration.

sudo nginx -t

Reload Nginx.

sudo service nginx restart

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 pkg install -y node

Check the version.

node --version
# v12.4.0

Install Yarn

Install the Yarn package manager.

sudo pkg install -y yarn

Check the version.

yarn --version
# 1.16.0

Install Sylius

Create a document root directory.

sudo mkdir -p /usr/local/www/sylius

Change ownership of the /usr/local/www/sylius directory to johndoe.

sudo chown -R johndoe:johndoe /usr/local/www/sylius

Navigate to the document root folder.

cd /usr/local/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:[email protected]/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 /usr/local/www/sylius directory to www.

sudo chown -R www:www /usr/local/www/sylius

Create /var/lib/php/session/ directory and change ownership to www.

sudo mkdir -p /var/lib/php/session && sudo chown -R www:www /var/lib/php/session

Restart the PHP-FPM service.

sudo service php-fpm restart

The Sylius e-commerce platform is installed. By default, administration panel routes to /admin.

Want to contribute?

You could earn up to $600 by adding new articles


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK