John Davidson

php - Optimize Prestashop in Docker

0 comments
Message:


I want to configure proper dev environment for Prestashop 1.7 using Docker.
Issue is that it's quite slow. Profiler(from Symfony) shows around 2.7-6 seconds to load some admin pages. (freshly installed website). In production we have website working not in docker container and page load speed is around 150-250ms. I understand that it might be slow because of some large folders like "vendor", so I tried some ways to optimize it by adding :delegated. Performance probably was improved for several seconds, but still 3 seconds is not comfortable to work. I would like to improve it at least to load within 1000ms.


Prestashop image from: https://hub.docker.com/r/prestashop/prestashop/


You can try this docker-compose to play around what can be modified to improve:


version: '3'

services:
prestashop:
build: ./docker/prestashop
container_name: app
ports:
- 80:80
links:
- mariadb:mariadb
depends_on:
- mariadb
volumes:
- ./docker/common:/scripts
- ./src:/var/www/html:delegated
- vendor:/var/www/html/vendor
- var:/var/www/html/var
environment:
- PS_DOMAIN=localhost
- PS_DEV_MODE=1
- DB_SERVER=mariadb
- DB_USER=root
- DB_PASSWD=root
- DB_NAME=ps_test
- PS_INSTALL_AUTO=1
- PS_COUNTRY=EE
- [email protected]
- ADMIN_PASSWD=test123
- PS_INSTALL_DB=1

mariadb:
build: ./docker/mariadb
container_name: mariadb
restart: always
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=ps_test
volumes:
- db_data:/var/lib/mysql
- ./docker/mariadb/logs/:/var/log/mysql:delegated

volumes:
db_data:
vendor:
var:

prestashop Dockerfile:


FROM prestashop/prestashop:1.7-7.2-apache

RUN yes | pecl install xdebug \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_connect_back=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_port=9000" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "file_uploads=On" >> /usr/local/etc/php/conf.d/uploads.ini \
&& echo "memory_limit=1G" >> /usr/local/etc/php/conf.d/uploads.ini \
&& echo "upload_max_filesize=64M" >> /usr/local/etc/php/conf.d/uploads.ini \
&& echo "post_max_size=64M" >> /usr/local/etc/php/conf.d/uploads.ini \
&& echo "max_execution_time=600" >> /usr/local/etc/php/conf.d/uploads.ini \
&& echo "max_input_vars=100000" >> /usr/local/etc/php/conf.d/custom.ini \
&& echo "error_reporting-1" >> /usr/local/etc/php/conf.d/custom.ini \
&& echo "display_errors = On" >> /usr/local/etc/php/conf.d/custom.ini

RUN usermod -u 1000 www-data
RUN chown 1000 /var/www -R


My Answer:
vendor and cache not being properly optimized in the Docker environment.

Here are some steps you can take to optimize Prestashop in Docker:

1. Use a multi-stage build in your Dockerfile to reduce the size of the final image. This will help speed up the build process and reduce the overall size of the container.

2. Make sure you are using a caching mechanism for Composer dependencies. You can use a volume mount for the vendor directory to persist the dependencies between builds.

3. Enable OPcache in your PHP configuration to improve performance by caching compiled PHP code.

4. Use a reverse proxy like Nginx or Apache to serve static files and cache dynamic content. This will help reduce the load on the PHP application.

5. Optimize your database queries and indexes to improve the performance of database operations.

6. Use a tool like Blackfire or Xdebug to profile your application and identify bottlenecks that can be optimized.

By following these steps, you should be able to optimize the performance of your Prestashop application running in a Docker container.

Rate this post

4 of 5 based on 1096 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us