Get the composer access keys from magento marketplace
magento devdocs
Install mysql-client optionally to ease database admin tasks
Install certbot for installation on server
2. Follow these steps to setup the enviroment
Clone this repository using git clone and cd into it
Initilization can be done either for local or server
Both of these scripts will do the following tasks, check for specific comparison in table below
- Create folders in host that will be mounted to docker containers
- Configure proper permissions
- Optimize host for elasticsearch / redis
- Configure docker-compose environment file
- Configure host environment for frequent commands
subject
local initialize
server initialize
override compose file
docker-compose.local.yml
docker-compose.server.yml
mage_root
/home/$HOST_USER/html/magento
/var/www/html/$DOMAIN_NAME
auto restart policy
never
unless-stopped
nginx sever_name / ssl
localhost / no ssl
$DOMAIN_NAME / with ssl
php fpm pool max child
static, 6
static, 14
varnish memory
256 mb
512 mb
elasticsearch memory
256 mb
512 mb
cron / rabbitmq
optional, add manually if needed
installed
Local initialize
Run the script
sudo ./local-initialize.sh
Server initialize
Replace $domain_name with your domain name without protocol and run the script
sudo ./server-initialize.sh $domain_name
Enviroment variables for frequent commands
Restart the pc to apply enviroment variables set by initilization script
All containers in magento stack use $magento_stack command example $magento_stack ps
Magento 2 cli use $cli_magento command example $cli_magento setup:upgrade
Composer use $cli_composer command example $cli_composer info
Npm use $cli_npm command example $cli_npm install
Grunt cli use $cli_grunt command example $cli_grunt exec
Redis cli use $redis_cli command example $redis_cli info
Rabbitmq cli use $rabbitmq_ctl command example $rabbitmq_ctl info
Commands for other services
Nginx use docker exec example docker exec -it nginx nginx -s reload
Varnish use docker exec example docker exec -it varnish varnishstat
Mysql cli use docker exec for example docker exec -it mysql mysql -u $user -p
Mysql admin tasks use host based mysql-client for example mysqldump -h 127.0.0.1 -u $user -p
Elasticsearch use curl localhost:port example curl localhost:9200/_cat/health?pretty
Up the docker enviromnment
Edit the .env file set by initilization script and make any changes if required
Run the command to build images and start the containers
$magento_stack up -d
Run this command after previous step finishes to check if all containers are up and running
$magento_stack ps
Generate ssl certificates and setup renew hook for installation on server
Clear the dummy certificates set by initilization script
Now you should have a fully working Magento 2 instance
5. Extra optimizations
Elasticsearch replicas configuration
Elasticsearch tries to create an additional replica of each indexes by default on second node, since local development will only have one node this will never succeed.
This causes half the shards to be unassigned and cluster health to be yellow.
Use these commands to set default replica configuration to 0 for current and all future indexes.
# Replica setting for all new index
curl -XPUT "localhost:9200/_template/default_template" -H 'Content-Type: application/json' -d'
{
"index_patterns": ["*"],
"settings": {
"index": {
"number_of_replicas": 0
}
}
}'
# Replica setting for current index
curl -XPUT 'localhost:9200/_settings' -H 'Content-Type: application/json' -d'
{
"index" : {
"number_of_replicas" : 0
}
}'