Tip: Start typing to get instant search results.
Magento 2 Deployment
Below we present two ready-made SSH one-liners that facilitate the Static or Full Deployment process on our servers with Magento 2.
The scripts cover installations with two languages (English and Greek) and assume you are already in the Magento folder via SSH (cd public_html).
Static Deployment:
The following one-liner executes deployment of static files. First, it performs the necessary cleanup of static files, and then proceeds to regenerate them for both languages (in this one-liner, the two languages are given as an argument, as in some Magento versions this is necessary for the files to be generated correctly):
$ opcflush; rm -rf pub/static/* var/view_preprocessed/* ; php bin/magento s:s:d -f -j 4 en_US el_GR; bin/magento c:f
Full Deployment:
The following one-liner executes a full deployment and includes setup:upgrade, compile, static deployment, etc.:
bin/magento main:en; rm -rf generated/*; rm -rf pub/static/*; rm -rf var/view_preprocessed/*; opcflush ; bin/magento set:up; bin/magento s:d:c; rm -rf pub/static/* var/view_preprocessed/* ; opcflush; bin/magento s:s:d -f -j 4 en_US el_GR ; bin/magento main:dis; bin/magento c:en; bin/magento c:f
Useful notes for the above one-liners:
- Parallelism (-j): The -j 4 option means to use 4 CPU threads in parallel. Depending on the available CPUs on the server, you can also try -j 6 or -j 8 or -j 10, however we recommend not to use all the CPUs the server has, especially when your website is live.
Try to see which number of threads gives you faster results (more threads does not always mean faster deployment). - Flexibility: These specific one-liners are indicative and functional for most Magento 2 versions. Depending on the specifics of the project, some steps (e.g., complete folder cleanup) may not always be necessary.
Extra – Advanced Optimizations (Composer & APCu)
For more experienced users, we support and recommend additional optimizations at the PHP level, through:
- Optimized composer commands
- Use of APCu cache in
composer
With these actions you can have improved performance, especially during startup and execution of autoloaded files.
Important note: Test these techniques first in a staging environment. Do not apply them directly to your live environment.
$ bin/magento setup:up $ composer install --no-dev $ bin/magento s:d:c $ composer dump-autoload -o --apcu $ bin/magento s:s:d -j 4 en_US el_GR $ bin/magento c:f