Monthly Archives: December 2014

How to prepare Magento 2 beta package for offline use

Magento 2 comes with a composer installer and all external dependencies including sample data are being installed using composer. However, I needed to have a simple way to install Magento 2 along with sample data in an offline environment, without using composer. I had a few reasons to do this – I wanted to have a fast way to install Magento 2 multiple times and I wanted to test command line installing for purposes.

Main goals are:

  • avoid downloading more than 1 GB of data each time
  • let it work in offline mode
  • operate with smaller packages
  • simplify steps needed to install Magento 2

Cloning GIT repository and downloading dependencies resulted in downloading more than 1GB of data:

  • Magento 2 code cloned with packages downloaded using composer: 471.3 MB (194 MB after gzipping)
  • sample data media: 590.9 MB (zipped)
  • sample data code: 0.2 MB (zipped)

I decided to prepare a Magento 2 package which contains only code needed to run application and to prepare sample data package which could be installed just by copy pasting that into Magento 2. Recently I was playing with a sample data compression script provided by Vinai Kopp, and I made a fork which can compress Magento 2 sample data.

At the end I have the following packages:

  • Magento 2 code (26 MB, gzipped)
  • compressed sample data media (92MB, zipped)
  • sample data code: 0.2 MB (zipped)

I know there is a composer cache. I know I could use Vagrant/Docker or other virtualization, but still I wanted to avoid overcomplicating the process. If you see that use case useful, please find all needed steps described below.

Just keep in mind it is written for 0.42.0-beta1 release of Magento 2 and it is not a recommended way to install Magento 2.

Prepare Magento 2 package

1. Clone GIT repository

2. Install composer dependencies

3. Remove huge directories not needed to run application

4. Prepare package

Prepare Magento 2 sample data package

1. Downlod demo data

2. Compress demo data

Install Magento 2 using created package

1. Prepare directory and unpack package:

2. Set required permissions

3. Run Setup

Install sample data using package

1. Unpack media sample data

2. Unpack sample data code

3. Install sample data

4. Make sure newly added files are writable:

This one is a little dirty, but as far as I know composer doesn’t support installing local packages.

Let me know if you find this article useful and if you have any thoughts around that.

How to easily dump Magento database with n98-magerun

It looks I felt in love with a n98-magerun tool. I already talked about my favourite n98-magerun commands and about a command which allows to generate fake customer data. Today I’m going to continue n98-magerun post series and focus on a command which allows to make database dump very easily. n98-magerun.phar db:dump in addition to commands mentioned in previous blog posts is another one must have.

The command allows to dump a database very easily. Similar to a n98magerun mysql-client command, it doesn’t require me to enter a password and look for any connection details. It automatically generates a dump file name based on a current date and time, allows to use built-in filters to exclude big utility tables and finally creates an archive after completing the dump.

Sample calls may look as follows:

First call produced a 5.1 GB file containing all database tables. Second stripped a bunch of database tables such as changelog tables, index tables, reports or logs tables and it resulted in reducing the database dump to 3.1 GB. Third one called with a compression option reduced size to about 251 MB. Third gain is expected and it could be also achieved with one additional gz command call, but it’s really convenient to do a gzipped dump in one command call.

Stripping not needed database tables can save gigabytes of transfer when working with a big database. However, it won’t fit all use cases, for example in which you need to prepare a dump to debug index problems where you need to get an exact state of a Magento application database.