Skip to main content
page last edited on 5 October 2022

Server Setup

Version: 5.5

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 5.4-based application, the general software setup is similar to Symfony despite minor alterations. Hence you can refer to the Symfony 5.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.

If you upgraded your software from X-Cart 5.4.1.x and need to reconfigure the server, don't forget to adjust the XCART_PUBLIC_DIR variable in the .env.local file on the server.

XCART_PUBLIC_DIR=0

After that, redeploy the store on the System → Cache Management page of your store's Admin area or use the ./bin/service xcst:rebuild operation in the console.

Apache

The example configuration to get your application running under Apache 2.4 with PHP-FPM:

## X-Cart 5 apache 2.4 sample configuration
#
# Replace placeholders:
# {{public-full-path}} - real full path of public dir
#
# Example
#
# Xcart installation path: /var/www/xcart
# Expected URL: https://localhost/
#
# public-full-path: /var/www/xcart/public
#

LoadModule proxy_module lib/httpd/modules/mod_proxy.so
LoadModule proxy_fcgi_module lib/httpd/modules/mod_proxy_fcgi.so
LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so

ServerName xcart.test

<VirtualHost *:80>
ServerAdmin admin@example.com

DocumentRoot {{public-full-path}}

<Directory {{public-full-path}}>
DirectoryIndex index.php

Options Indexes FollowSymLinks
AllowOverride All
Require all granted
FallbackResource /index.php

<IfModule mod_rewrite.c>
Options -MultiViews

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>

</Directory>

<FilesMatch ".php$">
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>

</VirtualHost>

Please carefully check the above configuration sample and adapt it to your server environment.

You can find the sample of an Apache server configuration for a store located in a subfolder but not in the domain root in the /docs folder of the software package.

Nginx

The example configuration to get your application running under Nginx with PHP-FPM:

## X-Cart 5 nginx sample configuration
## Copy this file to your /etc/nginx directory
## and include it in your nginx.conf

#
# Replace placeholders:
# {{public-full-path}} - real full path of public dir
#
# Example
#
# Xcart installation path: /var/www/xcart
# Expected URL: https://localhost
#
# 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/php/php8.0-fpm.sock;
}

server {
listen 80 default_server;
server_name xcart.test;
root {{public-full-path}};

index index.php;
charset UTF-8;

location ~ /service.php/ {
# try to serve file directly, fallback to service.php
try_files $uri $uri/ /service.php?$query_string;
}

location / {
# try to serve file directly, fallback to index.php
try_files $uri $uri/ /index.php?$query_string;
}

location ~ \.php(/|$) {
fastcgi_pass fastcgi_xcart;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;

fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
# 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;
}

location ~ \.(jpg|jpeg|png|gif|)$ {
try_files $uri =404;
break;
}
}

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.