patch - Environment Patching

Apply local environment configurations to cloned files and database dumps for optimal local development.

Purpose

The patch command modifies cloned shop files and database configurations to work correctly in your local development environment, ensuring seamless integration between remote code and local infrastructure.

When to Use

  • After cloning shop files: Configure files for local environment after clone command
  • After database dump: Prepare database settings for local database server
  • Environment changes: When local environment settings change (URLs, database credentials)
  • Development setup: As part of automated local environment preparation

Prerequisites

Before running the patch command:

  1. Authentication: Must be authenticated with ps-enterprise auth
  2. Configuration: Must have valid environment configuration from ps-enterprise config
  3. Remote Dump: It is required to run ps-enterprise remote-dump to get the database state
  4. Clone: Must have shop files cloned locally using ps-enterprise clone

Usage

Basic Patching

ps-enterprise patch

Options

Flag Short Description Required
--help -h Show command help No

Process

The patch command performs several modifications to prepare your environment for local development:

1. Database Configuration

  • Connection Settings: Updates database connection parameters for local database server
  • Host Configuration: Changes database host from remote to local container
  • Credentials: Applies local database username and password
  • Port Mapping: Configures correct port mapping for local database access

2. URL Rewriting

  • Base URLs: Updates shop base URLs to local development URLs
  • Asset URLs: Modifies asset and media URLs for local access
  • API Endpoints: Configures API endpoints to work with local environment
  • SSL Settings: Adjusts SSL/TLS settings for local development

3. Apache Configuration (.htaccess)

  • Rewrite Rules: Modifies URL rewrite rules for local environment
  • Directory Paths: Updates file paths for local directory structure
  • Development Mode: Enables development-friendly Apache settings
  • Error Handling: Configures local error handling and debugging

4. Database Queries

  • Pre-dump Queries: Executes necessary queries before database import
  • Post-dump Queries: Runs cleanup and configuration queries after import
  • Local Settings: Applies local-specific database configurations
  • Development Data: Injects development-specific data and settings

5. File Permissions

  • Web Server Access: Sets appropriate permissions for web server access
  • File Ownership: Configures correct file ownership for local environment
  • Directory Permissions: Ensures directories have correct read/write permissions
  • Security Settings: Applies development-appropriate security permissions

Examples

Standard Development Setup

# Complete local environment setup
ps-enterprise remote-dump    # Get database dump
ps-enterprise clone          # Get shop files
ps-enterprise patch          # Apply local configurations

# Files and database are now ready for local development

Retrieve Remote Database Changes

ps-enterprise stop           # Stop local environment
ps-enterprise remote-dump    # Update database
ps-enterprise patch          # Re-apply patches with new settings
ps-enterprise start          # Start local environment

Files Modified

The patch command modifies several types of files:

Configuration Files

  • app/config/parameters.yml - Database and system configuration
  • config/defines.inc.php - PrestaShop core definitions
  • .htaccess - Apache URL rewriting and security rules
Do Not Commit: The changes made by the patch command are specific to your local environment. Do not commit these modified files to your version control system (e.g., Git). They should be ignored to avoid conflicts and issues in production or other environments.

Database Modifications

Pre-dump Queries

Executed before database import:

-- Disable foreign key checks for import
SET FOREIGN_KEY_CHECKS=0;
SET UNIQUE_CHECKS=0;
SET AUTOCOMMIT=0;

Post-dump Queries

Executed after database import:

-- Update shop URLs
UPDATE ps_configuration SET value='http://localhost:8080/' WHERE name='PS_SHOP_DOMAIN';
UPDATE ps_configuration SET value='http://localhost:8080/' WHERE name='PS_SHOP_DOMAIN_SSL';

-- Enable development mode
UPDATE ps_configuration SET value='1' WHERE name='PS_MODE_DEV';

-- Re-enable checks
SET FOREIGN_KEY_CHECKS=1;
SET UNIQUE_CHECKS=1;
COMMIT;

Success Indicators

After successful patching:

✓ Database configuration updated
✓ URL rewriting configured
✓ .htaccess modified for local environment
✓ Database queries prepared
✓ File permissions set
✓ Local environment ready

Troubleshooting

Missing Shop Files

❌ Shop files not found. Please run 'ps-enterprise clone' first.

Solution: Run the clone command to download shop files before patching.

Database Dump Not Found

❌ Database dump not found at ./tmp/dump.sql

Solution: Run ps-enterprise remote-dump to create database dump before patching.

File Permission Error

❌ Permission denied: Cannot modify configuration files

Solution: Check and fix file permissions.

Invalid Local Configuration

❌ Invalid local configuration. Please run 'ps-enterprise config'.

Solution: Re-run the configuration command to ensure valid local settings.

  • clone - Must be run before patching (provides files to patch)
  • remote-dump - Usually run before patching (provides database to patch)
  • config - Provides configuration used by patch process
  • start - Uses patched files to start local environment

Local Only: Patched files and configurations are designed for local development only. Never deploy patched configurations to production environments.