It's a simply as possible docker-compose
stack to run a
Prestashop for development and for
production.
To run this you just need a docker and docker-compose.
You can install a fresh instance of Prestashop or restore your already installed shop from dump/backup.
When you want to run fresh instance of prestashop:
- Create a .env file (use .env.dist as starter file,
cp .env.dist .env
) and setup values. - Run
docker-compose up [-d]
. - Wait for download and build images.
- Wait for install a fresh Prestashop instance.
- Goto PS_DOMAIN:PRESTASHOP_PORT domain and play with your new shop.
When you have a dump of your already installed Prestashop instance:
- Create a .env file (use .env.dist as starter file,
cp .env.dist .env
) and setup required values:DB_PREFIX
(database_prefix
),MYSQL_DATABASE
(database_name
),MYSQL_PASSWORD
(database_password
),MYSQL_USER
(database_user
). They should have the same values as in app/config/parameters.php.
- Move your database dump file(s) into initdb.d/ directory.
- Move your files into prestashop/ directory.
- Run
docker-compose up [-d]
. - Wait for download and build images.
- Wait when
db
service will load dump file(s) into the database. Note! When you goto the shop before database is loaded you will got an error. Please be patient and wait for database. - Goto http://localhost/ domain and play with your new shop.
If you want to run production environment
- Uncomment line
#COMPOSE_FILE=docker-compose.yml:docker-compose.prod.yml
in .env file. It tells todocker-compose
to use those files instead of default docker-compose.yml and docker-compose.override.yml (they're good for development). - Rebuild images with
docker-compose build [--pull]
. - Run new stack
docker-compose up [-d]
.
PRESTASHOP_HOST
allow to change a host on which nginx
services is
listening. Default it's 127.0.0.1
so only you can connect from your local
machine to the shop. Setup 0.0.0.0
to allow others from the same network to
connect to your shop (for example to test shop on your mobile).
Other environments are described here.
Setup redis as a session handler can increase some server performance. To do it
edit your .env file. Add :docker/redis/compose.yml
to COMPOSE_FILE
environment.
You can also change other environments:
REDIS_HOST_PASSWORD=!ChangeMe!
REDIS_IMAGE=extalion/prestashop_redis
From time to time is good to clean database from old records in specific tables.
To do that there's a command bin/mysql-clear
. Run:
bin/mysql-clear [--db-prefix DB_PREFIX] [--days DAYS] [--dry-run] [-h] [--clean-*]
Before delete any data from database is good to make a backup.
Create cronjobs/jobs file and add there a cron entries. You can copy example file cronjobs/jobs.dist:
cp cronjobs/jobs.dist cronjobs/jobs
echo "* * * * * /cronjobs/custom-script.sh" > cronjobs/jobs
echo "* 8 * * * /cronjobs/custom-script-2.sh" >> cronjobs/jobs
Add custom scripts to cronjobs/ directory. Remember to add .sh extension
to files. Entrypoint will add x
mode to all files cronjobs/*.sh.
Note! Name custom scripts like modulename-youractionname.sh
.
You can use template file cronjobs/example.sh to create your own cron job. Put your logic between those lines:
###> Your cron job ###
...
###< Your cron job ###
In the most cases you will use http
and it should looks like:
curl -Ls "${moduleCronUrl}" >> "${log_file}" 2>&1
where $moduleCronUrl
you can find in specific module configuration. For
example goto
gsitemap
module configuration page and check Information
section.
To monitor your cron jobs you can use cronitor or sentry.
For cronitor:
- setup
CRONITOR_KEY
key in .env file, - uncomment line
#run_cronitor "$script_name"
to start monitor a job, - uncomment line
#complete_cronitor "$script_name"
to finish monitor a job.
Note! Yours monitor(s) names will be the same as a script name.
For sentry:
- setup
SENTRY_DSN
key in .env file, - uncomment line
#sentry_monitor_id=''
and providemonitorId
, - uncomment line
#check_in_id="$(run_sentry "$sentry_monitor_id")"
to start monitor a job, - uncomment line
#complete_sentry "$sentry_monitor_id" "$check_in_id" "$duration"
to finish monitor a job.
When you change an entries in cronjobs/jobs file remember to run
bin/install-cronjobs
.
To make a backup we're using a docker-backup tool which use BorgBackup under hood.
Create a .docker-backup file (use .docker-backup.dist as starter file,
cp .docker-backup.dist .docker-backup
) and setup values. Refer to
documentation.
Note! In filesToExclude
change admin directory name to point to your admin
directory.
To update Prestashop
from cli just run:
bin/autoupgrade --dir=adminxyz [--version=]
Use bin/autoupgrade --help
to see more options.
Note! Under hood we're using autoupgrade module.
To do that just copy update-config.json to prestashop/update-config.json, change values up to you and run:
bin/autoupgrade-config --from=update-config.json
Recommend to setup "skip_backup": true
. You're already using other tool(s) to
make a backup.
If you want to debug a shop with xdebug:
- be sure you're running dev environment (and images),
- add/setup
debug
toXDEBUG_MODE
, - reload docker with
docker-compose up -d
.
Now you're ready to remote debugging.