exec - Execute Commands in Containers

Run shell commands inside your local PrestaShop Enterprise development environment web container.

Purpose

The exec command provides direct access to running container, allowing you to execute commands within the containerized environment for debugging, maintenance, development tasks, and system administration.

When to Use

  • Debugging container issues: Investigate problems within the container environment
  • Running maintenance scripts: Execute database maintenance or cleanup tasks
  • Inspecting file system: Browse and examine files within containers
  • Database operations: Run direct database queries or maintenance commands
  • Development tasks: Execute composer, npm, or other development tools
  • System administration: Perform container administration tasks

Prerequisites

Before running the exec command:

  1. Running Environment: Local environment must be started with ps-enterprise start
  2. Active Containers: Web container must be running and healthy

Usage

Execute Specific Command

# Run specific command in container
ps-enterprise exec "ls -la /var/www/html"

Interactive Shell Access

# Open interactive shell in container
ps-enterprise exec --interactive

Interactive Shell with Specific User

# Open interactive bash shell using www-data user
ps-enterprise exec --interactive "sudo -u www-data bash"

Command with Specific Shell

# Use bash for command execution
ps-enterprise exec --shell=bash "composer install"

Options

Flag Short Description Required
--interactive Open interactive shell session No
--shell=<shell> Specify shell to use (sh, bash, zsh) No
--static Display static logs instead of live streaming No
--help -h Show command help No

Examples

File System Operations

# List files in web root
ps-enterprise exec "ls -la /var/www/html"

# Check disk usage
ps-enterprise exec "df -h"

# Find specific files
ps-enterprise exec "find /var/www/html -name '*.php' -type f"

# Check file permissions
ps-enterprise exec "ls -la /var/www/html/app/config/"

PHP and Composer Operations

# Check PHP version and configuration
ps-enterprise exec "php -v"
ps-enterprise exec "php -i | grep memory_limit"

# Run Composer commands
ps-enterprise exec "composer --version"
ps-enterprise exec "composer install --no-dev"
ps-enterprise exec "composer update specific/package"

# Execute PHP scripts
ps-enterprise exec "php /var/www/html/bin/console cache:clear"

Database Operations

# Connect to database
ps-enterprise exec "mysql -u prestashop -pprestashop prestashop"

# Run specific database queries
ps-enterprise exec "mysql -u prestashop -pprestashop prestashop -e 'SHOW TABLES;'"

# Database maintenance
ps-enterprise exec "mysql -u prestashop -pprestashop prestashop -e 'OPTIMIZE TABLE ps_configuration;'"

PrestaShop Specific Commands

# Clear PrestaShop cache
ps-enterprise exec "rm -rf /var/www/html/var/cache/*"

# Check PrestaShop installation
ps-enterprise exec "php /var/www/html/bin/console prestashop:version"

# Run PrestaShop CLI commands (if available)
ps-enterprise exec "php /var/www/html/bin/console module:install mymodule"

Interactive Shell Sessions

# Open interactive shell for extended work
ps-enterprise exec --interactive

# Inside container shell, you can run multiple commands:
$ cd /var/www/html
$ ls -la
$ composer install
$ php bin/console cache:clear
$ exit

Development Tools

# Install development dependencies
ps-enterprise exec "composer install --dev"

# Run code quality tools (if configured)
ps-enterprise exec "vendor/bin/phpcs --standard=PSR12 modules/mymodule/"
ps-enterprise exec "vendor/bin/phpstan analyse modules/mymodule/"

# Run tests (if configured)
ps-enterprise exec "vendor/bin/phpunit tests/"

Advanced Usage

Environment Variables

# Set environment variables for command execution
ps-enterprise exec "export DEBUG=true && php script.php"

# Use environment variables in commands
ps-enterprise exec "echo \$PATH"

File Transfer Operations

# Create files inside container
ps-enterprise exec "echo 'test content' > /tmp/test.txt"

# Copy files within container
ps-enterprise exec "cp /var/www/html/config/config.inc.php /tmp/backup.php"

# Modify file permissions
ps-enterprise exec "chmod 755 /var/www/html/bin/console"
ps-enterprise exec "chown www-data:www-data /var/www/html/var/logs/"

System Information

# Check system information
ps-enterprise exec "uname -a"
ps-enterprise exec "cat /etc/os-release"

# Check running processes
ps-enterprise exec "ps aux"

# Check network configuration
ps-enterprise exec "netstat -tulpn"

# Check service status
ps-enterprise exec "service apache2 status"

Troubleshooting

Container Not Running

❌ No running containers found for project
Please run 'ps-enterprise start' first

Solution: Start the environment before executing commands.

Command Not Found

❌ Command 'composer' not found in container

Solution:

  • Verify the command is installed in the container
  • Use full path: /usr/local/bin/composer
  • Install the required tool if possible

Permission Denied

❌ Permission denied: cannot access '/root/.composer'

Solution:

  • Switch to appropriate user: su www-data
  • Modify permissions: chmod 755 /path/to/directory
  • Run with different user context

Shell Not Available

❌ Shell 'zsh' not found in container

Solution: Use available shell like bash or sh.

Integration with Development Workflow

Debugging Workflow

# Start environment and begin debugging
ps-enterprise start
ps-enterprise log &  # Monitor logs in background

# Execute debugging commands
ps-enterprise exec "tail -f /var/log/apache2/error.log"
ps-enterprise exec "php -l /var/www/html/modules/mymodule/mymodule.php"

Development Tasks

# Install new dependencies
ps-enterprise exec "composer require vendor/package"

# Run development tools
ps-enterprise exec "vendor/bin/phpcs modules/mymodule/"

# Clear caches and test
ps-enterprise exec "rm -rf var/cache/* && php bin/console cache:warmup"

Maintenance Operations

# Database maintenance
ps-enterprise exec "mysql -u prestashop -pprestashop prestashop -e 'OPTIMIZE TABLE ps_log;'"

# File system maintenance
ps-enterprise exec "find /var/www/html/var/logs -name '*.log' -mtime +7 -delete"

# Permission fixes
ps-enterprise exec "chown -R www-data:www-data /var/www/html/var/"
  • start - Must be run first to have containers available for exec
  • log - Use alongside exec for debugging (monitor logs while executing commands)
  • stop - Stops containers, making exec unavailable
  • Development workflow integrates exec for container-based development tasks

Container Context: Commands executed with exec run inside the containerized environment with the container’s file system, network, and user context.
Pro Tip: Use --interactive flag for extended debugging sessions where you need to run multiple commands and explore the container environment.
Temporary Changes: Most changes made inside containers are temporary and will be lost when containers are recreated, unless they affect mounted volumes or persistent data.