Contents
Overview of deployment
This topic provides guidelines and best practices for deploying a Magento site to production. We don鈥檛 recommend a specific set of instructions; these are intended as general guidelines. You should be working with an experienced system integrator who can help you make decisions for your particular deployment.
Assumptions:
- Your development environment is behind a firewall with the Magento application in developer mode.
- All custom code is in source control.
- Your development environment is as similar as possible to production (same number of webnodes, same caching architecture, and so on)
- Your production environment is a separate set of servers in a secure environment.
- Your production environment runs the Magento application in production mode with desired security options enabled.
- Your production system has a working, live Magento installation.
Deploying to production involves the following essential steps. Each set of steps is discussed in more detail in the sections that follow.
In your development system
- Test your system in your development environment.
- Put all custom code in source control.
- Compile code and generate static view files.
- Archive file system assets and export the database.
- Transfer file system and database assets to your production system.
In your production system
- Create the Magento deployment configuration.
- Extract file system and database assets from your archives.
- Set file system permissions.
- Test everything.
- When everything is working, 鈥渇lip鈥 your DNS server to point to your production system.
Prepare your development system
Your development system is a dedicated developer or build system where you periodically:
- Deploy Magento 2 code (including custom code).
-
Clean static files.
rm -rf <your Magento install dir>/pub/static/*
-
Remove the Magento database and reinstall it with database schema and data from your implementation.
One way to do this is to run the command-line installer with the optional
--cleanup-database
command. - Use the
magento setup:static-content:deploy
command to deploy static view files. -
Clean temporary files that shouldn鈥檛 be in production.
cd <your Magento install dir>/var rm -rf cache/* composer_home/* log/* page_cache/* session/*
- Archive the file system to a suitable format (
.tar
,.tar.gz
,.zip
, and so on). - Export the database using a tool like
mysqldump
Best practices in development:
- Use the Magento file system owner to run cron
- Log in, or switch to, the Magento file system owner to run commands, install or uninstall Magento, and so on
- Use the
magento deploy:mode:set
command to enable developer mode - Periodically clean the cache and compiled code directories
- Set up your
robots.txt
to prevent search engines from indexing your development site. (You don鈥檛 want search results to point to this site because it won鈥檛 be available to customers.)
Production server checklist
Make sure you do as many as possible of the following before continuing:
- Set up Redis caching
-
Set up Varnish web acceleration
We strongly recommend Varnish for HTTP acceleration, including page caching.
- Set up a Content Delivery Network (CDN)
- Set up multiple webnodes with load balancing
- Configure Magento payment and shipping methods
- Set your web server virtual host to point to the Magento
pub
directory because doing so prevents running the Setup Wizard, Component Manager, or System Upgrade in production
Guidelines for deployment to production
This section provides guidelines for deploying a Magento installation to production. Depending on your requirements, additional tasks might be required. Consult a system administrator for advice.
- Copy your development file system and database archives to the production system.
- Extract the Magento 2 file system archive to an empty directory.
- Set up persistent storage (for example, media, logs, cache, session, and so on).
- Take your existing system offline by enabling maintenance mode using magento maintenance:enable. (DOWNTIME STARTS)
- Install the Magento software in a clean database (optionally using the
--cleanup-database
option). - Import database data from your development system.
- Move your existing file system to an archive location.
- Move the file system you copied from your production system to the Magento docroot.
- Change to production mode and set file system permissions and ownership for production.
- Test everything thoroughly and carefully.
- Switch DNS to the new server. (DOWNTIME ENDS)
Best practices in production:
- Use Varnish to accelerate HTTP traffic, including providing page caching
- Use the
magento deploy:mode:set
command to enable developer mode - Use the
pub
directory as the Magento docroot to prevent running the Setup Wizard, Component Manager, or System Upgrade in production. (Set up virtual hosts to point to<your Magento install dir>/pub
.) - Set up your
robots.txt
to allow search engines to index your production site.
Find us on