SlideShare una empresa de Scribd logo
1 de 29
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

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 communityAngela Byron
 
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 MinutesAcquia
 
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 FeaturesNuvole
 
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 developmentsparkfabrik
 
Using Grunt with Drupal
Using Grunt with DrupalUsing Grunt with Drupal
Using Grunt with Drupalarithmetric
 
Drupal Migrations in 2018
Drupal Migrations in 2018Drupal Migrations in 2018
Drupal Migrations in 2018Pantheon
 
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 8Websolutions 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 teamLuc 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 WebsiteMediacurrent
 
Composer Tools & Frameworks for Drupal
Composer Tools & Frameworks for DrupalComposer Tools & Frameworks for Drupal
Composer Tools & Frameworks for DrupalPantheon
 
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 7Phase2
 
Introduction to Composer for Drupal
Introduction to Composer for DrupalIntroduction to Composer for Drupal
Introduction to Composer for DrupalLuc Bézier
 
The OpenEuropa Initiative
The OpenEuropa InitiativeThe OpenEuropa Initiative
The OpenEuropa InitiativeNuvole
 
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
 

La actualidad más candente (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
 

Destacado

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 InfrastructuresDiego 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 communicationNata 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
 
Responsive Implementation in Drupal
Responsive Implementation in DrupalResponsive Implementation in Drupal
Responsive Implementation in DrupalMukesh Agarwal
 
Lobbying For Success Lpga
Lobbying For Success   LpgaLobbying For Success   Lpga
Lobbying For Success LpgaDanielpaul
 
Charlottes Web Characters
Charlottes Web CharactersCharlottes Web Characters
Charlottes Web CharactersAngie Simmons
 
Pg certificate
Pg certificatePg certificate
Pg certificatedkhari
 
5 Essential Reed Diffusers
5 Essential Reed Diffusers5 Essential Reed Diffusers
5 Essential Reed DiffusersSteve 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
 

Destacado (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 a Drupal Best Practices

Becoming A Drupal Master Builder
Becoming A Drupal Master BuilderBecoming A Drupal Master Builder
Becoming A Drupal Master BuilderPhilip 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 moreAcquia
 
Efficient development workflows with composer
Efficient development workflows with composerEfficient development workflows with composer
Efficient development workflows with composernuppla
 
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 2016Paul McKibben
 
Efficient development workflows with composer
Efficient development workflows with composerEfficient development workflows with composer
Efficient development workflows with composernuppla
 
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 ProjectsGR8Conf
 
Development Setup of B-Translator
Development Setup of B-TranslatorDevelopment Setup of B-Translator
Development Setup of B-TranslatorDashamir Hoxha
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesShabir Ahmad
 
Introduction to Drupal - Installation, Anatomy, Terminologies
Introduction to Drupal - Installation, Anatomy, TerminologiesIntroduction to Drupal - Installation, Anatomy, Terminologies
Introduction to Drupal - Installation, Anatomy, TerminologiesGerald 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 2021Martin 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 DrushPantheon
 
DDAY2014 - Features per Drupal 8
DDAY2014 - Features per Drupal 8DDAY2014 - Features per Drupal 8
DDAY2014 - Features per Drupal 8DrupalDay
 
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 Stacknuppla
 
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 molinaSalvador Molina (Slv_)
 
Extending CMS Made Simple
Extending CMS Made SimpleExtending CMS Made Simple
Extending CMS Made Simplecmsmssjg
 

Similar a 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
 

Último

COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaborationbruanjhuli
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioChristian Posta
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDELiveplex
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Brian Pichman
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-pyJamie (Taka) Wang
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarPrecisely
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.YounusS2
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfAijun Zhang
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?IES VE
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxUdaiappa Ramachandran
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7DianaGray10
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsSafe Software
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024D Cloud Solutions
 

Último (20)

COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and Istio
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-py
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity Webinar
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdf
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?
 
20230104 - machine vision
20230104 - machine vision20230104 - machine vision
20230104 - machine vision
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptx
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024
 

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