Skip to content

Magento2 Deployment

Server Configuration

In this section I will describe the important bits of nginx and varnish configuration, redirects map. Magento2 server configuration can be found at /opt/Projects/snippets-edmondscommerce/temp/magento2-migration

Configuration versioning

Make sure you version control your server configuration. To do that follow the steps below.

# creates and initializes serverConfig-BARE repository
cd /root
mkdir serverConfig-BARE
cd serverConfig-BARE
git init --bare

# clones git project
git clone /root/ServerConfig-BARE serverConfig
# now follow procedure below with each of the files you want to version control this would
# definitely include nginx, varnish configuration, crontab content
cd /etc/nginx/conf.d/
cp --parents /etc/nginx/conf.d/someconf.conf /root/serverConfig # it will copy by keeping directory structure
rm someconf.conf; ln -s /root/serverConfig/etc/nginx/conf.d/someconf.conf someconf.conf;

cd /root/serverConfig
git add --all
git commit -m 'starting server configuration tracking'
git push

Warning

Don't forget to version control your crontab content!

Nginx

Important files are

  • /etc/nginx/includes/admin - this is for Magento2 backend hardening. It restricts access by IP and Basic Auth. Also whole admin pages bypasses Varnish caching.
  • /etc/nginx/conf.d/example.co.uk.conf - basic nginx server blocks, map blocks, various Magento specific locations.
  • /etc/nginx/map/finalredirects.map - holds request and location values of redirects.

Warning

Bare in mind that having to many redirects in the map file can cause problems and nginx might throw an error. If that is the case try increasing map_hash_bucket_size parameter in /etc/nginx/nginx.conf file. You can read more about it in map_has_bucket_size documentation page

Varnish

Important file in regards to varnish is /etc/varnish/varnish.params, you can read more about it at official documentation page

Warning

Important bit is DAEMON_OPTS setting in varnish.params. Magento recommended settings is for 3000 products category only, but that is ussualy not enough. Settings below is for 6000 products.

DAEMON_OPTS="-p http_resp_hdr_len=126000 -p http_resp_size=158768 -p workspace_backend=128M"

Migration

  • edmondscommerce/magento2-data-migration - core migration code, to do the full migration, from downloading database of Magento1, images, to creating Magento2 database importing images etc.
  • edmondscommerce/magento2-migrations - this extension has basic functionality for updating core_config_data table, and other generic things with Install Data setup script more information in the blog page
  • EdmondsCommerce_ProductionSettings - extension which uses methods from edmondscommerce/magento2-migrations and allows to set project specific settings, replace hardcoded strings (if migrating from http to https), change theme, etc.. sample extension code can be found at /opt/Projects/snippets-edmondscommerce/temp/magento2-migration/EdmondsCommerce_ProductionSettings

Going LIVE with the project

Below I will describe the steps that needs to be taken to go LIVE with Magento 2 project

Preconditions:

  • You have your Magento 2 project files and database on the new server.
  • You have nginx and varnish configured
  • You have edited your /etc/hosts files and website is working
  • After making sure website is working through /etc/hosts, you have removed the domain entry from the file
  • You have your domain nameservers with Cloudflare

Magento 1

  • SSH into your Magento 1 server
  • cd into your Magento1 project root.
  • Create maintenance.flag file.

After executing steps above, your site will be put to maintenance mode.

Magento 2

  • SSH into your Magento 2 server
  • Cd into your project root and execute php bin/magento maintenance:enable --ip={YOURIP} this will enable maintenance mode on your Magento 2 site for public, though you should have access to the site
    • Magento

Cloudflare

  • Go to cloudflare and update your domain A records and possibly SPF record to point to new server
  • Create new A record (for example m1) so that you can still access your Magento 1 project via m1.somedomain.co.uk

Magento 2

  • Go to your Magento 2 project again and after you are certain that site is working ok execute php bin/magento maintenance:disable
  • That is it, your Magento2 site is now visible to public.

Magento 1

  • Go to your Magento 1 server, create web server virtual host for m1.somedomain.co.uk
  • IP and/or Basic Auth restrict it
  • Make sure you can access it.

Results:

  • Your Magento 2 site is running and visible to public
  • Your Magento 1 site is running on old server and can be accesed by m1.somedomain.co.uk