You can find samples of the nginx and apache setup in the /docs folder of the X-Cart software package.
Since X-Cart is a Symfony 6.4-based application, the general software setup is similar to Symfony despite minor alterations. Hence you can refer to the Symfony 6.4 official documentation in addition to this article.
The public directory
The public directory is the home of your application's public and static files, including images, stylesheets, and JavaScript files. It is also where the front controller (index.php
) lives.
The server document root must be configured in the /public subfolder of your X-Cart root. You must also ensure both index.php
and service.php
are executable.
Nginx
Below is the example configuration to get your application running under Nginx with PHP-FPM.
If you have X-Cart installed into a web directory, see the web directory example configuration.
## X-Cart 5 nginx sample configuration
## Copy this file to your /etc/nginx directory
## and include it to your nginx.conf
#
# Replace placeholders:
# {{projects-dir}} - real full path of projects dir
#
# Example
#
# Projects dir installation path: /var/www/projects
# Some X-Cart store installation path (git clone root): /var/www/projects/xcart1
# Some other X-Cart store installation path (git clone root): /var/www/projects/xcart2
# Expected URL of first store: https://localhost/xcart1/src/public/
# Expected URL of second store: https://localhost/xcart2/src/public/
#
upstream fastcgi_xcart {
# use tcp connection
server 127.0.0.1:9000;
# or socket
# server unix:/var/run/php5-fpm.sock;
# server unix:/var/run/php/php7.0-fpm.sock;
}
server {
server_name xcart.test;
root {{projects-dir}};
index index.php;
charset UTF-8;
location ~ /service\.php/ {
try_files $uri $uri/ @handler2;
}
location @handler2 {
rewrite ^/(.*src)\/service\.php\/(.*)$ /$1/service.php?$query_string last;
}
location / {
try_files $uri $uri/ @handler;
}
location @handler {
rewrite ^/(.*src)\/(.*)$ /$1/index.php?$query_string last;
}
location ~ \.php(/|$) {
fastcgi_pass fastcgi_xcart;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_read_timeout 300;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REDIRECT_STATUS 200;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
location ~ \.(jpg|jpeg|png|gif|woff|woff2|ttf)$ {
try_files $uri =404;
break;
}
}
Web directory
## X-Cart 5 nginx sample configuration
## Copy this file to your /etc/nginx directory
## and include it to your nginx.conf
##
## This configuration is prepared for the following server setup:
## Wordpress in the root of the domain
## XCart in web-dir
#
# Replace placeholders:
# {{web-dir}} - XCart web dir value
# {{root-full-path}} - real full path of host handler app (Wordpress)
# {{public-full-path}} - real full path of XCart public dir
#
# Example
#
# Host handler app path (Wordpress) : /var/www/http
# XCart installation path: /var/www/xcart
# Expected XCart URL: https://localhost/shop
#
# web-dir: /shop
# root-full-path: /var/www/http
# public-full-path: /var/www/xcart/public
#
upstream fastcgi_xcart {
# use tcp connection
server 127.0.0.1:9000;
# or socket
# server unix:/var/run/php5-fpm.sock;
# server unix:/var/run/php/php7.0-fpm.sock;
}
upstream fastcgi_other {
# use tcp connection
server 127.0.0.1:9000;
# or socket
# server unix:/var/run/php5-fpm.sock;
# server unix:/var/run/php/php7.0-fpm.sock;
}
# To use virtual web_dir with symfony routing and service-tool is is required to move web_dir from prefix to suffix
map $request_uri $real_request_uri {
~^{{web-dir}}(?:/service.php)([^?]*)(\?.*)?$ "/service.php{{web-dir}}$1";
~^{{web-dir}}(?:/\w+\.php)?([^?]*)(\?.*)?$ "{{web-dir}}$1";
default $request_uri;
}
# Determinate real file path
map $request_uri $real_file {
~^{{web-dir}}(?:/\w+\.php)?([^?]*)(\?.*)?$ $1;
default $request_uri;
}
server {
listen 80 default_server;
server_name xcart.test;
root {{root-full-path}};
index index.php;
charset UTF-8;
# Static files must not be processd trough fastcgi handler
location ~ {{web-dir}}(/.*\.(jpg|jpeg|png|gif|woff|woff2|ttf))$ {
alias {{public-full-path}};
try_files $1 =404;
break;
}
# Route index.php and service.php to the fastcgi handler
location ~ ^{{web-dir}}/(index|service)\.php {
alias {{public-full-path}};
try_files $real_file @handler;
}
# Route cleanurls to index.php
location ~ ^{{web-dir}}/ {
alias {{public-full-path}};
rewrite ^{{web-dir}}(.*)$ {{web-dir}}/index.php$1;
}
# XCart 5.5 handler (web-dir)
location @handler {
fastcgi_pass fastcgi_xcart;
fastcgi_split_path_info ^{{web-dir}}/(.+\.php)?(.*)$;
include fastcgi_params;
# Set real FS path
fastcgi_param SCRIPT_FILENAME {{public-full-path}}/$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT {{public-full-path}};
fastcgi_param REQUEST_URI {{web-dir}}/$fastcgi_script_name$fastcgi_path_info?$query_string;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/index.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
# host handler (w/o web-dir)
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php(/|$) {
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass fastcgi_xcart;
#The following parameter can be also included in fastcgi_params file
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Please carefully check the above configuration sample and adapt it to your server environment.
You can find the sample of an Nginx server configuration for a store located in a subfolder but not in the domain root in the /docs folder of the software package.