Performance and going live
During development the shop is tuned for convenience: errors on screen, templates rebuilt on every change, the cache off. Customers need the opposite — speed and hidden details. Almost everything is switched on one back office page: "Advanced Parameters → Performance".
Performance settings
| Setting | In development | On the production server |
|---|---|---|
| Debug mode | On | Off |
| Template compilation | "Recompile templates if the files have been updated" | "Never recompile template files" |
| Smarty cache | Off | On |
| Smart cache for CSS | Off | On |
| Smart cache for JavaScript | Off | On |
| Data cache | Off | Memcached or another one, if the server has it |
"Smart cache" combines all style files into one and all scripts into one — that is exactly why a module registers files through registerStylesheet() instead of writing the tags itself.
Debug mode in the file
The switch in the back office changes a constant in the file config/defines.inc.php. On the production server it must look like this:
// config/defines.inc.php
define('_PS_MODE_DEV_', false);With false errors are not shown to visitors, and Symfony runs in the prod environment with its cache in var/cache/prod.
Clearing the cache
After new code is deployed the cache is cleared:
php bin/console cache:clear --env=prodThe command removes the Symfony cache: the service container, routes, Twig templates. The "Clear cache" button on the "Performance" page does the same and also resets compiled Smarty templates and combined styles and scripts.
| What you changed | What to clear |
|---|---|
services.yml, routes.yml, a Twig template | cache:clear |
| A Smarty template, CSS, JavaScript | The "Clear cache" button |
| A class override | The file var/cache/prod/class_index.php |
What slows a module down
| Cause | What to do |
|---|---|
| A database query in a hook on every page | Cache the result, select only the columns you need |
| Styles and scripts on all pages | Load them only where the module block is shown |
| A request to an external service while a page is shown | Move it to a scheduled command |
Creating an object in a loop: new Product($id) | One DbQuery query for the whole list |
Template cache in a hook
A block that rarely changes can be built once. Pass a cache id to fetch() and prepare the data only when there is no cache yet:
// modules/acmehello/acmehello.php
public function hookDisplayHome(array $params): string
{
$template = 'module:acmehello/views/templates/hook/home.tpl';
$cacheId = $this->getCacheId('acmehello_home');
if (!$this->isCached($template, $cacheId)) {
$this->context->smarty->assign([
'greeting' => Configuration::get('ACMEHELLO_GREETING'),
]);
}
return $this->fetch($template, $cacheId);
}With the Smarty cache on, the greeting block is built once and then served ready. When the setting is changed on the module page, the cache is reset with a $this->_clearCache($template) call after saving.
Before going live
| What to check | Why |
|---|---|
The install folder is deleted | Otherwise the shop can be reinstalled |
| The back office folder has a random name | Bots try the /admin address |
_PS_MODE_DEV_ is false | Errors and paths are hidden from visitors |
| HTTPS is on for all pages | "Shop Parameters → General" |
| Friendly URLs are on | "Shop Parameters → Traffic & SEO" |
| Email is sent | A test email on the "E-mail" page |
| Test orders and customers are removed | Clean statistics |
| Write permissions only where needed | var, img, upload, download, translations |
| A scheduled backup of the database and files | Recovery after a failure |
| Maintenance mode is off | "Shop Parameters → General → Maintenance" |
Moving to a server
Files are copied to the server, the database is moved with a dump. After the move three things are fixed: the database parameters in app/config/parameters.php, the domain in the back office on the "Traffic & SEO" page in the "Set shop URL" block, and the cache is cleared.
Upgrading the shop
The core is upgraded with the upgrade module from PrestaShop — it is installed from the back office — after making a copy of the files and the database. The upgrade is first tested on a copy of the shop. Your modules and the child theme are not affected by an upgrade — unless you edited the core.
Common mistake
The code is deployed to the server, but the shop works the old way or fails with an unknown service error. In the prod environment the container and routes are not rebuilt by themselves. Clearing the cache is made part of the deployment order: copy the files — run cache:clear --env=prod — check the home page and the back office.