Linux Commands and Scripts

Easy to Install X-Cart 5 on CentOS 8

In this tutorial, we will show you how to it is easy to install X-Cart 5 on CentOS 8.

X-Cart is a commercial open source shopping cart platform distributed through the SaaS solution, or via download package.  It is is an extremely flexible open-source eCommerce platform with tons of features and integrations. X-Cart source code is hosted on Github.

Prerequisites:

  • CentOS 8 dedicated server or VPS
  • PHP version 7.2 or higher
  • PHP extensions: pdopharmysqlmbstringcurl
  • MySQL version 5.7.7 or higher or MariaDB equivalent
  • Nginx web server
  • A root user access or normal user with administrative privileges.

Step 1 – Keep the server up to date

# yum update -y

Install the required packages.

# dnf install socat git -y

Step 2 – Install PHP

By default, CentOS 8 install PHP 7.2 and PHP 7.3. In order to install PHP 7.4 first, we need to install Remi repository,  which will provide the PHP 7.4 packages we want to install along with some handy package management utilities.

# dnf install http://rpms.remirepo.net/enterprise/remi-release-8.rpm -y

Next, in order to enable the PHP remi-7.4 stream run the following dnf commands.

# dnf module reset php -y

# dnf module enable php:remi-7.4 -y

Install PHP 7.4

# dnf install php php-cli php-fpm php-common php-mbstring php-curl php-mysqlnd php-json php-xml php-phar php-pdo php-gd -y

To verify the installation check the version of the PHP using following command:

# php -v

Output will similar like this:

PHP 7.4.6 (cli) (built: Oct 12 2020 08:09:15) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.6, Copyright (c), by Zend Technologies
We have successfully install PHP 7.4.

Start and enable PHP-FPM.

# systemctl start php-fpm.service

# systemctl enable php-fpm.service

Step 3 – Install MariaDB

# dnf install -y mariadb-server

Check the version.

# mysql –version

Output

# mysql Ver 15.1 Distrib 10.3.17-MariaDB, for Linux (x86_64) using readline 5.1

Start and enable MariaDB.

# systemctl start mariadb.service
# systemctl enable mariadb.service

Run the mysql_secure_installation script to improve the security of your MariaDB installation.

# mysql_secure_installation

Log into MariaDB as the root user.

# mysql -u root -p

Create a new MariaDB database and user and remember the credentials.

CREATE DATABASE dbname;
GRANT ALL ON dbname.* TO ‘username’ IDENTIFIED BY ‘password’;
FLUSH PRIVILEGES;
exit;

Step 4 – Install Nginx

# dnf install -y nginx

Check the version.

# nginx -v

Start and enable Nginx.

# systemctl start nginx.service
# systemctl enable nginx.service

Configure Nginx for use with the X-Cart.

vi /etc/nginx/conf.d/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;
server_name example.com;
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-fpm/www.sock;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}

Test the configuration.

# nginx -t

Reload Nginx.

# systemctl reload nginx.service

Step 5 – Install X-Cart

Navigate to the /var/www directory.

# cd /var/www/

Download an X-Cart 5 package from this page: http://www.x-cart.com/download.html

Upload the X-Cart package to your server using SFTP or scp (for Linux user)

Place the file in your /var/www/ directory. In this example, the filename is x-cart-5.4.1.16-en.tgz, yours may be different.

Extract the X-Cart package.

# tar -xzpf x-cart-5.4.1.16-en.tgz
# rm x-cart-5.4.1.16-en.tgz

Change ownership of the /var/www/xcart directory to nginx

# chown -R nginx:nginx /var/www/xcart

Run sudo vim /etc/php-fpm.d/www.conf and set the user and group to nginx. Initially, they will be set to apache.

# vi /etc/php-fpm.d/www.conf

Find user = and group = and change there value to nginx

user = nginx
group = nginx

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

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

Restart the PHP-FPM service.

#  systemctl restart php-fpm.service

Navigate to example.com/install.php in your web browser and follow the instructions to finish the installation.

We have successfully installed X-Cart 5 on CentOS 8.

We have shown you how to it is easy to install X-Cart 5 on CentOS 8.

Related Articles