How to Install X-Cart with Nginx and Let's Encrypt SSL on Ubuntu 18.04 LTS

X-Cart is an extremely flexible open-source eCommerce platform with a wide range of functions and integrations. The X-Cart source code is hosted on Github. This guide describes the process of installing X-Cart 5 on Ubuntu 18.04 LTS using Nginx as the webserver and MySQL as the database server and how to secure the installation with a free SSL Certificate from Let's encrypt.


  • PHP version 7.2 or higher
  • PHP extensions: pdo, phar, mysql, mbstring, curl
  • MySQL version 5.7.7 or higher or MariaDB equivalent
  • Nginx

Initial Steps

Check your Ubuntu version:

lsb_release -ds
# Ubuntu 18.04.4 LTS

Set up the timezone:

sudo dpkg-reconfigure tzdata

Update your operating system packages (software). This is an important first step because it ensures you have the latest updates and security fixes for your operating system's default software packages:

sudo apt update && sudo apt upgrade -y

Install some essential packages that are necessary for basic administration of Ubuntu operating system:

sudo apt install -y curl wget vim git unzip socat bash-completion

Step 1 - Install PHP and PHP extensions

Install PHP, as well as the necessary PHP extensions:

sudo apt install -y php7.2 php7.2-cli php7.2-fpm php7.2-common php7.2-mbstring php7.2-curl php7.2-mysql php7.2-json php7.2-xml php7.2-phar php7.2-pdo php7.2-gd

To show PHP compiled in modules, you can run:

php -m

. . .
. . .

Check the PHP version:

php --version

# PHP 7.2.17-0ubuntu0.18.04.1 (cli) (built: Apr 18 2019 14:12:38) ( NTS )
# Copyright (c) 1997-2018 The PHP Group
# Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
# with Zend OPcache v7.2.17-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies

PHP-FPM service is automatically started and enabled on reboot on Ubuntu 18.04 system, so there is no need to start and enable it manually. We can move on to the next step, which is the database installation and setup.

Step 2 - Install MySQL and create a database

Install MySQL:

sudo apt install -y mysql-server

Check the version:

mysql --version
# mysql  Ver 14.14 Distrib 5.7.27, for Linux (x86_64) using  EditLine wrapper

Run the mysql_secure_installation script to improve the security of your MySQL installation:

sudo mysql_secure_installation

Log into MySQL as the root user:

sudo mysql -u root -p
# Enter password:

Create a new MySQL database and user and remember the credentials:

GRANT ALL ON dbname.* TO 'username' IDENTIFIED BY 'password';

Step 3 - Install client and obtain Let's Encrypt certificate (optional)

Securing your website with HTTPS is not necessary, but it is a good practice to secure your site traffic. In order to obtain TLS certificate from Let's Encrypt we will use client. is a pure UNIX shell software for obtaining TLS certificates from Let's Encrypt with zero dependencies. 

Download and install

sudo su - root
git clone
./ --install --accountemail [email protected]
source ~/.bashrc
cd ~

Check version: --version
# v2.8.1

Obtain RSA and ECC/ECDSA certificates for your domain/hostname:

# RSA 2048 --issue --standalone -d --keylength 2048
# ECDSA --issue --standalone -d --keylength ec-256

If you want fake certificates for testing you can add the --staging flag to the above commands.

After running the above commands, your certificates and keys will be in:

  • For RSA: /home/username/ directory.
  • For ECC/ECDSA: /home/username/example.com_ecc directory.

To list your issued certs you can run: --list

Create a directory to store your certs. We will use the /etc/letsencrypt directory.

mkdir -p /etc/letsecnrypt/
sudo mkdir -p /etc/letsencrypt/example.com_ecc

Install/copy certificates to /etc/letsencrypt directory.

# RSA --install-cert -d --cert-file /etc/letsencrypt/ --key-file /etc/letsencrypt/ --fullchain-file /etc/letsencrypt/ --reloadcmd "sudo systemctl reload nginx.service"
# ECC/ECDSA --install-cert -d --ecc --cert-file /etc/letsencrypt/example.com_ecc/cert.pem --key-file /etc/letsencrypt/example.com_ecc/private.key --fullchain-file /etc/letsencrypt/example.com_ecc/fullchain.pem --reloadcmd "sudo systemctl reload nginx.service"

All the certificates will be automatically renewed every 60 days.

After obtaining certs exit form the root user and return back to normal sudo user:


Step 4 - Install and configure Nginx

Install Nginx:

sudo apt install -y nginx

Check the Nginx version:

sudo nginx -v
# nginx version: nginx/1.14.0 (Ubuntu)

Configure Nginx for X-Cart by running:

sudo vim /etc/nginx/sites-available/xcart.conf

And populate the file with the below config.

server {
  listen 80;
  listen [::]:80;
  root /var/www/xcart;
  index index.php index.html index.htm;
  location @handler {
    index cart.php;
    rewrite ^/sitemap.xml(\?.+)?$ /cart.php?target=sitemap;
    rewrite ^/(.*)$ /cart.php?url=$1 last;
  location / {
    try_files $uri $uri/ @handler;
  location ~ \.php$ {
    try_files $uri @handler;
    fastcgi_split_path_info  ^(.+\.php)(/.+)$;
    fastcgi_index index.php;
    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    include fastcgi_params;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

Activate the new xcart.conf configuration by linking the file to the sites-enabled directory:

sudo ln -s /etc/nginx/sites-available/xcart.conf /etc/nginx/sites-enabled

Test the configuration:

sudo nginx -t

Reload Nginx:

sudo systemctl reload nginx

Step 5 - Install X-Cart

Navigate to the /var/www directory:

cd /var/www/

Download an X-Cart 5 package from this page:

Upload the downloaded package onto your server.

Change ownership of the /var/www/xcart directory to www-data:

sudo chown -R www-data:www-data /var/www/xcart

Navigate to in your web browser and follow the instructions to finish the installation.

Step 6 - Finish setup

Accept the license agreement and click Next.

X-Cart Installation Wizard

Create Administrator Account.

Create Admin account

The installation wizard will check whether your server meets the system requirements for X-Cart 5

Check system requirements

Configure database settings:

Database connection Details

Setting up Directories + Step 6. Building Cache. All the tasks at these steps are fully automated, so you just need to wait and let X-Cart 5 do the job

Updateing .htaccess

Now the installation process has been completed.  You can use the links provided to access your store’s Customer front end and Admin area. 

Installation complete

Share this page:

0 Comment(s)