Magento 2 install local or remote SSH environment using Docker and Visual Studio CODE

  1. Local server(your machine) or remote server with the connection over SSH:
  2. Install docker and wget, github, htop
  3. Git pull Magento or another project docker pull from the genaker/magento2-project or build docker image
  4. start docker image as a working container
  5. Change Magento base URL configuration
  6. Change localhost or remote HTTP:{your_ip address}
  7. Connect Visual Studio Code to the remote docker

1. Connect to the server

ssh -i *****.pem ec2-user@3.137.***.***

2. Install docker and wget, github, htop

curl -s | sudo bash
sudo chmod -R 777 /var/run/docker.sock
sudo yum install wget,git,htop -y
sudo yum install mc -y
mc -b

3. Docker pull Magento project

docker pull genaker/magento2-project

Supervisor: A Process Control System

4. Start docker image as a working container

docker run --name magento2 -d -p 80:80 genaker/magento2-project#OR you can mount magento root as a volume on a host file system if you need new magento installation docker run --name magento2 -d -p 80:80 -p 443:443 -v /tmp:/shared -v /var/www/html/magento:/var/www/html/magento genaker/magento2-project
docker exec -it magento2 bash
supervisorctl status
supervisorctl tail -f redis stdout
supervisorctl start redis

How to connect to Mysql?


5. Change Magento base URL

docker exec -it magento2 /var/www/html/magento/bin/magento config:set web/unsecure/base_url "http://18.222.***.***/"

7. Connect Visual Studio Code to the remote docker

Visual Studio Code Remote — Containers

  • Develop with a consistent, easily reproducible toolchain on the same operating system you deploy to.
  • Quickly swap between different, isolated development environments and safely make updates without worrying about impacting your local machine.
  • Make it easy for new team members / contributors to get up and running in a consistent development environment.
  • Try out new technologies or clone a copy of a code base without impacting your local setup.

Visual Studio Code Remote — SSH

  • Develop on the same operating system you deploy to or use larger, faster, or more specialized hardware than your local machine.
  • Quickly swap between different, remote development environments and safely make updates without worrying about impacting your local machine.
  • Access an existing development environment from multiple machines or locations.
  • Debug an application running somewhere else such as a customer site or in the cloud.
Host Magento2
HostName 18.222.***.***
User ec2-user
IdentityFile {path to the pem file}
composer require genaker/module-react-emojigame
bin/magento setup:upgrade
rm -rf generated/*
bin/magento setup:di:compile
bin/magento setup:static-content:deploy -f
# install dockercurl -s | sudo bashsudo chmod 666 /var/run/docker.sock# Run magento container 
docker run --name magento2 -d -p 80:80 genaker/magento2-project
# check docker running containers
docker ps
# change Magento URL to your remote server IP addres (optional)docker exec -it magento2 /var/www/html/magento/bin/magento config:set web/unsecure/base_url "http://***.***.***.***/"# Cahek Magento web sitecurl -I http://***.***.***.***/
# Connect to the Mageto Dockerdocker exec -it magento2 bash# go to magento folder cd /var/www/html/magento
docker run --name magento2-my-second-project -d -p 666:80 genaker/magento2-project## set new url with the port:docker exec -it magento2-my-second-project /var/www/html/magento/bin/magento config:set web/unsecure/base_url "http://***.***.***.***:666/"
docker stop  magento2-my-second-project
docker exec -it magento2 bash
cd /var/www/html/magento
git clone -f magento2-sample-data/dev/tools/build-sample-data.php -- --ce-source=.bin/magento setup:upgradebin/magento setup:static-content:deploy -fbin/magento setup:di:compile

Committing Changes to the Docker Registry

Modify the MAgento Container

docker ps -a

Commit Changes to Image

docker commit [CONTAINER_ID] [new_image_name]
docker commit 62e0302eee0c magento-react# check images
docker images

Pushing Docker image

docker login
docker image tag magento-react genaker/magento-react:latest 

Pushing a Docker container image to Docker Hub

  • When you build them, using docker build -t <hub-user>/<repo-name>[:<tag>]
  • By re-tagging an existing local image docker tag <existing-image> <hub-user>/<repo-name>[:<tag>]
  • By using docker commit <existing-container> <hub-user>/<repo-name>[:<tag>] to commit changes
$ docker push <hub-user>/<repo-name>:<tag>
docker push genaker/magento-react
docker run --name magento2 -d -p 80:80 -p 443:443 -v /tmp:/shared  genaker/magento-react

99. If you need a new Magento 2 project

docker run --name magento2 -d -p 80:80 -p 443:443 -v /tmp:/shared -v /var/www/html/magento:/var/www/html/magento genaker/magento2-projectcd /var/www/html
rm -rf magento
COMPOSER_MEMORY_LIMIT=-1 composer create-project --repository-url= magento/project-community-edition magento# or use git than you need git clone && composer install mysql -e 'drop database magento2';
mysql -e 'create database magento2';
cd magentobin/magento setup:install --base-url=http://***.**.*.** --db-host=localhost --db-name=magento2 --db-user=magento --db-password=magento --admin-firstname=Magento --admin-lastname=User --admin-user=admin --admin-password=admin123 --backend-frontname=admin --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1; \sudo chmod -R 777 var/ generated/ pub/media/ pub/static;php -d"memory_limit=-1" bin/magento sampledata:deploy# we need reload becouse opcache timestamp validation is off supervisorctl restart php-fpm# Change to SSL/HTTPS and domainbin/magento config:set web/secure/base_url this magento bag you basicaly must set unsecure/base_usr also or admin will not work
bin/magento config:set web/unsecure/base_url
bin/magento config:set web/secure/use_in_frontend 1bin/magento config:set web/secure/use_in_adminhtml 1# Point your domain to your IP addres or Load ballancer
php bin/magento deploy:mode:set production
nano /etc/php.d/10-opcache.ini
;opcache.validate_timestamps = 0
supervisorctl restart php-fpm

Set Up Permissions

find . -type f -exec chmod 644 {} \;find . -type d -exec chmod 755 {} \;chmod -Rf 775 varchmod -Rf 775 pub/staticchmod -Rf 775 pub/mediachmod 775 ./app/etcchmod 644 ./app/etc/*.xmlchmod -Rf 775 bin
tail -f var/log/exception.log
tail -f var/log/system.log
tail -f /var/log/php-fpm/www-error.log
sudo chmod -R 775 /var/www/html/magento/*
mkdir -p app/design/frontend/Genaker/theme-react-luma/
cd app/design/frontend/Genaker/theme-react-luma/
git clone .
mkdir -p app/code/React/React
cd app/code/React/React/
git clone .
mkdir -p app/code/ReactLuma/Theme
cd app/code/ReactLuma/Theme
git clone .

Enable CSS critical path

bin/magento config:set dev/css/use_css_critical_path 1
php bin/magento config:set dev/js/move_script_to_bottom 1



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yegor Shytikov

Yegor Shytikov

True Stories about Magento 2. Melting metal server infrastructure into cloud solutions. Donate: