SlideShare a Scribd company logo
T H E T H E O R Y   A N D I M P L E M E N T
M A G E N T O 2
C A P I S T R A N O
D e p l o y M a g e n t o 2
C a p i s t r a n o
M a g e n t o 2 C a p i s t r a n o
Q u e s t i o n s
C O N T E N T
D E P L O Y M A G E N T O 2
Update Repository
Composer pull down
Sync files
Deploy static files
Enable maintenance
Enable modules
D E P L O Y M A G E N T O 2
Run setup scripts
Clear cache
Disable maintenance mode
Update permissions
Restart PHP FPM
C A P I S T R A N O
s
Capistrano is a framework for building automated deployment
scripts
Multiple stages
Parallel execution
Server roles
Community driven
It's just SSH
C A P I S T R A N O
s
Benefits:
Deploy automatically
Reduce risk for deploy process
Easy to customize
C A P I S T R A N O
s
Prerequisite:
Ruby version 2.0 or higher
A project that uses source control
Bundler, along with a Gemfile for your project
Note:
- Create a Gemfile by Bundle with 'bundle init'
command.
C A P I S T R A N O
s
How it working:
Connect to the server via forward SSH and
pull down codebase.
Create a release for each deploy time.
The current project will refer to latest success
release.
Fallback to latest success release if deploy
process to break down.
C A P I S T R A N O
s
Install:
Add Capistrano to your project's Gemfile:
group :development do
gem "capistrano", "~> 3.8"
end
Capify project:
bundle install
bundle exec cap install
C A P I S T R A N O
s
Folder Structure:
├── Capfile
├── config
│ ├── deploy
│ │ ├── production.rb
│ │ └── staging.rb
│ └── deploy.rb
└── lib
└── capistrano
└── tasks
C A P I S T R A N O
s
Configuring config/deploy.rb:
set :application, 'example'
set :repo_url, 'git@github.com:acme/example-com.git'
Update the :application and :repo_url values in config/deploy.rb:
For each stage, e.g 'config/deploy/production', set the branch
and :deploy_to folder for pulling code:
set :branch, 'master'
set :deploy_to, "/var/www/my_app_name"
C A P I S T R A N O
s
Configuring config/deploy/*.rb:
server 'www.example.com', user: 'www-data', roles: %w{app
db web}
set :deploy_to, '/var/www/html'
set :branch, proc { `git rev-parse --abbrev-ref master`.chomp
}
Single application server
C A P I S T R A N O
s
Customize tasks:
namespace :magento2 do
desc "Restart PHP FPM"
task :restart_php_fpm do
on roles(:all), in: :sequence, wait: 1 do
execute :sudo, 'service php7.0-fpm restart'
end
end
end
Define helper tasks in lib/capistrano/tasks file.
In my project, I also create a task for upload adminer.php file using for
staging site.
C A P I S T R A N O
s
Project Structure:
├── current -> latest release
├── releases
│ ├── 20170420014820
│ ├── 20170420014820
│
└── repo
│
└── shared
C A P I S T R A N O
s
Usage:
Single application server:
bundle exec cap <stage> deploy
# bundle exec cap production deploy
Multiple application server:
Refer to Capistrano documentation for detail on how to configure
multiple application servers.
List all available tasks:
bundle exec cap -T
M 2 C A P I S T R A N O
s
Install
Add the following to your project's Gemfile:
source 'https://rubygems.org'
gem 'capistrano-magento2'
Useful gem:
gem 'capistrano-composer'
gem 'capistrano-upload-config'
gem 'capistrano-file-permissions'
D E P L O Y S E T T I N G
s
Capistrano Built-Ins
set :linked_files, [
'app/etc/env.php',
'pub/.htaccess'
]
set :linked_dirs, [
'pub/media',
'var'
]
For prepared config files and keep the resource sync between
releases folders.
D E P L O Y S E T T I N G
s
Capistrano Built-Ins
set :config_files, %w{app/etc/env.php
pub/.htaccess}
# push link files after check them exist.
before 'deploy:check:linked_files', 'config:push'
Using capistrano-upload-config gem to push them into the server
Note:
- Link files must be named as filename.<stage>.extension, e.g
env.production.json in the repository project.
D E P L O Y S E T T I N G
s
Magento Deploy Settings
set :magento_deploy_setup_role, :all
set :magento_deploy_cache_shared, true
set :magento_deploy_languages, ['en_US']
set :magento_deploy_themes, []
set :magento_deploy_composer, true
set :magento_deploy_production, true
set :magento_deploy_maintenance, true
set :magento_deploy_confirm, []
D E P L O Y S E T T I N G
s
Magento Deploy Settings
Those tasks above for:
- Role for primary host.
- Cache operation.
- Setup languages for theme.
- Deploy static content files.
- Enables composer install.
- Enables production DI compilation.
- Enables use of maintenance mode.
- Used to require confirmation of deployment
D E P L O Y S E T T I N G
s
Magento Deploy Settings
set :magento_deploy_chmod_d, '0755'
set :magento_deploy_chmod_f, '0644'
set :magento_deploy_chmod_x, ['bin/magento']
set :file_permissions_roles, :all
set :file_permissions_paths, ["pub/static", "var"]
set :file_permissions_users, ["SERVER_USER"]
set :file_permissions_groups, ["SERVER_GROUP"]
set :file_permissions_chmod_mode, "0777"
before "deploy:updated", "deploy:set_permissions:acl"
D E P L O Y S E T T I N G
s
Magento Deploy Settings
Those commands above for setup permission and
ownership for all folders of project with some
specific for pub/static/ and var/ folder.
Capistrano using the setfacl to do that for
SERVER_USER and SERVER_GROUP account.
D E P L O Y S E T T I N G
s
Composer Auth Credentials
set :magento_auth_public_key,
'MAGENTO_USERNAME'
set :magento_auth_private_key,
'MAGENTO_PASSWORD'
This will execute that command below:
composer config --global --auth http-basic.repo.magento.com
MAGENTO_USERNAME MAGENTO_PASSWORD
D E P L O Y S E T T I N G
s
Magento Customize Tasks
before 'magento:deploy:verify', 'magento2:copy_config'
after 'magento:setup:static-content:deploy',
'magento2:add_adminer'
after 'magento:maintenance:disable',
'magento2:restart_php_fpm'
Note:
- The 'copy_config' is customized task, see details in Q&A
section.
Q U E S T I O N S
s
What the benefit of config.php.dist?
Answer:
It help you to controll what the modules you actually
want to using them in your project, it will converted to
config.php, so the your project must be have it in the
app/etc folder.
The customize task called 'copy_config' will help you to
do all of this, see in my example repository for how to
create this task.
Q U E S T I O N S
s
Why must to restart PHP FPM?
Answer:
We need to restart PHP FPM to flush cache of Zend
Opcache - a native extension built-in PHP.
Error: Don't know how to build task?
Answer:
Add require gem to the Capfile:
# Load Magento deployment tasks
require 'capistrano/magento2/deploy'
Q U E S T I O N S
s
Have any project for example?
Answer:
I created a Github repository, for example, I also using
it for deploying my Magento 2 site, you can refer it at
here:
https://github.com/unetstudio/magento-2-capistrano-
deploy
R E F E R E N C E S
s
https://github.com/capistrano/capistrano
https://github.com/davidalger/capistrano-magento2
https://github.com/unetstudio/magento-2-capistrano-
deploy
https://github.com/bundler/bundler
A B O U T M E
s
Hi there, I'm Duc Dao. A web developer living in Hanoi,
Vietnam. Currently, I'm working in SmartOSC
corporation and love to share knowledge.
Email: huuduc.uneti@gmail.com
Website: http://newbie-dev.net
D U C D A O
T H A N K Y O U !
Ad

More Related Content

What's hot (20)

What's new in Gerrit Code Review 3.0
What's new in Gerrit Code Review 3.0What's new in Gerrit Code Review 3.0
What's new in Gerrit Code Review 3.0
Luca Milanesio
 
Bitbucket
BitbucketBitbucket
Bitbucket
hariprasad1035
 
Bamboo - an introduction
Bamboo - an introductionBamboo - an introduction
Bamboo - an introduction
Sven Peters
 
Migrating To GitHub
Migrating To GitHub  Migrating To GitHub
Migrating To GitHub
Sridhar Peddinti
 
Github PowerPoint Final
Github PowerPoint FinalGithub PowerPoint Final
Github PowerPoint Final
Elizabeth Walden
 
Deep Dive into Keystone Tokens and Lessons Learned
Deep Dive into Keystone Tokens and Lessons LearnedDeep Dive into Keystone Tokens and Lessons Learned
Deep Dive into Keystone Tokens and Lessons Learned
Priti Desai
 
Alphorm.com Formation SOPHOS XG FIREWALL, Administration
Alphorm.com Formation SOPHOS XG FIREWALL, AdministrationAlphorm.com Formation SOPHOS XG FIREWALL, Administration
Alphorm.com Formation SOPHOS XG FIREWALL, Administration
Alphorm
 
8 palo alto security policy concepts
8 palo alto security policy concepts8 palo alto security policy concepts
8 palo alto security policy concepts
Mostafa El Lathy
 
Stateless authentication with OAuth 2 and JWT - JavaZone 2015
Stateless authentication with OAuth 2 and JWT - JavaZone 2015Stateless authentication with OAuth 2 and JWT - JavaZone 2015
Stateless authentication with OAuth 2 and JWT - JavaZone 2015
Alvaro Sanchez-Mariscal
 
Getting started with GitHub Desktop
Getting started with GitHub DesktopGetting started with GitHub Desktop
Getting started with GitHub Desktop
Aram Panasenco
 
An introduction to OAuth 2
An introduction to OAuth 2An introduction to OAuth 2
An introduction to OAuth 2
Sanjoy Kumar Roy
 
Credential store using HashiCorp Vault
Credential store using HashiCorp VaultCredential store using HashiCorp Vault
Credential store using HashiCorp Vault
Mayank Patel
 
Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)
Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)
Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)
Svetlin Nakov
 
OAuth 2.0
OAuth 2.0OAuth 2.0
OAuth 2.0
Uwe Friedrichsen
 
KubeCon 2022 EU Flux Security.pdf
KubeCon 2022 EU Flux Security.pdfKubeCon 2022 EU Flux Security.pdf
KubeCon 2022 EU Flux Security.pdf
Weaveworks
 
Open vSwitch - Stateful Connection Tracking & Stateful NAT
Open vSwitch - Stateful Connection Tracking & Stateful NATOpen vSwitch - Stateful Connection Tracking & Stateful NAT
Open vSwitch - Stateful Connection Tracking & Stateful NAT
Thomas Graf
 
SCM (Source Control Management) - Git Basic
SCM (Source Control Management) - Git Basic SCM (Source Control Management) - Git Basic
SCM (Source Control Management) - Git Basic
Aman Patial
 
Best practices for Terraform with Vault
Best practices for Terraform with VaultBest practices for Terraform with Vault
Best practices for Terraform with Vault
Mitchell Pronschinske
 
Quick Introduction to git
Quick Introduction to gitQuick Introduction to git
Quick Introduction to git
Joel Krebs
 
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Simplilearn
 
What's new in Gerrit Code Review 3.0
What's new in Gerrit Code Review 3.0What's new in Gerrit Code Review 3.0
What's new in Gerrit Code Review 3.0
Luca Milanesio
 
Bamboo - an introduction
Bamboo - an introductionBamboo - an introduction
Bamboo - an introduction
Sven Peters
 
Deep Dive into Keystone Tokens and Lessons Learned
Deep Dive into Keystone Tokens and Lessons LearnedDeep Dive into Keystone Tokens and Lessons Learned
Deep Dive into Keystone Tokens and Lessons Learned
Priti Desai
 
Alphorm.com Formation SOPHOS XG FIREWALL, Administration
Alphorm.com Formation SOPHOS XG FIREWALL, AdministrationAlphorm.com Formation SOPHOS XG FIREWALL, Administration
Alphorm.com Formation SOPHOS XG FIREWALL, Administration
Alphorm
 
8 palo alto security policy concepts
8 palo alto security policy concepts8 palo alto security policy concepts
8 palo alto security policy concepts
Mostafa El Lathy
 
Stateless authentication with OAuth 2 and JWT - JavaZone 2015
Stateless authentication with OAuth 2 and JWT - JavaZone 2015Stateless authentication with OAuth 2 and JWT - JavaZone 2015
Stateless authentication with OAuth 2 and JWT - JavaZone 2015
Alvaro Sanchez-Mariscal
 
Getting started with GitHub Desktop
Getting started with GitHub DesktopGetting started with GitHub Desktop
Getting started with GitHub Desktop
Aram Panasenco
 
An introduction to OAuth 2
An introduction to OAuth 2An introduction to OAuth 2
An introduction to OAuth 2
Sanjoy Kumar Roy
 
Credential store using HashiCorp Vault
Credential store using HashiCorp VaultCredential store using HashiCorp Vault
Credential store using HashiCorp Vault
Mayank Patel
 
Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)
Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)
Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)
Svetlin Nakov
 
KubeCon 2022 EU Flux Security.pdf
KubeCon 2022 EU Flux Security.pdfKubeCon 2022 EU Flux Security.pdf
KubeCon 2022 EU Flux Security.pdf
Weaveworks
 
Open vSwitch - Stateful Connection Tracking & Stateful NAT
Open vSwitch - Stateful Connection Tracking & Stateful NATOpen vSwitch - Stateful Connection Tracking & Stateful NAT
Open vSwitch - Stateful Connection Tracking & Stateful NAT
Thomas Graf
 
SCM (Source Control Management) - Git Basic
SCM (Source Control Management) - Git Basic SCM (Source Control Management) - Git Basic
SCM (Source Control Management) - Git Basic
Aman Patial
 
Best practices for Terraform with Vault
Best practices for Terraform with VaultBest practices for Terraform with Vault
Best practices for Terraform with Vault
Mitchell Pronschinske
 
Quick Introduction to git
Quick Introduction to gitQuick Introduction to git
Quick Introduction to git
Joel Krebs
 
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Simplilearn
 

Similar to Magento 2 Capistrano Deploy (20)

Magento 2 Development
Magento 2 DevelopmentMagento 2 Development
Magento 2 Development
Duke Dao
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.cat
Pablo Godel
 
Maven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension toolMaven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension tool
elliando dias
 
Magento2 From Setup To Deployment. Automate Everything
Magento2 From Setup To Deployment. Automate EverythingMagento2 From Setup To Deployment. Automate Everything
Magento2 From Setup To Deployment. Automate Everything
Juan Alonso
 
Capistrano
CapistranoCapistrano
Capistrano
Jason Noble
 
Capifony. Minsk PHP MeetUp #11
Capifony. Minsk PHP MeetUp #11Capifony. Minsk PHP MeetUp #11
Capifony. Minsk PHP MeetUp #11
Yury Pliashkou
 
Professional deployment
Professional deploymentProfessional deployment
Professional deployment
Ivelina Dimova
 
Using Maven2
Using Maven2Using Maven2
Using Maven2
elliando dias
 
Instrumentación de entrega continua con Gitlab
Instrumentación de entrega continua con GitlabInstrumentación de entrega continua con Gitlab
Instrumentación de entrega continua con Gitlab
Software Guru
 
Introduction maven3 and gwt2.5 rc2 - Lesson 01
Introduction maven3 and gwt2.5 rc2 - Lesson 01Introduction maven3 and gwt2.5 rc2 - Lesson 01
Introduction maven3 and gwt2.5 rc2 - Lesson 01
rhemsolutions
 
Capistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient wayCapistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient way
Sylvain Rayé
 
drupal ci cd concept cornel univercity.pptx
drupal ci cd concept cornel univercity.pptxdrupal ci cd concept cornel univercity.pptx
drupal ci cd concept cornel univercity.pptx
rukuntravel
 
Slim3 quick start
Slim3 quick startSlim3 quick start
Slim3 quick start
Guangyao Cao
 
Infrastructure = code - 1 year later
Infrastructure = code - 1 year laterInfrastructure = code - 1 year later
Infrastructure = code - 1 year later
Christian Ortner
 
Vagrant introduction for Developers
Vagrant introduction for DevelopersVagrant introduction for Developers
Vagrant introduction for Developers
Antons Kranga
 
Pyramid deployment
Pyramid deploymentPyramid deployment
Pyramid deployment
Carlos de la Guardia
 
Rock-solid Magento Development and Deployment Workflows
Rock-solid Magento Development and Deployment WorkflowsRock-solid Magento Development and Deployment Workflows
Rock-solid Magento Development and Deployment Workflows
AOE
 
Development Setup of B-Translator
Development Setup of B-TranslatorDevelopment Setup of B-Translator
Development Setup of B-Translator
Dashamir Hoxha
 
How to install squid proxy on server or how to install squid proxy on centos o
How to install squid proxy on server  or how to install squid proxy on centos oHow to install squid proxy on server  or how to install squid proxy on centos o
How to install squid proxy on server or how to install squid proxy on centos o
Proxiesforrent
 
Getting Started With CFEngine - Updated Version
Getting Started With CFEngine - Updated VersionGetting Started With CFEngine - Updated Version
Getting Started With CFEngine - Updated Version
CFEngine
 
Magento 2 Development
Magento 2 DevelopmentMagento 2 Development
Magento 2 Development
Duke Dao
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.cat
Pablo Godel
 
Maven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension toolMaven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension tool
elliando dias
 
Magento2 From Setup To Deployment. Automate Everything
Magento2 From Setup To Deployment. Automate EverythingMagento2 From Setup To Deployment. Automate Everything
Magento2 From Setup To Deployment. Automate Everything
Juan Alonso
 
Capifony. Minsk PHP MeetUp #11
Capifony. Minsk PHP MeetUp #11Capifony. Minsk PHP MeetUp #11
Capifony. Minsk PHP MeetUp #11
Yury Pliashkou
 
Professional deployment
Professional deploymentProfessional deployment
Professional deployment
Ivelina Dimova
 
Instrumentación de entrega continua con Gitlab
Instrumentación de entrega continua con GitlabInstrumentación de entrega continua con Gitlab
Instrumentación de entrega continua con Gitlab
Software Guru
 
Introduction maven3 and gwt2.5 rc2 - Lesson 01
Introduction maven3 and gwt2.5 rc2 - Lesson 01Introduction maven3 and gwt2.5 rc2 - Lesson 01
Introduction maven3 and gwt2.5 rc2 - Lesson 01
rhemsolutions
 
Capistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient wayCapistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient way
Sylvain Rayé
 
drupal ci cd concept cornel univercity.pptx
drupal ci cd concept cornel univercity.pptxdrupal ci cd concept cornel univercity.pptx
drupal ci cd concept cornel univercity.pptx
rukuntravel
 
Infrastructure = code - 1 year later
Infrastructure = code - 1 year laterInfrastructure = code - 1 year later
Infrastructure = code - 1 year later
Christian Ortner
 
Vagrant introduction for Developers
Vagrant introduction for DevelopersVagrant introduction for Developers
Vagrant introduction for Developers
Antons Kranga
 
Rock-solid Magento Development and Deployment Workflows
Rock-solid Magento Development and Deployment WorkflowsRock-solid Magento Development and Deployment Workflows
Rock-solid Magento Development and Deployment Workflows
AOE
 
Development Setup of B-Translator
Development Setup of B-TranslatorDevelopment Setup of B-Translator
Development Setup of B-Translator
Dashamir Hoxha
 
How to install squid proxy on server or how to install squid proxy on centos o
How to install squid proxy on server  or how to install squid proxy on centos oHow to install squid proxy on server  or how to install squid proxy on centos o
How to install squid proxy on server or how to install squid proxy on centos o
Proxiesforrent
 
Getting Started With CFEngine - Updated Version
Getting Started With CFEngine - Updated VersionGetting Started With CFEngine - Updated Version
Getting Started With CFEngine - Updated Version
CFEngine
 
Ad

Recently uploaded (20)

Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Ad

Magento 2 Capistrano Deploy

  • 1. T H E T H E O R Y   A N D I M P L E M E N T M A G E N T O 2 C A P I S T R A N O
  • 2. D e p l o y M a g e n t o 2 C a p i s t r a n o M a g e n t o 2 C a p i s t r a n o Q u e s t i o n s C O N T E N T
  • 3. D E P L O Y M A G E N T O 2 Update Repository Composer pull down Sync files Deploy static files Enable maintenance Enable modules
  • 4. D E P L O Y M A G E N T O 2 Run setup scripts Clear cache Disable maintenance mode Update permissions Restart PHP FPM
  • 5. C A P I S T R A N O s Capistrano is a framework for building automated deployment scripts Multiple stages Parallel execution Server roles Community driven It's just SSH
  • 6. C A P I S T R A N O s Benefits: Deploy automatically Reduce risk for deploy process Easy to customize
  • 7. C A P I S T R A N O s Prerequisite: Ruby version 2.0 or higher A project that uses source control Bundler, along with a Gemfile for your project Note: - Create a Gemfile by Bundle with 'bundle init' command.
  • 8. C A P I S T R A N O s How it working: Connect to the server via forward SSH and pull down codebase. Create a release for each deploy time. The current project will refer to latest success release. Fallback to latest success release if deploy process to break down.
  • 9. C A P I S T R A N O s Install: Add Capistrano to your project's Gemfile: group :development do gem "capistrano", "~> 3.8" end Capify project: bundle install bundle exec cap install
  • 10. C A P I S T R A N O s Folder Structure: ├── Capfile ├── config │ ├── deploy │ │ ├── production.rb │ │ └── staging.rb │ └── deploy.rb └── lib └── capistrano └── tasks
  • 11. C A P I S T R A N O s Configuring config/deploy.rb: set :application, 'example' set :repo_url, '[email protected]:acme/example-com.git' Update the :application and :repo_url values in config/deploy.rb: For each stage, e.g 'config/deploy/production', set the branch and :deploy_to folder for pulling code: set :branch, 'master' set :deploy_to, "/var/www/my_app_name"
  • 12. C A P I S T R A N O s Configuring config/deploy/*.rb: server 'www.example.com', user: 'www-data', roles: %w{app db web} set :deploy_to, '/var/www/html' set :branch, proc { `git rev-parse --abbrev-ref master`.chomp } Single application server
  • 13. C A P I S T R A N O s Customize tasks: namespace :magento2 do desc "Restart PHP FPM" task :restart_php_fpm do on roles(:all), in: :sequence, wait: 1 do execute :sudo, 'service php7.0-fpm restart' end end end Define helper tasks in lib/capistrano/tasks file. In my project, I also create a task for upload adminer.php file using for staging site.
  • 14. C A P I S T R A N O s Project Structure: ├── current -> latest release ├── releases │ ├── 20170420014820 │ ├── 20170420014820 │ └── repo │ └── shared
  • 15. C A P I S T R A N O s Usage: Single application server: bundle exec cap <stage> deploy # bundle exec cap production deploy Multiple application server: Refer to Capistrano documentation for detail on how to configure multiple application servers. List all available tasks: bundle exec cap -T
  • 16. M 2 C A P I S T R A N O s Install Add the following to your project's Gemfile: source 'https://rubygems.org' gem 'capistrano-magento2' Useful gem: gem 'capistrano-composer' gem 'capistrano-upload-config' gem 'capistrano-file-permissions'
  • 17. D E P L O Y S E T T I N G s Capistrano Built-Ins set :linked_files, [ 'app/etc/env.php', 'pub/.htaccess' ] set :linked_dirs, [ 'pub/media', 'var' ] For prepared config files and keep the resource sync between releases folders.
  • 18. D E P L O Y S E T T I N G s Capistrano Built-Ins set :config_files, %w{app/etc/env.php pub/.htaccess} # push link files after check them exist. before 'deploy:check:linked_files', 'config:push' Using capistrano-upload-config gem to push them into the server Note: - Link files must be named as filename.<stage>.extension, e.g env.production.json in the repository project.
  • 19. D E P L O Y S E T T I N G s Magento Deploy Settings set :magento_deploy_setup_role, :all set :magento_deploy_cache_shared, true set :magento_deploy_languages, ['en_US'] set :magento_deploy_themes, [] set :magento_deploy_composer, true set :magento_deploy_production, true set :magento_deploy_maintenance, true set :magento_deploy_confirm, []
  • 20. D E P L O Y S E T T I N G s Magento Deploy Settings Those tasks above for: - Role for primary host. - Cache operation. - Setup languages for theme. - Deploy static content files. - Enables composer install. - Enables production DI compilation. - Enables use of maintenance mode. - Used to require confirmation of deployment
  • 21. D E P L O Y S E T T I N G s Magento Deploy Settings set :magento_deploy_chmod_d, '0755' set :magento_deploy_chmod_f, '0644' set :magento_deploy_chmod_x, ['bin/magento'] set :file_permissions_roles, :all set :file_permissions_paths, ["pub/static", "var"] set :file_permissions_users, ["SERVER_USER"] set :file_permissions_groups, ["SERVER_GROUP"] set :file_permissions_chmod_mode, "0777" before "deploy:updated", "deploy:set_permissions:acl"
  • 22. D E P L O Y S E T T I N G s Magento Deploy Settings Those commands above for setup permission and ownership for all folders of project with some specific for pub/static/ and var/ folder. Capistrano using the setfacl to do that for SERVER_USER and SERVER_GROUP account.
  • 23. D E P L O Y S E T T I N G s Composer Auth Credentials set :magento_auth_public_key, 'MAGENTO_USERNAME' set :magento_auth_private_key, 'MAGENTO_PASSWORD' This will execute that command below: composer config --global --auth http-basic.repo.magento.com MAGENTO_USERNAME MAGENTO_PASSWORD
  • 24. D E P L O Y S E T T I N G s Magento Customize Tasks before 'magento:deploy:verify', 'magento2:copy_config' after 'magento:setup:static-content:deploy', 'magento2:add_adminer' after 'magento:maintenance:disable', 'magento2:restart_php_fpm' Note: - The 'copy_config' is customized task, see details in Q&A section.
  • 25. Q U E S T I O N S s What the benefit of config.php.dist? Answer: It help you to controll what the modules you actually want to using them in your project, it will converted to config.php, so the your project must be have it in the app/etc folder. The customize task called 'copy_config' will help you to do all of this, see in my example repository for how to create this task.
  • 26. Q U E S T I O N S s Why must to restart PHP FPM? Answer: We need to restart PHP FPM to flush cache of Zend Opcache - a native extension built-in PHP. Error: Don't know how to build task? Answer: Add require gem to the Capfile: # Load Magento deployment tasks require 'capistrano/magento2/deploy'
  • 27. Q U E S T I O N S s Have any project for example? Answer: I created a Github repository, for example, I also using it for deploying my Magento 2 site, you can refer it at here: https://github.com/unetstudio/magento-2-capistrano- deploy
  • 28. R E F E R E N C E S s https://github.com/capistrano/capistrano https://github.com/davidalger/capistrano-magento2 https://github.com/unetstudio/magento-2-capistrano- deploy https://github.com/bundler/bundler
  • 29. A B O U T M E s Hi there, I'm Duc Dao. A web developer living in Hanoi, Vietnam. Currently, I'm working in SmartOSC corporation and love to share knowledge. Email: [email protected] Website: http://newbie-dev.net
  • 30. D U C D A O T H A N K Y O U !