Streamlining PrestaShop 9 Local Development with Docker
Mastering PrestaShop 9 Local Development with Docker
Setting up a robust local development environment is crucial for any PrestaShop developer, especially when working on modules, themes, or core modifications. A recent PrestaShop forum thread, initiated by Knowband Plugins, provides an excellent, detailed walkthrough on how to leverage Docker for a streamlined PrestaShop 9 local setup. This approach emphasizes isolation, reproducibility, and ease of management, making it highly valuable for developers.
Why Docker for PrestaShop 9 Local Development?
The primary goal of using Docker is to create an isolated, disposable development environment. This means you can spin up a PrestaShop instance with its database, make changes, test, and then easily discard or reset it without affecting your host machine. This is particularly beneficial for:
- Module and Theme Development: Quickly test changes in a clean environment.
- Core Work: Experiment with PrestaShop core modifications without risk.
- Version Management: Easily switch between different PrestaShop or PHP versions.
The guide focuses on using the official PrestaShop Docker image with Docker Compose, providing a simple yet powerful stack for local work, explicitly excluding production use cases.
Key Prerequisites and Setup Steps
Before diving in, ensure you have Docker with Compose installed (Docker Desktop for Windows/macOS, or the Compose plugin for Linux). A free host port (commonly 8080) is also needed. For PrestaShop 9.2.0, the recommended PHP versions range from 8.1 to 8.5, and MySQL 5.7+ or MariaDB 10.2+ for the database.
1. Choosing Your Image Tag
The thread highlights the importance of pinning specific image versions (e.g., prestashop/prestashop:9.2.0-8.4) rather than using latest to ensure consistency. This combines the PrestaShop version with the desired PHP version.
2. Defining Services with Docker Compose
A docker-compose.yml file orchestrates the services. The core setup involves a database service (MySQL 8.0 is recommended) and the PrestaShop application service.
services:
db:
image: mysql:8.0
environment:
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
MYSQL_DATABASE: prestashop
MYSQL_USER: ps_app
MYSQL_PASSWORD: change_this_locally
volumes:
- db_data:/var/lib/mysql
healthcheck:
test: ["CMD-SHELL", "mysqladmin ping -h 127.0.0.1 -u $$MYSQL_USER --password=$$MYSQL_PASSWORD"]
interval: 5s
timeout: 4s
retries: 12
prestashop:
image: prestashop/prestashop:9.2.0-8.4
depends_on:
db:
condition: service_healthy
ports:
- "8080:80"
environment:
DB_SERVER: db
DB_NAME: prestashop
DB_USER: ps_app
DB_PASSWD: change_this_locally
PS_INSTALL_AUTO: 1
PS_DOMAIN: localhost:8080
PS_DEV_MODE: 1
PS_FOLDER_ADMIN: admin-dev
ADMIN_MAIL: admin@example.com
ADMIN_PASSWD: change_this_too
volumes:
- ps_data:/var/www/html
- ./modules/mymodule:/var/www/html/modules/mymodule
volumes:
db_data:
ps_data:Crucially, environment variables like PS_INSTALL_AUTO: 1 automate the installation, and PS_DEV_MODE: 1 enables developer mode. The volumes section ensures that database data persists and, more importantly for developers, allows a specific module folder (e.g., ./modules/mymodule) on your host machine to be directly mounted into the container. This enables real-time editing without rebuilding the Docker image.
Running and Developing
To start your PrestaShop instance, simply run docker compose up -d. The front office will be accessible at http://localhost:8080 and the back office at http://localhost:8080/admin-dev (using the credentials defined in your compose file). You can confirm module mounting with docker compose exec prestashop ls /var/www/html/modules/mymodule.
For console commands (like enabling modules), use docker compose exec prestashop php bin/console prestashop:module enable mymodule. If you need to start fresh, docker compose down -v will remove containers and volumes, allowing a clean reinstall.
Addressing Common Issues and Workflow Tips
The original post proactively addresses common problems such as port conflicts, redirection issues (emphasizing PS_DOMAIN matching the browser URL), database connection failures, and MySQL 8 authentication/charset errors, offering clear solutions.
A valuable tip from the replies (by Knowband Plugins) reminds developers to check file permissions on mounted module folders if modules encounter writing issues, as these permissions are inherited from the host machine.
The thread also briefly compares this official image approach with Laradock, suggesting the official image is better for single, isolated shops, while Laradock suits environments with multiple PHP projects.
Conclusion
This detailed guide provides an invaluable resource for PrestaShop 9 developers looking to adopt Docker for their local environments. The step-by-step instructions, practical tips, and troubleshooting advice make it an excellent foundation for efficient module and theme development. The community feedback reinforces the utility of this approach, particularly the time-saving benefits of mounted volumes for iterative development.