Prestashop on AWS: the definitive guide

First things first

Prestashop is an Open Source CMS, based on PHP, which is verticalized on e-commerce solutions. As all Open Source projects its community is full of skilled passionate and professionists that constantly develop modules and support users who want to customize their shops.

You can find several documents about how to properly install your Prestashop, both on official forum and developers portals but no one has never detailed how to properly set it up on AWS. If you decide to host your shop on AWS is quite sure you want to scale out properly to supply your demand without having to worry if your marketing campaign are being effective as expected, here’s some tips to properly configure in an AWS environment in a detailed guide

MySQL? Yes, but Maria!

Database Engine choice is not that easy, but if we think that MariaDB is fully MySQL compatible and – based on several tests – latency drop down to -0.2 only start using MariaDB instead of MySQL, the choice is actually easier than ever.

Here’s couple of settings for your Parameter Group in RDS:

"performance_schema" : "OFF"
"innodb_lock_wait_timeout" : "120"
"max_allowed_packet" : "16777216"
"key_buffer_size" : "134217728"
"read_buffer_size" : "2097152"
"read_rnd_buffer_size" : "1048576"
"thread_cache_size" : "80"
"join_buffer_size" : "2097152"
"sort_buffer_size" : "2097152"
"max_connections" : "400"
"tmp_table_size" : "33554432"
"max_heap_table_size" : "33554432"
"table_definition_cache" : "8192"
"query_cache_size" : "33554432"
"innodb_buffer_pool_size" : "3221225472"
"innodb_log_file_size" : "134217728"
"innodb_log_buffer_size" : "8388608"
"innodb_flush_log_at_trx_commit" : "2"
"innodb_thread_concurrency" : "32"
"innodb_read_io_threads" : "8"
"innodb_write_io_threads" : "8"
"innodb_flush_method" : "O_DIRECT"
"innodb_file_per_table" : "1"
"innodb_io_capacity" : "2000"
"innodb_file_format" : "Barracuda"
"innodb_buffer_pool_dump_at_shutdown" : "ON"
"innodb_buffer_pool_load_at_startup" : "ON"
"innodb_log_compressed_pages" : "0"

These settings refer to a tune that must be fined according to your needs, and based on your shop peculiarity.

Turbo PHP

When PHP sees a vCPU the first thing it says is “yummy”, but instead of thinking about migrate to PHP7 – that has several benefits on CPU Optimization – you can think about using PHP-FPM which is largely use in Publishing Industry. If your backend and your custom modules have started to stress your VPS or Virtual Machine then you should really consider to introduce it into your stack.

Couple of tips to configure it:

  1. use “ondemand” instead of “dynamic” profile
  2. use UNIX socket instead of TCP

The first tip refer to how child processes are managed by PHP-FPM, and “ondemand” stop using CPU when no connections are coming. A “static” profile might be more effective in case you have a steady state workload, but if it’s spiky then ondemand could be more efficient. Second tip simply is how your web server will forward PHP requests to your daemon, and UNIX socket are just a bit better than TCP.

Let’s talk about Web

Configure a Web Server seems one the easiest thing in this guide, but it’s not. As long as you want to increase your traffic without affecting other End-Users Experience you have to properly set Web Server up to do so. If a web page requires more than 2s to open, half of End-Users will directly close the tab which means you’re potentially lose a customer.

Here’s why we have think about a configuration that leverage on both NGINX and Apache benefits, without being affected by their weaknesses. NGINX, which is famous for its speed on managing connections, is configured as a proxy and basically just route requests from 80 (better if 443) to another port. On that port is listening Apache which is easy to configure with MPM module to manage concurrent connections effectively, drastically reducing latency.

Balance your Prestashop

To achieve High Availability and to easily scale up you need a “layer” that basically spread connections among a virtual machines fleet. Here’s what ELB does. Implementing a Load Balancer we virtually add a “layer” to our stack which is in charge of managing our End-Users connections. AWS offer a simple guide to properly implement ELB with Apache to reduce potential latency issues (click here).

But our stack is not similar to what AWS has described into that guide, so there’s the tips for setting up web servers in a balanced environment:

  • NGINX will have a timout equal to twice the ELB timeout (default is 65s), and its “work_processes” parameter must be customized according to the EC2 instance you’re using (vCPU)
  • Apache will have a timout that can vary from twice the ELB and twice the NGINX timeout, while its MPM configuration is prefork or worker\events in case you have a specific needs based on your workload

That’s not all folks

Here you’ll find a Cloudformation template which helps you to configure an AWS environment from scratch, you can also find a video (it’s italian, but it’s clear enough) that help you to set up the template step-by-step





Do things differently…

Template can be modified and customized according to your needs and to implement even more AWS services, but let us give you couple of ideas:

  • Continuous Integration and CodeDeploy, set up a Continuous Integration and the related Deploy with CodeDeploy (it’s free) allows you to be sure that when your application scale out the latest stable version of your e-commerce will be deployed on brand new instances
  • Cloudfront, Prestashop has the media server function that allows you to deliver static content leveraging on a CDN that decrease latency and enhance the UX loading high-res images quickly
  • Elasticache, using memcached module for PHP you could redirect your cache on a RAM cluster to scale out more easily

Do you want a customized E-Commerce environment?
Get in touch

I have read and I authorize the treatment of my personal data