Meet Magento Academy - SysOps part

Virtual Machine initiation with VMware Workstation.

If we have no access to the Internet (or we prefer to develop locally for whatever reason, we’ll use VMware Workstation as a hypervisor. We could take other options (like VirtualBox), but the main reason for VMware is the compatibility with the labs at WMI UAM.

  1. Download Debian Linux Netinst image (current stable version – 9.2.1 for 2017/2018 classes). (pick amd64 architecture)
  2. Launch a VMWare Workstation.
  3. Click “Create a New Virtual Machine”
  4. Choose:
    1. Installer disc image file (iso) and point to Netinst image you’ve just downloaded in Step 1.
    2. Linux as a guest operating system
    3. Debian 8.x version (even though we’re installing 9.2.1),
    4. Virtual Machine Name – Magento Debian 9.2.1
    5. Location will autofill with the path and the name. Change the path to P:\vm\your_index_number\
    6. Leave maximum Disk Size set to 20GB, and split virtual disk into multiple files.
    7. Press Finish
  5. Play your virtual machine
  6. Pick the following options:
    1. install instead of graphical install
    2. the language you prefer – english (is usually the best)
    3. your location  (for WMI classes)  – Poland
    4. your keymap  (for WMI classes ) – Polish
    5. your hostname – mma1
    6. yout domain – mma1.local  is OK
    7. root password – qwerty
    8. new username and password – i.e. s123456, qwerty
    9. select your timezone – (i.e.) Europe
    10. Disk partition – “Guided, entire disk and the only available disk”
    11. “Keep all files in one partition” (we’re doing development, so it’s more convenient)
    12. Finish paritioning and write the changes to disk  and  Confirm (it may take a while, the system will go to packages search)
    13. Select No for Scan another CD and DVD question.
    14. Next, select the best mirror for debian packages – Europe, Poland, is usually OK (if you’re at the classes at WMI UAM leave the proxy empty, usually leaving empty is OK)
    15. Choose whether you want to participate in a packages survey – Yes and No are both OK.
    16. Unselect “Debian desktop environment“, “print server“, Select: “SSH server” and continue to the installation
    17. Install grub to MBR, pick /dev/sda
  7. After the Installation complete, press Continue.
  8. The system will be rebooted and after successful startup you’ll be able to log in.

We have a Debian Linux ready 🙂

How to log in

The most convenient way to manage our Linux is to login in via ssh.

First, we neet to check what’s the IP and log in via putty/SSH as follows:

  1. Before you’ll use ssh you need to check what’s the ip address of the machine
  2. Check the ip address of your machine with ip command (in the example we have ens33).
  3. The IP address assigned to our system is We’ll use it to log in via putty.
  4. Download putty and use the ip in “Host Name (or ip address)”
  5. Log in as a user you’ve just created (s123456,qwerty) and the switch to the superuser with “su –” command.
  6. We can test if we’re logged in to the root account, by installing curl:


Dedicated User for Magento processes

Magento APP uess PHP run with php-fpm. For security reasons we’ll create a dedicated user for a web server and php app processes.

We run the command:

We can check if everything went OK:

We can see the user got 1001 ID in our system. Notice, it’s not important to remember the ID of the user.

Tuning – if we want to avoid problems with limit of open file descriptor it’s good to set up in /etc/security/limits.conf at the end of file the following settings:

Debian repositories


Update the repositories:

Add Mysql repositories:

Update the repositories again to see everything is all right:

We’re done with repositories.

Mysql installation

We’ll use percona instead of mysql. It’s a compatible fork of mysql, but it’s faster and better from DBA perspective.

During the installation we’ll be asked for mysql root account’s password. Pick “qwerty”.

After mysql is installed we log in and create the database and a user for our Magento store.

We’re done with the database.

Notice that we’ve restricted the connections to mysql “supershop” database to user “supershop” and localhost. If we were on the production, we would need to allow other hosts to connect.


We’ll install PHP 7 with all required modles (

  • php7.0-fpm
  • php7.0-bcmath
  • php7.0-curl
  • php7.0-gd
  • php7.0-intl
  • php7.0-mbstring
  • php7.0-mcrypt
  • php7.0-mysql
  • php7.0-xml
  • php7.0-xsl
  • php7.0-zip
  • php7.0-json
  • php7.0-opcache
  • php7.0-soap

Next we need to adjust the configuration of  /etc/php/7.0/fpm/php.ini  changing the parameters:

In the /etc/php/7.0/fpm/pool.d/www.conf we change the user and socket for php processes:

Next we restart PHP FPM:

We’re done with PHP.


In order to preserve the same environment for cron jobs we need to apply the same changes to /etc/php/7.0/cli/php.ini.

Web Server

First we need to install nginx with all addons:

We’ll use the sample Magento config and put it in /etc/nginx/snippets/magento2.conf (it can be used for many virtual hosts if we have more than one):

Next we create virtualhost /etc/nginx/sites-available/supershop.conf

an we activate it (also removing default virtualhost):

We change the owner of the Nginx processes by adding or changing the following line in /etc/nginx/nginx.conf :

Restart Nginx:

We’re done with nginx.

Two Redis Instances


We assume we have unmodified Debian 8.8, so our init deamon is systemd. sysVinit would also do the trick but with different commands. 


Before installing redis we need to adjust some kernel parameters.

In/etc/sysctl.conf set vm.overcommit_memory to 1 and load the config sysctl -p.


We’re ready to install Redis. We need to instances: cache i session running on different ports.

Next we copty the  INI  Redis file:

In /etc/systemd/system/redis-cache.service file we modify starting settings:

In /etc/systemd/system/redis-session.service file we modify starting settings:


From both redis-session.service and redis-cache.service files we remove lines containing Alias and  RunTimeDirectory. If we don’t we will meet some errors.

For each instance we create it’s folder:

We change current folder to /etc/redis, we duplicate the configuration so it listens on different port and use different PID and log files.

In redis-cache.conf we change:

In redis-session.conf we change:

We make systemd, to prepare for two active Redis instances:


After starting two instances (knowing their ports) we can check if they work properly:

Code Deployment

We need to download the Magento code from  Pick .tar.gz format in the Download on the bottom.

We can do so on our desktop and then upload it logging to our server using winscp (instead of putty).

While I installed the Linux I created the “kalkos” account, so I’ll upload Magento code to kalkos’s home folder and then from supershop user I’ll unpack it to the public_html folder.

We change the context to the supershop user, who’s supposed to run magento:

and we unpack the code:

We can now check http://localhost/setup

Oh – it’s Magento welcome page 🙂

Cron jobs

Magento 2 requires some cron jobs –

With which php7.0 command we can locate the path to PHP cli interpreter,which we’ll use in crontab.

We will modify crontab with “crontab -u supershop -e” and we’ll insert the following lines there:

Varnish - optional

We’ll use Varnish as a reverse proxy server. It’s an optional step. If we want to use varnish we also need to change the line listen in /etc/nginx/sites-available/supershop.conf to:

Next we install varnish:

We want to launch varnish on the port 80.  We need to make sure that /lib/systemd/system/varnish.service contains the line:

In/etc/varnish/default.vcl we place the sample config with purging option with HTTP request.

Finally, we restart the varnish service:

and we’re done.