SlideShare a Scribd company logo
Best Practices for
development & deployment
More structured, more productive, more
done!
Somedutta Ghosh
Best practices in -
★ Drupal - security, structuring, custom coding,
etc.
★ Git - Version control tool
★ Deployment method
★ Drush
Drupal Best Practices
● NEVER. HACK. CORE.
Drupal Best Practices
● No development on live.
● Disable development modules on production/live environment.
○ views_ui
○ field_ui
○ devel
● All drupal level logging should be on only on non-production
environments; only server level logging on live.
○ dblog off - syslog on
Drupal Best Practices
● Preferable to use server level logging instead of
drupal logging, as this will remove unnecessary
database writing for the application.
● Choosing Syslog over Drupal watchdog
● Enable logging of slow queries in mysql.
Drupal Best Practices
● Files and directory ownership and permissions,
○ group should include web server, and
○ only owner and group should be given permissions.
Drupal Best Practices
● JS, CSS should not be present in database (css inside the element
can be present as we could have with wysiwyg text editor)
○ no jss/css in node content
○ no jss/css in block content
<script type="text/javascript" >
jQuery(window).load(function() {
jQuery('.pics').cycle({
fx: 'scrollLeft',
next: '#right',
delay: 2000 ,
});
});
</script>
<style>
.pics {
width: 100%;
margin: 10px;
}
</style>
Writing Custom Code
● Add helpful documentations for
all modules. Always add a
README.txt file in all custom
modules.
● Add documentation for functions
and inline comments for
understanding the code.
Writing Custom Code
● Before writing custom, look for contrib.
● Make sure you use the extensive drupal API instead of
writing custom functions/code.
● Use drupal database API for making db calls.
● Use drupal form API for creating forms.
● Use theme functions like theme_image, theme_links
instead of writing raw html.
● To show any text always use the t() function.
● For creating links always use l() function instead of a tags.
Writing Custom Code
● Try to avoid writing functionality related code in theme.
● Follow naming conventions for easier management.
● all features can be prepended by ‘feature_’
● all custom modules and theme can be prepended by the
initials of the sitename. eg. for site ‘Alpha’ use ‘a_’ or
‘alpha_’
Modules - contrib and custom
● Improve structuring - move modules to separate folders
under sites/all/modules/ depending on custom, contrib,
features or modified.
Modules - contrib and custom
● Often we need to apply patches or modify contrib
modules. In such a case,
○ create another folder under modules - patches
○ store all applied patch inside this
○ keep a README.txt file in /patch folder to record
patches applied, the module they were applied on and
their purpose
○ when modifying modules, create a patch from them
and treat those patches same as other patches
Make your modules Modular!
● Separate functionalities should go into separate modules.
● Use small functions, where each function performs a
specific part of a big functionality. Try making these
functions as general as possible and use arguments
instead of hardcoding, such that they can be used multiple
times and with different data.
● For long and heavy operations, use batch process.
Custom modules
● Use the theme layer for printing HTML. Use tpl files for
large amounts of HTML code. Small html code could go into
non-tpm files like .module files.
● CSS/JS for specific pages should not be added on every
page
○ if adding css/js to every page through hook init move
them to theme’s info file
○ add these files through page callbacks
Theme
● PHP should be present in tpl files for either conditions or
printing variables; all calculations should be done in template.
php file.
● CSS/JS should not be present in template.php; add them
through files and included via theme’s info file.
Git Best Practices
Essential to use version control. The greatest plus points of git
are -
● branching - multiple functionalities can be kept separate
● distributed - multiple developers can work on the same
codebase at the same time, and git smoothly merges the
code
● different versions of the same file - with extensive options
of viewing log of changes, one can see when a file or a line
of code was added
Git Best Practices
● Keep individual functionalities in individual branches
● When on a feature branch, merge with the base branch often
● Branch out from development branch for new functionality.
● Branch out from master(production) branch for production bug
fixes.
Git Best Practices
● Have intuitive branch names - eg. each
feature/functionality branch prepended with feat_ or each
bugfix branch prepended with bugfix_
● production, stage, dev - different instances in the
development tree - deploy a different branch on each
instance - master, stage, dev respectively.
Git Best Practices
● Commit early. Commit often.
● Commit messages should be useful, insightful and
descriptive
● Make a habit of git commit instead of git commit -m
“[message]”. This opens an editor where you can write a
more descriptive commit message
● Set up a .gitignore file - to exclude configuration files that
are server environment dependent and large binary files
● Do not add settings.php and files folder in git repository
● After completing a feature from local to production, delete the
Deployment Best Practices
● 3 environments should be used - production, staging and
development.
● dev - any new code is first deployed and tested here. work from all
developers will be tested here
● stage/test - the content will be same as the live instance and
updated code from dev will be tested here
● production/live - it is the live instance. New code/functionality after
passing tests on the stage environment, can be moved to live.
Deployment Best Practices
● All changes should always go through dev and staging
before production so that the changes can be extensively
tested.
● Version control tool should be used since it makes moving
code between environments very easy and especially
useful when multiple people are working on the same code.
● Use features and strongarm to move database changes
between environments - reduces configuration times on
different environments.
Drush - do less, get more
● drush cc all - clear all cache
● drush dl [project_name] - download modules
● drush en -y [project_name] - enable modules
● drush dis -y [project_name] - disable modules
● drush pm-uninstall -y [project_name] - uninstalll modules
● drush pm-list - show list of modules with their status, enabled,
disabled, not installed
Drush - do less, get more
● drush fl - to list all features and show their state, overridden or not
● drush fd [feature_name] - show overrides in feature; you will need
module diff for using this command
● drush fu -y [feature_name] - updates the feature(db to code)
● drush fr -y [feature_name] - reverts the feature(code to db)
● creating feature using drush
○ drush fe [feature-name] [feature-component(s)] - export/create or
update a feature with one or more components
○ drush fc - show a list of feature components that can be exported
into features
Drush - do less, get more
● drush updb - running update.php from drush
● drush cron - run cron from drush
● drush ws - show list of latest 10(default count, can be increased with
option in command) messages messages
● drush upwd - Reset the password for an user account that has the
given username(username to be specified in command)
● drush sqlq “[sql-query]” - run any db query from drush
● drush sql-dump - take a sql dump of the current site’s database
Drush - do less, get more
Drush alias -
● an alias is basically a short name for a drupal installation. It is a set
of options that collectively define that installation.
● its biggest advantage is super easy syncing with remote servers and
running drush commands on remote servers locally
Drush - do less, get more
● create a drush alias file - sitename.alias.drushrc.php, eg alpha.alias.
drushrc.php
● place it in either of -
○ ~/.drush
○ sites/all/drush
● the simplest content of an alias file could be
<?php
$aliases[local] = array(
'root' => '/var/www/alpha'
);
● now you can access your local environment for drush through -
drush @alpha.local status
Drush - do less, get more
● for adding a remote configuration, eg. dev on a remote server, add
following to above alias file
$aliases[dev] = array(
'root' => '/home/alpha/public_html',
'remote-host' => 'alpha.dev.com',
'remote-user' => alpha',
);
● if ssh requires password authentication, add this to alias config of the
remote - 'ssh-options' => '-o PasswordAuthentication=yes' - this will
prompt for password every time you use drush with the remote’s
alias
Drush - do less, get more
● we now have 2 aliases for the site alpha
* drush @alpha.local * drush @alpha.dev
● syncing local database with remote with single command
○ drush sql-sync [source] [destination]
○ drush sql-sync @alpha.dev@alpha.local
● syncing local files folder with remote with single command and
drush alias
○ drush rsync [source]:sites/default/files/ [destination]:
sites/default/files/
○ drush rsync @alpha.dev:sites/default/files/ @alpha.local:
sites/default/files/
Drush - do less, get more
● drush help - list of drush commands and their use; drush help [command]
gives more help information about a specific command

More Related Content

What's hot

Evolution of Drupal and the Drupal community
Evolution of Drupal and the Drupal communityEvolution of Drupal and the Drupal community
Evolution of Drupal and the Drupal community
Angela Byron
 
Migrate to Drupal 8
Migrate to Drupal 8Migrate to Drupal 8
Migrate to Drupal 8
Claudiu Cristea
 
Drupal in-depth
Drupal in-depthDrupal in-depth
Drupal in-depth
Kathryn Carruthers
 
Speedrun: Build a Website with Panels, Media, and More in 45 Minutes
Speedrun: Build a Website with Panels, Media, and More in 45 MinutesSpeedrun: Build a Website with Panels, Media, and More in 45 Minutes
Speedrun: Build a Website with Panels, Media, and More in 45 Minutes
Acquia
 
Speed up Drupal development with Drush
Speed up Drupal development with DrushSpeed up Drupal development with Drush
Speed up Drupal development with Drushkbasarab
 
Building and Maintaining a Distribution in Drupal 7 with Features
Building and Maintaining a  Distribution in Drupal 7 with FeaturesBuilding and Maintaining a  Distribution in Drupal 7 with Features
Building and Maintaining a Distribution in Drupal 7 with Features
Nuvole
 
Drupal 6 to 7 migration guide
Drupal 6 to 7 migration guideDrupal 6 to 7 migration guide
Drupal 6 to 7 migration guideEbizon
 
Drupal 8: frontend development
Drupal 8: frontend developmentDrupal 8: frontend development
Drupal 8: frontend development
sparkfabrik
 
Using Grunt with Drupal
Using Grunt with DrupalUsing Grunt with Drupal
Using Grunt with Drupal
arithmetric
 
Drupal Migrations in 2018
Drupal Migrations in 2018Drupal Migrations in 2018
Drupal Migrations in 2018
Pantheon
 
How to Migrate Drupal 6 to Drupal 8?
How to Migrate Drupal 6 to Drupal 8?How to Migrate Drupal 6 to Drupal 8?
How to Migrate Drupal 6 to Drupal 8?
DrupalGeeks
 
History of Drupal: From Drop 1.0 to Drupal 8
History of Drupal: From Drop 1.0 to Drupal 8History of Drupal: From Drop 1.0 to Drupal 8
History of Drupal: From Drop 1.0 to Drupal 8
Websolutions Agency
 
Drupal 8 Configuration Management for you and your team
Drupal 8 Configuration Management for you and your teamDrupal 8 Configuration Management for you and your team
Drupal 8 Configuration Management for you and your team
Luc Bézier
 
How a Content Delivery Network Can Help Speed Up Your Website
How a Content Delivery Network Can Help Speed Up Your WebsiteHow a Content Delivery Network Can Help Speed Up Your Website
How a Content Delivery Network Can Help Speed Up Your Website
Mediacurrent
 
Composer Tools & Frameworks for Drupal
Composer Tools & Frameworks for DrupalComposer Tools & Frameworks for Drupal
Composer Tools & Frameworks for Drupal
Pantheon
 
Taking your site from Drupal 6 to Drupal 7
Taking your site from Drupal 6 to Drupal 7Taking your site from Drupal 6 to Drupal 7
Taking your site from Drupal 6 to Drupal 7
Phase2
 
Introduction to Composer for Drupal
Introduction to Composer for DrupalIntroduction to Composer for Drupal
Introduction to Composer for Drupal
Luc Bézier
 
The OpenEuropa Initiative
The OpenEuropa InitiativeThe OpenEuropa Initiative
The OpenEuropa Initiative
Nuvole
 
Plain english guide to drupal 8 criticals
Plain english guide to drupal 8 criticalsPlain english guide to drupal 8 criticals
Plain english guide to drupal 8 criticalsAngela Byron
 

What's hot (20)

Evolution of Drupal and the Drupal community
Evolution of Drupal and the Drupal communityEvolution of Drupal and the Drupal community
Evolution of Drupal and the Drupal community
 
Migrate to Drupal 8
Migrate to Drupal 8Migrate to Drupal 8
Migrate to Drupal 8
 
Drupal in-depth
Drupal in-depthDrupal in-depth
Drupal in-depth
 
Speedrun: Build a Website with Panels, Media, and More in 45 Minutes
Speedrun: Build a Website with Panels, Media, and More in 45 MinutesSpeedrun: Build a Website with Panels, Media, and More in 45 Minutes
Speedrun: Build a Website with Panels, Media, and More in 45 Minutes
 
Speed up Drupal development with Drush
Speed up Drupal development with DrushSpeed up Drupal development with Drush
Speed up Drupal development with Drush
 
Building and Maintaining a Distribution in Drupal 7 with Features
Building and Maintaining a  Distribution in Drupal 7 with FeaturesBuilding and Maintaining a  Distribution in Drupal 7 with Features
Building and Maintaining a Distribution in Drupal 7 with Features
 
Drupal 6 to 7 migration guide
Drupal 6 to 7 migration guideDrupal 6 to 7 migration guide
Drupal 6 to 7 migration guide
 
Drupal 8: frontend development
Drupal 8: frontend developmentDrupal 8: frontend development
Drupal 8: frontend development
 
Using Grunt with Drupal
Using Grunt with DrupalUsing Grunt with Drupal
Using Grunt with Drupal
 
Drupal Migrations in 2018
Drupal Migrations in 2018Drupal Migrations in 2018
Drupal Migrations in 2018
 
How to Migrate Drupal 6 to Drupal 8?
How to Migrate Drupal 6 to Drupal 8?How to Migrate Drupal 6 to Drupal 8?
How to Migrate Drupal 6 to Drupal 8?
 
Beginners Guide to Drupal
Beginners Guide to DrupalBeginners Guide to Drupal
Beginners Guide to Drupal
 
History of Drupal: From Drop 1.0 to Drupal 8
History of Drupal: From Drop 1.0 to Drupal 8History of Drupal: From Drop 1.0 to Drupal 8
History of Drupal: From Drop 1.0 to Drupal 8
 
Drupal 8 Configuration Management for you and your team
Drupal 8 Configuration Management for you and your teamDrupal 8 Configuration Management for you and your team
Drupal 8 Configuration Management for you and your team
 
How a Content Delivery Network Can Help Speed Up Your Website
How a Content Delivery Network Can Help Speed Up Your WebsiteHow a Content Delivery Network Can Help Speed Up Your Website
How a Content Delivery Network Can Help Speed Up Your Website
 
Composer Tools & Frameworks for Drupal
Composer Tools & Frameworks for DrupalComposer Tools & Frameworks for Drupal
Composer Tools & Frameworks for Drupal
 
Taking your site from Drupal 6 to Drupal 7
Taking your site from Drupal 6 to Drupal 7Taking your site from Drupal 6 to Drupal 7
Taking your site from Drupal 6 to Drupal 7
 
Introduction to Composer for Drupal
Introduction to Composer for DrupalIntroduction to Composer for Drupal
Introduction to Composer for Drupal
 
The OpenEuropa Initiative
The OpenEuropa InitiativeThe OpenEuropa Initiative
The OpenEuropa Initiative
 
Plain english guide to drupal 8 criticals
Plain english guide to drupal 8 criticalsPlain english guide to drupal 8 criticals
Plain english guide to drupal 8 criticals
 

Viewers also liked

Towards Secure and Dependable Authentication and Authorization Infrastructures
Towards Secure and Dependable Authentication and Authorization InfrastructuresTowards Secure and Dependable Authentication and Authorization Infrastructures
Towards Secure and Dependable Authentication and Authorization Infrastructures
Diego Kreutz
 
Best Practices for Drupal Integrations
Best Practices for Drupal IntegrationsBest Practices for Drupal Integrations
Best Practices for Drupal IntegrationsAcquia
 
High Availability Application Architectures in Amazon VPC (ARC202) | AWS re:I...
High Availability Application Architectures in Amazon VPC (ARC202) | AWS re:I...High Availability Application Architectures in Amazon VPC (ARC202) | AWS re:I...
High Availability Application Architectures in Amazon VPC (ARC202) | AWS re:I...
Amazon Web Services
 
Social media tools for inteam communication
Social media tools for inteam communicationSocial media tools for inteam communication
Social media tools for inteam communication
Nata Isaevich
 
Highlights Of My Life
Highlights Of My LifeHighlights Of My Life
Highlights Of My LifeTomoya Shoji
 
Как заставить инвестора сказать «да»
Как заставить инвестора сказать «да»Как заставить инвестора сказать «да»
Как заставить инвестора сказать «да»
Nata Isaevich
 
Enhancing PowerPoint in the Classroom: Managing Attention
Enhancing PowerPoint in the Classroom: Managing Attention Enhancing PowerPoint in the Classroom: Managing Attention
Enhancing PowerPoint in the Classroom: Managing Attention
gregorycanderson
 
Easydeco Business Plan 2000
Easydeco Business Plan 2000Easydeco Business Plan 2000
Easydeco Business Plan 2000
Luis Manuel Halcon Guardiola
 
Responsive Implementation in Drupal
Responsive Implementation in DrupalResponsive Implementation in Drupal
Responsive Implementation in Drupal
Mukesh Agarwal
 
Lobbying For Success Lpga
Lobbying For Success   LpgaLobbying For Success   Lpga
Lobbying For Success Lpga
Danielpaul
 
Ancient Greece
Ancient GreeceAncient Greece
Ancient Greece
Jonathan_Tyus
 
Charlottes Web Characters
Charlottes Web CharactersCharlottes Web Characters
Charlottes Web CharactersAngie Simmons
 
Pg certificate
Pg certificatePg certificate
Pg certificatedkhari
 
Cybersafety yr0 3
Cybersafety yr0 3Cybersafety yr0 3
Cybersafety yr0 3
Angie Simmons
 
5 Essential Reed Diffusers
5 Essential Reed Diffusers5 Essential Reed Diffusers
5 Essential Reed Diffusers
Steve 5
 
09April2009 Assembly Presentation
09April2009   Assembly Presentation09April2009   Assembly Presentation
09April2009 Assembly Presentationnurarafah
 
Hudson Center of Entrepreneurship and Executive Education
Hudson Center of Entrepreneurship and Executive EducationHudson Center of Entrepreneurship and Executive Education
Hudson Center of Entrepreneurship and Executive Educationgoldjan
 
Jesuitas en Sudamérica
Jesuitas en SudaméricaJesuitas en Sudamérica
Jesuitas en Sudaméricadeliaa
 
strategi belajara mengajar
strategi belajara mengajarstrategi belajara mengajar
strategi belajara mengajar
zulfawardi S.Pd.I., MA
 

Viewers also liked (20)

Towards Secure and Dependable Authentication and Authorization Infrastructures
Towards Secure and Dependable Authentication and Authorization InfrastructuresTowards Secure and Dependable Authentication and Authorization Infrastructures
Towards Secure and Dependable Authentication and Authorization Infrastructures
 
Best Practices for Drupal Integrations
Best Practices for Drupal IntegrationsBest Practices for Drupal Integrations
Best Practices for Drupal Integrations
 
High Availability Application Architectures in Amazon VPC (ARC202) | AWS re:I...
High Availability Application Architectures in Amazon VPC (ARC202) | AWS re:I...High Availability Application Architectures in Amazon VPC (ARC202) | AWS re:I...
High Availability Application Architectures in Amazon VPC (ARC202) | AWS re:I...
 
Social media tools for inteam communication
Social media tools for inteam communicationSocial media tools for inteam communication
Social media tools for inteam communication
 
Highlights Of My Life
Highlights Of My LifeHighlights Of My Life
Highlights Of My Life
 
Как заставить инвестора сказать «да»
Как заставить инвестора сказать «да»Как заставить инвестора сказать «да»
Как заставить инвестора сказать «да»
 
Enhancing PowerPoint in the Classroom: Managing Attention
Enhancing PowerPoint in the Classroom: Managing Attention Enhancing PowerPoint in the Classroom: Managing Attention
Enhancing PowerPoint in the Classroom: Managing Attention
 
Easydeco Business Plan 2000
Easydeco Business Plan 2000Easydeco Business Plan 2000
Easydeco Business Plan 2000
 
Responsive Implementation in Drupal
Responsive Implementation in DrupalResponsive Implementation in Drupal
Responsive Implementation in Drupal
 
Lobbying For Success Lpga
Lobbying For Success   LpgaLobbying For Success   Lpga
Lobbying For Success Lpga
 
Ancient Greece
Ancient GreeceAncient Greece
Ancient Greece
 
Charlottes Web Characters
Charlottes Web CharactersCharlottes Web Characters
Charlottes Web Characters
 
Pg certificate
Pg certificatePg certificate
Pg certificate
 
Cybersafety yr0 3
Cybersafety yr0 3Cybersafety yr0 3
Cybersafety yr0 3
 
Bilderberg Presentatie
Bilderberg PresentatieBilderberg Presentatie
Bilderberg Presentatie
 
5 Essential Reed Diffusers
5 Essential Reed Diffusers5 Essential Reed Diffusers
5 Essential Reed Diffusers
 
09April2009 Assembly Presentation
09April2009   Assembly Presentation09April2009   Assembly Presentation
09April2009 Assembly Presentation
 
Hudson Center of Entrepreneurship and Executive Education
Hudson Center of Entrepreneurship and Executive EducationHudson Center of Entrepreneurship and Executive Education
Hudson Center of Entrepreneurship and Executive Education
 
Jesuitas en Sudamérica
Jesuitas en SudaméricaJesuitas en Sudamérica
Jesuitas en Sudamérica
 
strategi belajara mengajar
strategi belajara mengajarstrategi belajara mengajar
strategi belajara mengajar
 

Similar to Drupal Best Practices

Becoming A Drupal Master Builder
Becoming A Drupal Master BuilderBecoming A Drupal Master Builder
Becoming A Drupal Master Builder
Philip Norton
 
Drupal 8 improvements for developer productivity php symfony and more
Drupal 8 improvements for developer productivity  php symfony and moreDrupal 8 improvements for developer productivity  php symfony and more
Drupal 8 improvements for developer productivity php symfony and more
Acquia
 
Efficient development workflows with composer
Efficient development workflows with composerEfficient development workflows with composer
Efficient development workflows with composer
nuppla
 
Help! I inherited a Drupal Site! - DrupalCamp Atlanta 2016
Help! I inherited a Drupal Site! - DrupalCamp Atlanta 2016Help! I inherited a Drupal Site! - DrupalCamp Atlanta 2016
Help! I inherited a Drupal Site! - DrupalCamp Atlanta 2016
Paul McKibben
 
Efficient development workflows with composer
Efficient development workflows with composerEfficient development workflows with composer
Efficient development workflows with composer
nuppla
 
Configuration as Dependency: Managing Drupal 8 Configuration with git and Com...
Configuration as Dependency: Managing Drupal 8 Configuration with git and Com...Configuration as Dependency: Managing Drupal 8 Configuration with git and Com...
Configuration as Dependency: Managing Drupal 8 Configuration with git and Com...
Erich Beyrent
 
My "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails ProjectsMy "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails Projects
GR8Conf
 
Development Setup of B-Translator
Development Setup of B-TranslatorDevelopment Setup of B-Translator
Development Setup of B-Translator
Dashamir Hoxha
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
Shabir Ahmad
 
Introduction to Drupal - Installation, Anatomy, Terminologies
Introduction to Drupal - Installation, Anatomy, TerminologiesIntroduction to Drupal - Installation, Anatomy, Terminologies
Introduction to Drupal - Installation, Anatomy, Terminologies
Gerald Villorente
 
Drush. Why should it be used?
Drush. Why should it be used?Drush. Why should it be used?
Drush. Why should it be used?Sergei Stryukov
 
Configuration Kits - DrupalCamp NYC 2021
Configuration Kits - DrupalCamp NYC 2021Configuration Kits - DrupalCamp NYC 2021
Configuration Kits - DrupalCamp NYC 2021
Martin Anderson-Clutz
 
Modernize Your Drupal Development
Modernize Your Drupal DevelopmentModernize Your Drupal Development
Modernize Your Drupal DevelopmentChris Tankersley
 
LISA15: systemd, the Next-Generation Linux System Manager
LISA15: systemd, the Next-Generation Linux System Manager LISA15: systemd, the Next-Generation Linux System Manager
LISA15: systemd, the Next-Generation Linux System Manager
Alison Chaiken
 
Lean Drupal Repositories with Composer and Drush
Lean Drupal Repositories with Composer and DrushLean Drupal Repositories with Composer and Drush
Lean Drupal Repositories with Composer and Drush
Pantheon
 
DDAY2014 - Features per Drupal 8
DDAY2014 - Features per Drupal 8DDAY2014 - Features per Drupal 8
DDAY2014 - Features per Drupal 8
DrupalDay
 
Docman - The swiss army knife for Drupal multisite docroot management and dep...
Docman - The swiss army knife for Drupal multisite docroot management and dep...Docman - The swiss army knife for Drupal multisite docroot management and dep...
Docman - The swiss army knife for Drupal multisite docroot management and dep...
Aleksey Tkachenko
 
Decoupling Drupal mit dem Lupus Nuxt.js Drupal Stack
Decoupling Drupal mit dem Lupus Nuxt.js Drupal StackDecoupling Drupal mit dem Lupus Nuxt.js Drupal Stack
Decoupling Drupal mit dem Lupus Nuxt.js Drupal Stack
nuppla
 
Exploring composer in drupal 8 with drupal project - salva molina
Exploring composer in drupal 8 with drupal project - salva molinaExploring composer in drupal 8 with drupal project - salva molina
Exploring composer in drupal 8 with drupal project - salva molina
Salvador Molina (Slv_)
 
Extending CMS Made Simple
Extending CMS Made SimpleExtending CMS Made Simple
Extending CMS Made Simple
cmsmssjg
 

Similar to Drupal Best Practices (20)

Becoming A Drupal Master Builder
Becoming A Drupal Master BuilderBecoming A Drupal Master Builder
Becoming A Drupal Master Builder
 
Drupal 8 improvements for developer productivity php symfony and more
Drupal 8 improvements for developer productivity  php symfony and moreDrupal 8 improvements for developer productivity  php symfony and more
Drupal 8 improvements for developer productivity php symfony and more
 
Efficient development workflows with composer
Efficient development workflows with composerEfficient development workflows with composer
Efficient development workflows with composer
 
Help! I inherited a Drupal Site! - DrupalCamp Atlanta 2016
Help! I inherited a Drupal Site! - DrupalCamp Atlanta 2016Help! I inherited a Drupal Site! - DrupalCamp Atlanta 2016
Help! I inherited a Drupal Site! - DrupalCamp Atlanta 2016
 
Efficient development workflows with composer
Efficient development workflows with composerEfficient development workflows with composer
Efficient development workflows with composer
 
Configuration as Dependency: Managing Drupal 8 Configuration with git and Com...
Configuration as Dependency: Managing Drupal 8 Configuration with git and Com...Configuration as Dependency: Managing Drupal 8 Configuration with git and Com...
Configuration as Dependency: Managing Drupal 8 Configuration with git and Com...
 
My "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails ProjectsMy "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails Projects
 
Development Setup of B-Translator
Development Setup of B-TranslatorDevelopment Setup of B-Translator
Development Setup of B-Translator
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
 
Introduction to Drupal - Installation, Anatomy, Terminologies
Introduction to Drupal - Installation, Anatomy, TerminologiesIntroduction to Drupal - Installation, Anatomy, Terminologies
Introduction to Drupal - Installation, Anatomy, Terminologies
 
Drush. Why should it be used?
Drush. Why should it be used?Drush. Why should it be used?
Drush. Why should it be used?
 
Configuration Kits - DrupalCamp NYC 2021
Configuration Kits - DrupalCamp NYC 2021Configuration Kits - DrupalCamp NYC 2021
Configuration Kits - DrupalCamp NYC 2021
 
Modernize Your Drupal Development
Modernize Your Drupal DevelopmentModernize Your Drupal Development
Modernize Your Drupal Development
 
LISA15: systemd, the Next-Generation Linux System Manager
LISA15: systemd, the Next-Generation Linux System Manager LISA15: systemd, the Next-Generation Linux System Manager
LISA15: systemd, the Next-Generation Linux System Manager
 
Lean Drupal Repositories with Composer and Drush
Lean Drupal Repositories with Composer and DrushLean Drupal Repositories with Composer and Drush
Lean Drupal Repositories with Composer and Drush
 
DDAY2014 - Features per Drupal 8
DDAY2014 - Features per Drupal 8DDAY2014 - Features per Drupal 8
DDAY2014 - Features per Drupal 8
 
Docman - The swiss army knife for Drupal multisite docroot management and dep...
Docman - The swiss army knife for Drupal multisite docroot management and dep...Docman - The swiss army knife for Drupal multisite docroot management and dep...
Docman - The swiss army knife for Drupal multisite docroot management and dep...
 
Decoupling Drupal mit dem Lupus Nuxt.js Drupal Stack
Decoupling Drupal mit dem Lupus Nuxt.js Drupal StackDecoupling Drupal mit dem Lupus Nuxt.js Drupal Stack
Decoupling Drupal mit dem Lupus Nuxt.js Drupal Stack
 
Exploring composer in drupal 8 with drupal project - salva molina
Exploring composer in drupal 8 with drupal project - salva molinaExploring composer in drupal 8 with drupal project - salva molina
Exploring composer in drupal 8 with drupal project - salva molina
 
Extending CMS Made Simple
Extending CMS Made SimpleExtending CMS Made Simple
Extending CMS Made Simple
 

Recently uploaded

Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 

Recently uploaded (20)

Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 

Drupal Best Practices

  • 1. Best Practices for development & deployment More structured, more productive, more done! Somedutta Ghosh
  • 2. Best practices in - ★ Drupal - security, structuring, custom coding, etc. ★ Git - Version control tool ★ Deployment method ★ Drush
  • 3. Drupal Best Practices ● NEVER. HACK. CORE.
  • 4. Drupal Best Practices ● No development on live. ● Disable development modules on production/live environment. ○ views_ui ○ field_ui ○ devel ● All drupal level logging should be on only on non-production environments; only server level logging on live. ○ dblog off - syslog on
  • 5. Drupal Best Practices ● Preferable to use server level logging instead of drupal logging, as this will remove unnecessary database writing for the application. ● Choosing Syslog over Drupal watchdog ● Enable logging of slow queries in mysql.
  • 6. Drupal Best Practices ● Files and directory ownership and permissions, ○ group should include web server, and ○ only owner and group should be given permissions.
  • 7. Drupal Best Practices ● JS, CSS should not be present in database (css inside the element can be present as we could have with wysiwyg text editor) ○ no jss/css in node content ○ no jss/css in block content <script type="text/javascript" > jQuery(window).load(function() { jQuery('.pics').cycle({ fx: 'scrollLeft', next: '#right', delay: 2000 , }); }); </script> <style> .pics { width: 100%; margin: 10px; } </style>
  • 8. Writing Custom Code ● Add helpful documentations for all modules. Always add a README.txt file in all custom modules. ● Add documentation for functions and inline comments for understanding the code.
  • 9. Writing Custom Code ● Before writing custom, look for contrib. ● Make sure you use the extensive drupal API instead of writing custom functions/code. ● Use drupal database API for making db calls. ● Use drupal form API for creating forms. ● Use theme functions like theme_image, theme_links instead of writing raw html. ● To show any text always use the t() function. ● For creating links always use l() function instead of a tags.
  • 10. Writing Custom Code ● Try to avoid writing functionality related code in theme. ● Follow naming conventions for easier management. ● all features can be prepended by ‘feature_’ ● all custom modules and theme can be prepended by the initials of the sitename. eg. for site ‘Alpha’ use ‘a_’ or ‘alpha_’
  • 11. Modules - contrib and custom ● Improve structuring - move modules to separate folders under sites/all/modules/ depending on custom, contrib, features or modified.
  • 12. Modules - contrib and custom ● Often we need to apply patches or modify contrib modules. In such a case, ○ create another folder under modules - patches ○ store all applied patch inside this ○ keep a README.txt file in /patch folder to record patches applied, the module they were applied on and their purpose ○ when modifying modules, create a patch from them and treat those patches same as other patches
  • 13. Make your modules Modular! ● Separate functionalities should go into separate modules. ● Use small functions, where each function performs a specific part of a big functionality. Try making these functions as general as possible and use arguments instead of hardcoding, such that they can be used multiple times and with different data. ● For long and heavy operations, use batch process.
  • 14. Custom modules ● Use the theme layer for printing HTML. Use tpl files for large amounts of HTML code. Small html code could go into non-tpm files like .module files. ● CSS/JS for specific pages should not be added on every page ○ if adding css/js to every page through hook init move them to theme’s info file ○ add these files through page callbacks
  • 15. Theme ● PHP should be present in tpl files for either conditions or printing variables; all calculations should be done in template. php file. ● CSS/JS should not be present in template.php; add them through files and included via theme’s info file.
  • 16. Git Best Practices Essential to use version control. The greatest plus points of git are - ● branching - multiple functionalities can be kept separate ● distributed - multiple developers can work on the same codebase at the same time, and git smoothly merges the code ● different versions of the same file - with extensive options of viewing log of changes, one can see when a file or a line of code was added
  • 17. Git Best Practices ● Keep individual functionalities in individual branches ● When on a feature branch, merge with the base branch often ● Branch out from development branch for new functionality. ● Branch out from master(production) branch for production bug fixes.
  • 18. Git Best Practices ● Have intuitive branch names - eg. each feature/functionality branch prepended with feat_ or each bugfix branch prepended with bugfix_ ● production, stage, dev - different instances in the development tree - deploy a different branch on each instance - master, stage, dev respectively.
  • 19. Git Best Practices ● Commit early. Commit often. ● Commit messages should be useful, insightful and descriptive ● Make a habit of git commit instead of git commit -m “[message]”. This opens an editor where you can write a more descriptive commit message ● Set up a .gitignore file - to exclude configuration files that are server environment dependent and large binary files ● Do not add settings.php and files folder in git repository ● After completing a feature from local to production, delete the
  • 20. Deployment Best Practices ● 3 environments should be used - production, staging and development. ● dev - any new code is first deployed and tested here. work from all developers will be tested here ● stage/test - the content will be same as the live instance and updated code from dev will be tested here ● production/live - it is the live instance. New code/functionality after passing tests on the stage environment, can be moved to live.
  • 21. Deployment Best Practices ● All changes should always go through dev and staging before production so that the changes can be extensively tested. ● Version control tool should be used since it makes moving code between environments very easy and especially useful when multiple people are working on the same code. ● Use features and strongarm to move database changes between environments - reduces configuration times on different environments.
  • 22. Drush - do less, get more ● drush cc all - clear all cache ● drush dl [project_name] - download modules ● drush en -y [project_name] - enable modules ● drush dis -y [project_name] - disable modules ● drush pm-uninstall -y [project_name] - uninstalll modules ● drush pm-list - show list of modules with their status, enabled, disabled, not installed
  • 23. Drush - do less, get more ● drush fl - to list all features and show their state, overridden or not ● drush fd [feature_name] - show overrides in feature; you will need module diff for using this command ● drush fu -y [feature_name] - updates the feature(db to code) ● drush fr -y [feature_name] - reverts the feature(code to db) ● creating feature using drush ○ drush fe [feature-name] [feature-component(s)] - export/create or update a feature with one or more components ○ drush fc - show a list of feature components that can be exported into features
  • 24. Drush - do less, get more ● drush updb - running update.php from drush ● drush cron - run cron from drush ● drush ws - show list of latest 10(default count, can be increased with option in command) messages messages ● drush upwd - Reset the password for an user account that has the given username(username to be specified in command) ● drush sqlq “[sql-query]” - run any db query from drush ● drush sql-dump - take a sql dump of the current site’s database
  • 25. Drush - do less, get more Drush alias - ● an alias is basically a short name for a drupal installation. It is a set of options that collectively define that installation. ● its biggest advantage is super easy syncing with remote servers and running drush commands on remote servers locally
  • 26. Drush - do less, get more ● create a drush alias file - sitename.alias.drushrc.php, eg alpha.alias. drushrc.php ● place it in either of - ○ ~/.drush ○ sites/all/drush ● the simplest content of an alias file could be <?php $aliases[local] = array( 'root' => '/var/www/alpha' ); ● now you can access your local environment for drush through - drush @alpha.local status
  • 27. Drush - do less, get more ● for adding a remote configuration, eg. dev on a remote server, add following to above alias file $aliases[dev] = array( 'root' => '/home/alpha/public_html', 'remote-host' => 'alpha.dev.com', 'remote-user' => alpha', ); ● if ssh requires password authentication, add this to alias config of the remote - 'ssh-options' => '-o PasswordAuthentication=yes' - this will prompt for password every time you use drush with the remote’s alias
  • 28. Drush - do less, get more ● we now have 2 aliases for the site alpha * drush @alpha.local * drush @alpha.dev ● syncing local database with remote with single command ○ drush sql-sync [source] [destination] ○ drush sql-sync @alpha.dev@alpha.local ● syncing local files folder with remote with single command and drush alias ○ drush rsync [source]:sites/default/files/ [destination]: sites/default/files/ ○ drush rsync @alpha.dev:sites/default/files/ @alpha.local: sites/default/files/
  • 29. Drush - do less, get more ● drush help - list of drush commands and their use; drush help [command] gives more help information about a specific command