PrestaShop Installation on Linux

PrestaShop is an open-source e-commerce platform known for ease of use, extensive module ecosystem, and lower resource requirements compared to enterprise solutions. Installation on Linux requires PHP 7.2+, MySQL 5.7+, and web server configuration. This guide covers comprehensive PrestaShop setup including system prerequisites, LEMP stack installation, SSL/TLS security, performance tuning, and best practices for production environments.

System Requirements

PrestaShop requires modern Linux infrastructure with sufficient resources. Verify your VPS meets minimum specifications.

Check system requirements:

# Check available RAM
free -h

# Check disk space
df -h /

# Check CPU cores
nproc

# Check Linux distribution
cat /etc/os-release

Recommended specifications for production PrestaShop:

  • RAM: 4-8GB minimum, 16GB+ for large catalogs
  • Storage: SSD with 50GB+ available space
  • CPU: 2+ cores
  • Distribution: Ubuntu 20.04 LTS or later, Debian 11+

Update system packages:

sudo apt update
sudo apt upgrade -y
sudo apt install curl wget git zip unzip vim htop build-essential -y

Create a dedicated user for PrestaShop:

sudo useradd -m -s /bin/bash prestashop
sudo usermod -aG www-data prestashop

LEMP Stack Setup

Install Linux, Nginx, MySQL, and PHP components required for PrestaShop.

Install Nginx web server:

sudo apt install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
sudo nginx -t

Create web root directory:

sudo mkdir -p /var/www/prestashop
sudo chown -R prestashop:www-data /var/www/prestashop
sudo chmod -R 755 /var/www/prestashop

Install MariaDB (MySQL compatible):

sudo apt install mariadb-server mariadb-client -y
sudo systemctl start mariadb
sudo systemctl enable mariadb

Secure MariaDB installation:

sudo mysql_secure_installation

# When prompted:
# Enter current password: press Enter (no password)
# Set root password: Choose secure password
# Remove anonymous users: y
# Disable root login remotely: y
# Remove test database: y
# Reload privilege tables: y

Create PrestaShop database:

sudo mysql -u root -p << EOF
CREATE DATABASE prestashop_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'prestashop_user'@'localhost' IDENTIFIED BY 'SecurePassword123!';
GRANT ALL PRIVILEGES ON prestashop_db.* TO 'prestashop_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
EOF

Install PHP 8.1 with required extensions:

# Add PHP repository
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update

# Install PHP and required extensions
sudo apt install php8.1 php8.1-fpm php8.1-mysql php8.1-curl php8.1-gd \
    php8.1-intl php8.1-json php8.1-xml php8.1-zip php8.1-mbstring \
    php8.1-soap php8.1-ldap php8.1-imagick php8.1-opcache php8.1-cli -y

# Start PHP-FPM
sudo systemctl start php8.1-fpm
sudo systemctl enable php8.1-fpm

Verify PHP extensions:

php -m | grep -E "curl|gd|intl|json|xml|zip|mbstring|soap"
php -v

PrestaShop Download and Installation

Download PrestaShop from official sources and prepare for installation.

Check latest PrestaShop version:

# Visit https://github.com/PrestaShop/PrestaShop/releases for latest version
VERSION="8.1.1"

cd /var/www/prestashop
sudo wget https://github.com/PrestaShop/PrestaShop/releases/download/${VERSION}/prestashop_${VERSION}.zip

sudo unzip prestashop_${VERSION}.zip
sudo rm prestashop_${VERSION}.zip

Extract PrestaShop files:

cd /var/www/prestashop
sudo unzip prestashop_${VERSION}.zip -d ./temp
sudo mv temp/* .
sudo rmdir temp

Set correct permissions:

# Set directory ownership
sudo chown -R www-data:www-data /var/www/prestashop

# Set file permissions
sudo find /var/www/prestashop -type f -exec chmod 644 {} \;
sudo find /var/www/prestashop -type d -exec chmod 755 {} \;

# Writable directories
sudo chmod -R 777 /var/www/prestashop/var
sudo chmod -R 777 /var/www/prestashop/cache
sudo chmod -R 777 /var/www/prestashop/config
sudo chmod -R 777 /var/www/prestashop/img
sudo chmod -R 777 /var/www/prestashop/modules
sudo chmod -R 777 /var/www/prestashop/override
sudo chmod -R 777 /var/www/prestashop/upload

Access PrestaShop installation wizard:

# Navigate to http://your-server-ip/install

# The installer will guide you through:
# 1. License acceptance
# 2. System compatibility check
# 3. Database configuration
# 4. Store information
# 5. Admin account setup

Or install via command line (if available in your version):

cd /var/www/prestashop

php install/console.php \
    --domain=example.com \
    --db_server=localhost \
    --db_name=prestashop_db \
    --db_user=prestashop_user \
    --db_password="SecurePassword123!" \
    --shop_name="My Store" \
    --firstname=Admin \
    --lastname=User \
    [email protected] \
    --password=AdminPassword123!

Remove installation directory after setup:

# CRITICAL: Remove installer to prevent unauthorized setup
sudo rm -rf /var/www/prestashop/install
sudo rm -rf /var/www/prestashop/api

Verify installation:

# Check configuration file exists
ls -la /var/www/prestashop/config/settings.inc.php

# Test database connection
mysql -u prestashop_user -p "SecurePassword123!" prestashop_db -e "SELECT 1;"

PHP Configuration

Optimize PHP settings for PrestaShop performance and security.

Edit PHP-FPM pool configuration:

sudo nano /etc/php/8.1/fpm/pool.d/www.conf

Apply optimized settings:

[www]
user = www-data
group = www-data
listen = /run/php/php8.1-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660

; Process management
pm = dynamic
pm.max_children = 32
pm.start_servers = 8
pm.min_spare_servers = 4
pm.max_spare_servers = 16
pm.max_requests = 5000

; Timeouts
request_terminate_timeout = 300
request_slowlog_timeout = 10s
slowlog = /var/log/php8.1-fpm-slow.log

Configure php.ini for PrestaShop:

sudo nano /etc/php/8.1/fpm/php.ini

Set essential parameters:

; Memory and execution limits
memory_limit = 256M
max_execution_time = 300
max_input_time = 300
upload_max_filesize = 128M
post_max_size = 128M

; Performance
realpath_cache_size = 2048K
realpath_cache_ttl = 3600
opcache.enable = 1
opcache.memory_consumption = 128
opcache.max_accelerated_files = 10000
opcache.validate_timestamps = 0

; Security
disable_functions = 
expose_php = Off
display_errors = Off
log_errors = On
error_log = /var/log/php8.1-fpm-errors.log

; Session handling
session.save_path = /var/lib/php/sessions
session.gc_maxlifetime = 28800
session.cookie_secure = On
session.cookie_httponly = On
session.cookie_samesite = Lax

Restart PHP-FPM:

sudo systemctl restart php8.1-fpm
sudo systemctl status php8.1-fpm

MySQL Optimization

Configure MySQL for efficient PrestaShop database operations.

Edit MySQL configuration:

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Apply production settings:

[mysqld]
; InnoDB settings
default-storage-engine = InnoDB
innodb_buffer_pool_size = 2G
innodb_log_file_size = 256M
innodb_flush_method = O_DIRECT
innodb_file_per_table = 1

; Connection settings
max_connections = 200
max_allowed_packet = 256M
connect_timeout = 10
wait_timeout = 600

; Performance
tmp_table_size = 256M
max_heap_table_size = 256M
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow-query.log
long_query_time = 2

Restart MySQL:

sudo systemctl restart mariadb
sudo systemctl status mariadb

Create important indexes:

mysql -u prestashop_user -p "SecurePassword123!" prestashop_db << EOF
-- Product search optimization
ALTER TABLE ps_product ADD INDEX idx_status (active);
ALTER TABLE ps_product ADD INDEX idx_visibility (visibility);

-- Order optimization
ALTER TABLE ps_orders ADD INDEX idx_customer_date (id_customer, date_add);
ALTER TABLE ps_orders ADD INDEX idx_status (current_state);

-- Checkout performance
ALTER TABLE ps_cart ADD INDEX idx_customer (id_customer);
ALTER TABLE ps_cart ADD INDEX idx_date (date_add);
EOF

Nginx Server Configuration

Configure Nginx to serve PrestaShop efficiently with proper rewrite rules.

Create Nginx configuration:

sudo nano /etc/nginx/sites-available/prestashop.conf

Apply optimized configuration:

upstream php_backend {
    server unix:/run/php/php8.1-fpm.sock;
}

server {
    listen 80;
    server_name example.com www.example.com;
    root /var/www/prestashop;
    index index.php index.html;

    access_log /var/log/nginx/prestashop_access.log;
    error_log /var/log/nginx/prestashop_error.log warn;

    # Security headers
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header X-XSS-Protection "1; mode=block" always;

    # Caching static files
    location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ {
        expires 365d;
        add_header Cache-Control "public, immutable";
    }

    # Block access to sensitive files
    location ~ /\. {
        deny all;
    }

    location ~ ~* "\.php$" {
        deny all;
    }

    location = /robots.txt {
        allow all;
    }

    location ~* "(.*)/\." {
        deny all;
    }

    # PrestaShop rewrite rules
    location / {
        rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;
        
        if (!-e $request_filename) {
            rewrite ^(.*)$ /index.php last;
        }
    }

    # PHP handler
    location ~ \.php$ {
        fastcgi_pass php_backend;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_param REMOTE_ADDR $http_x_forwarded_for;
    }

    # Admin panel
    location ~ ^/admin-custom/ {
        if (!-e $request_filename) {
            rewrite ^(.*)$ /admin-custom/index.php last;
        }
    }
}

Enable Nginx configuration:

sudo ln -s /etc/nginx/sites-available/prestashop.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

SSL/TLS Implementation

Secure PrestaShop with SSL/TLS encryption using Let's Encrypt.

Install Certbot:

sudo apt install certbot python3-certbot-nginx -y

Obtain SSL certificate:

sudo certbot certonly --nginx -d example.com -d www.example.com

Update Nginx configuration with SSL:

sudo nano /etc/nginx/sites-available/prestashop.conf

Add SSL configuration:

# Redirect HTTP to HTTPS
server {
    listen 80;
    server_name example.com www.example.com;
    return 301 https://$server_name$request_uri;
}

# HTTPS server
server {
    listen 443 ssl http2;
    server_name example.com www.example.com;
    
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    
    # SSL configuration
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    
    # Security headers
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Content-Type-Options "nosniff" always;
    
    # ... rest of server configuration ...
}

Configure automatic renewal:

# Certbot auto-renewal is configured by default
# Verify renewal service
sudo systemctl status certbot.timer

# Test renewal
sudo certbot renew --dry-run

Update PrestaShop settings for HTTPS:

mysql -u prestashop_user -p "SecurePassword123!" prestashop_db << EOF
UPDATE ps_configuration SET value = 'https://example.com/' WHERE name = 'PS_SHOP_DOMAIN_SSL';
UPDATE ps_configuration SET value = 'https://example.com/' WHERE name = 'PS_BASE_URL_SSL';
UPDATE ps_configuration SET value = 1 WHERE name = 'PS_SSL_ENABLED';
EOF

Reload Nginx:

sudo nginx -t
sudo systemctl reload nginx

Performance Optimization

Implement caching and optimization techniques for PrestaShop.

Install and configure caching:

# Enable PrestaShop's built-in caching
mysql -u prestashop_user -p "SecurePassword123!" prestashop_db << EOF
UPDATE ps_configuration SET value = 'CacheMemcache' WHERE name = 'PS_CACHING';
UPDATE ps_configuration SET value = 'localhost' WHERE name = 'PS_CACHE_HOST';
UPDATE ps_configuration SET value = '11211' WHERE name = 'PS_CACHE_PORT';
EOF

Or use file-based caching:

mysql -u prestashop_user -p "SecurePassword123!" prestashop_db << EOF
UPDATE ps_configuration SET value = 'CacheFS' WHERE name = 'PS_CACHING';
EOF

Enable image optimization:

# Install ImageMagick
sudo apt install imagemagick -y

# PrestaShop will use ImageMagick for image processing
# Configure in admin panel: Performance > Image generation

Optimize database:

# Regular maintenance
mysql -u prestashop_user -p "SecurePassword123!" prestashop_db << EOF
OPTIMIZE TABLE ps_product;
OPTIMIZE TABLE ps_product_attribute;
OPTIMIZE TABLE ps_category_product;
OPTIMIZE TABLE ps_orders;
OPTIMIZE TABLE ps_order_detail;
OPTIMIZE TABLE ps_cart;
OPTIMIZE TABLE ps_cart_product;
EOF

Create a maintenance script:

cat > /usr/local/bin/prestashop-maintenance.sh << 'EOF'
#!/bin/bash

# Database optimization
mysql -u prestashop_user -p "SecurePassword123!" prestashop_db << SQL
OPTIMIZE TABLE ps_product;
OPTIMIZE TABLE ps_orders;
OPTIMIZE TABLE ps_cart;
SQL

# Clear unnecessary caches
rm -rf /var/www/prestashop/var/cache/*
rm -rf /var/www/prestashop/var/logs/*

# Archive old logs
gzip /var/log/nginx/prestashop_access.log
gzip /var/log/php8.1-fpm-slow.log

echo "PrestaShop maintenance completed: $(date)" >> /var/log/prestashop-maintenance.log
EOF

sudo chmod +x /usr/local/bin/prestashop-maintenance.sh

Schedule maintenance:

sudo crontab -e

# Add daily maintenance at 2 AM
0 2 * * * /usr/local/bin/prestashop-maintenance.sh

Security Hardening

Implement security best practices to protect your PrestaShop installation.

Change default admin URL:

mysql -u prestashop_user -p "SecurePassword123!" prestashop_db << EOF
UPDATE ps_configuration SET value = 'admin-custom-path' WHERE name = 'PS_ADMIN_FOLDER';
EOF

Update Nginx configuration:

# Update admin location
location ~ ^/admin-custom-path/ {
    if (!-e $request_filename) {
        rewrite ^(.*)$ /admin-custom-path/index.php last;
    }
}

Set up WAF rules:

# Block common attack patterns
if ($request_uri ~* "\.\.") {
    return 403;
}

if ($request_uri ~* "drop database|insert |update |delete |select ") {
    return 403;
}

if ($request_method = "TRACE") {
    return 403;
}

Enable two-factor authentication in admin:

# PrestaShop provides 2FA in admin panel
# Navigate to: Advanced Parameters > Admin > 2FA

Regular backups:

cat > /usr/local/bin/prestashop-backup.sh << 'EOF'
#!/bin/bash

BACKUP_DIR="/backups/prestashop"
SHOP_DIR="/var/www/prestashop"
DB_NAME="prestashop_db"
DB_USER="prestashop_user"
DB_PASS="SecurePassword123!"

mkdir -p $BACKUP_DIR

# Backup database
mysqldump -u $DB_USER -p$DB_PASS $DB_NAME | gzip > $BACKUP_DIR/db-$(date +%Y%m%d-%H%M%S).sql.gz

# Backup files
tar czf $BACKUP_DIR/files-$(date +%Y%m%d-%H%M%S).tar.gz -C /var/www prestashop

# Keep only 30 days of backups
find $BACKUP_DIR -type f -mtime +30 -delete

echo "PrestaShop backup completed: $(date)" >> /var/log/prestashop-backup.log
EOF

sudo chmod +x /usr/local/bin/prestashop-backup.sh

Schedule backups:

# Run backups daily
sudo crontab -e

0 3 * * * /usr/local/bin/prestashop-backup.sh

Conclusion

PrestaShop installation on Linux requires proper system preparation, correct LEMP stack configuration, and security hardening. This guide covers complete setup from system prerequisites through SSL/TLS implementation and performance optimization. Following these steps creates a robust, secure, and performant PrestaShop store ready for production traffic. Regular maintenance, backups, and monitoring ensure continued reliability and security as your store grows.