SlideShare uma empresa Scribd logo
1 de 35
Ohad Raz
WordPress Consultant
WordCamp Jerusalem 2013
WordPress Development Environments


 Ohad Raz
 WordPress Consultant
 WordCamp Jerusalem 2013
Who Am I?
•   Father and husband.
•   Ohad Raz (aka Bainternet).
•   WordPress Consultant Developer and Designer
•   Plugin developer 18 published plugins with over 132,000 downloads.
•   Core Contributor as of 3.5
•   Moderator and Editor @ WordPress Answers




                 And I also fight crime at night
What's this about?
• Development Environments.
• Development Environments Workflow.
• Tips and Tricks:
   • Server.
   • Domain.
   • Files.
   • Database.
• Some Version Control.
Environments
Local / Development     Staging / Testing   Live / Production
Development Environment
 Development usually refers to your
 local machine where you have your
 web server, database, IDE, and
 related tools installed.



Its where you actually develop your project.
Staging Environment
The Staging Environment is a server the
resembles where the project is actually
going to live and where you upload your
work for testing.


Its mostly used for testing and showing
off your work.
Live Environment
The live environment is where the
project is live on the web with real
content and where users actually
interact with your work



 It’s the actual site.
But why?
                         All Environments:
                         • Mistakes and accidents happen.
                         • You want to be taken seriously



Development:
                                                 Staging:
• Work Faster.
                                                 • Client approval.
• Freedom to experiment.
                                                 • Test on an environment
• Test multiple versions of PHP.
                                                    similar to production.
• Teams can work
  together (with version
  control).


                  Live: Because Every Site need a Home.
Development Environment
           Server
 WAMP       MAMP       XAMPP




 Windows    Mac      X any platform
 Apache     Apache   Apache
 MySQL      MySQL    MySQL
 PHP        PHP      PHP
                     Perl
Development Environment
                          Server
Install WordPress Locally :
1.   Download WordPress.
2.   Extract the downloaded zip file.
3.   Create a database.
4.   Configure wp-config.php
5.   Run WordPress Setup

               Or do it all at once with WordPress Auto Installer


                  This script will download the latest copy of WordPress,
                  extract the files to the directory you named, create
                  a new database and take you straight to where all you
                  have to do is set you sites name, your username and pass
                  and you
                  have a new WordPress Installation ready to roll.
Domain Issue
Live: domain.com
Dev: domain.dev

This way you can use a simple Search and Replace on files
and database dump.


Or use real domain name Using the hosts file.
Live & Dev: domain.com

                    # Point domain.com to your computer
                    127.0.0.1 domain.com


             Windows: C:WINDOWSsystem32driversetchosts

             Mac/Linux: /etc/hosts
Domain Issue
Create A Virtual Host


 <VirtualHost 127.0.0.1>
            DocumentRoot "C:/wamp/www/WordCamp/local"
            ServerName domain.dev
            <Directory "C:/wamp/www/WordCamp/local">
              Options FollowSymLinks Indexes MultiViews
              AllowOverride All
              Order deny,allow
              Allow from all
              Allow from 127.0.0.1
            </Directory>
 </VirtualHost>

                [wamp] c:wampbinapacheApacheVERSIONconfhttpd.conf


                [mamp] /private/etc/apache2/httpd.conf


                [xampp] ..apacheconfextrahttpd-vhosts.conf
Files Sync

FTP sync          Only copy changed files based on size or date
                  FileZilla - http://filezilla-project.org/
Command line      Rsync - http://rsync.samba.org/
                  Wget - http://www.gnu.org/software/wget/
                  Capistrano* - http://capistranorb.com/
Version control   Git - http://git-scm.com/
                  SVN - http://subversion.apache.org/
                  HG - http://mercurial.selenic.com/
Files Sync
                          wp-config.php
One level above the WordPress Root Directory in all environments
and ignored in version control.

Or a separate file per each environment:
//dev-config.php
/* Development Environment */
define('WP_ENV', 'local');
define('WP_DEBUG', true);
define('DB_NAME', 'local_db_name');
define('DB_USER', 'local_db_user');
define('DB_PASSWORD', 'local_db_password');
define('DB_HOST', 'local_db_host');

//stage-config.php
/* Staging Environment */
define('WP_ENV', 'stage');
define('WP_DEBUG', true);
define('DB_NAME', 'stage _db_name');
define('DB_USER', 'stage _db_user');
define('DB_PASSWORD', 'stage _db_password');
define('DB_HOST', 'stage _db_host');
Files Sync
                                   wp-config.php

//First we check for development env
if ( file_exists( dirname( __FILE__ ) . '/dev-config.php' ) ) {
              include( dirname( __FILE__ ) . '/dev-config.php' );

} elseif ( file_exists( dirname( __FILE__ ) . '/stage-config.php' ) ) {
              //then we check for staging env
              include( dirname( __FILE__ ) . '/stage-config.php' );
}else {
              //if we got here then we are at production env.
              define('WP_ENV', 'production');
              define('WP_DEBUG', false);
              define( 'DB_NAME', 'production_db' );
              define( 'DB_USER', 'production_user' );
              define( 'DB_PASSWORD', 'production_password' );
              define( 'DB_HOST', 'production_db_host' ); }
}
…
Database Sync
Native Export Import

It's best to import into Dev then move the database over to
production because when you import it will download all the
new media files from production.
Database Sync
Database Management tools:

Export & import the database using PHPMyAdmin or alternative.

Use ”add drop tables” This will delete the old tables when you import.

Use the ”INSERT IGNORE INTO” MySQL command to add the new tables from dev.
or the ”REPLACE” command to overwrite duplicate rows in the same table.
Database Sync
Use A plugin:

WP Migrate DB

Which takes care of
serialized data

Ex:
 s:9:“domin.dev"
Becomes:
s:11:“domain.info"
Database Sync
Use Command line via SSH:
 # Export a database to DBdump.sql
 mysqldump --add-drop-table -u USERNAME –p DATABASE_NAME> DBdump.sql


 # Import a database into MySQL
 mysql DATABASE_NAME -u USERNAME -p < DBdump.sql


Remote to local and visa-versa:
# Export remote database directly to local database
ssh user@site.com "mysqldump --add-drop-table -u USERNAME -pPassword DATABASE_NAME" | mysql DATABASE_NAME



 # Export local database directly to remote database
 mysqldump --add-drop-table DATABASE_NAME | ssh user@site.com "mysql -u USERNAME -pPassword DATABASE_NAME "
All Around Solutions
Server / Stack:

Bitnami - simple stack with WordPress bundled in.
Instant WordPress - The easiest and quickest way to install WordPress!
DesktopServer - Another easy way with virtual servers and deploy capability.


Plugins:

BackupBuddy - Back up, restore and move WordPress.
Duplicator – “ability to migrate a site from one location to another location in 3
steps.”
Version Control
Version Control - track your files over time.

But Why?
• Easily un-break your code.
     Feel free to experiment.
     No more of this:
           Logo.png
           Logo_final.png
           Logo_last.png
           Logo_last2.png

• Never. Lose. Anything.
    If You Ever
          Lost a file
          Written over a file
          Made a change that broke your code
Version Control
Some More reasons
• One canonical version.
    There is a clear place to go for the primary copy of the code.

• Collaboration
    Track changes For teams
         See what others have done
         Ability to reject / avoid bad changes
    Simultaneous editing
    Merge

• Deployment!!!
Version Control

Methods:
• Version Control the entire WordPress environment
• Version Control only the WP-Content Directory
• Version Control only a specific Theme or Plugin
Version Control
Simple git commands:
• git init - initializes a git repository
     git init - initializes a git repository in current folder
     git init foldername - initializes a git repository in foldername
• git add – tell git to keep track.
     git add . - add everything.
     git add somefile.php – add somefile.php
• git commit - stage files / stores a version of the current code
     git commit -m "commit message“
• git status - allows you to see the current state of your code.
• git pull – pull updates
• git push – push updates
Version Control
On Local Host:
•     Download and Install WordPress.
•     Create a new repository.
•     Tell git to ignore wp-config.php
•     Add and commit changes.


    git init .
    touch .gitignore | echo wp-config.php >>.gitignore
    git add .
    git commit –m”initial WordPress Commit”
Version Control
Repository Hosts
GITHUB - web-based hosting service for software development projects
          that use the Git revision control system.
BitBucket - web-based hosting service for projects that use either
          the Mercurial or Git revision control systems
Version Control
Create a new BitBucket Repository
Version Control
Create a new BitBucket Repository
Version Control
  On Local Host:
  •   Add Bitbucket as remote repository
  •   Push to Bitbucket.




git remote add origin https://bitbucket.org/bainternet/some-wordpress-project.git
git push
Version Control
  On Stage/Production:
  •   Clone Bitbucket Repository.
  •   Run WordPress install once.




git clone https://bitbucket.org/bainternet/some-wordpress-project.git
Version Control
  Workflow:
   On local                           On Server
git pull                             git pull
git checkout -b dev
//make some changes
git commit -m "made dev changes"
git checkout master
git merge dev
git commit -m “merged dev changes"
git push
Version Control
On local                               On Server
git pull
git checkout -b feature-x             git pull
//make some changes
git commit -m “started feature-x "
git checkout master
git checkout -b bug-y
//fix bug y
git commit -m “Fixed bug y"
git checkout master
git merge bug-y
git commit -m “merged bug y fix"
git push
git checkout feature-x
//finish working on feature x
git commit -m “finished feature-x "
git checkout master
git merge dev
git commit -m “merged dev changes"
git push
Questions???
Thank You!

Mais conteúdo relacionado

Mais procurados

Drupal VM for Drupal 8 Dev - MidCamp 2017
Drupal VM for Drupal 8 Dev - MidCamp 2017Drupal VM for Drupal 8 Dev - MidCamp 2017
Drupal VM for Drupal 8 Dev - MidCamp 2017Jeff Geerling
 
Tips for a Faster Website
Tips for a Faster WebsiteTips for a Faster Website
Tips for a Faster WebsiteRayed Alrashed
 
Vagrant + Docker provider [+Puppet]
Vagrant + Docker provider [+Puppet]Vagrant + Docker provider [+Puppet]
Vagrant + Docker provider [+Puppet]Nicolas Poggi
 
Ansible + WordPress
Ansible + WordPressAnsible + WordPress
Ansible + WordPressAlan Lok
 
WordCamp LA 2011 - WordPress Server Migration
WordCamp LA 2011 - WordPress Server MigrationWordCamp LA 2011 - WordPress Server Migration
WordCamp LA 2011 - WordPress Server MigrationBrad Markle
 
Drupal VM for Drupal 8 Dev - Drupal Camp STL 2017
Drupal VM for Drupal 8 Dev - Drupal Camp STL 2017Drupal VM for Drupal 8 Dev - Drupal Camp STL 2017
Drupal VM for Drupal 8 Dev - Drupal Camp STL 2017Jeff Geerling
 
CIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
CIRCUIT 2015 - AEM Infrastructure Automation with Chef CookbooksCIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
CIRCUIT 2015 - AEM Infrastructure Automation with Chef CookbooksICF CIRCUIT
 
A Better WordPress Workflow with WP-CLI
A Better WordPress Workflow with WP-CLIA Better WordPress Workflow with WP-CLI
A Better WordPress Workflow with WP-CLIRikesh Ramlochund
 
Go Faster with Ansible (PHP meetup)
Go Faster with Ansible (PHP meetup)Go Faster with Ansible (PHP meetup)
Go Faster with Ansible (PHP meetup)Richard Donkin
 
Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)Japheth Thomson
 
Learn you some Ansible for great good!
Learn you some Ansible for great good!Learn you some Ansible for great good!
Learn you some Ansible for great good!David Lapsley
 
How To Set a Vagrant Development System
How To Set a Vagrant Development SystemHow To Set a Vagrant Development System
How To Set a Vagrant Development SystemPaul Bearne
 
DevOps for Humans - Ansible for Drupal Deployment Victory!
DevOps for Humans - Ansible for Drupal Deployment Victory!DevOps for Humans - Ansible for Drupal Deployment Victory!
DevOps for Humans - Ansible for Drupal Deployment Victory!Jeff Geerling
 
Adobe AEM Maintenance - Customer Care Office Hours
Adobe AEM Maintenance - Customer Care Office HoursAdobe AEM Maintenance - Customer Care Office Hours
Adobe AEM Maintenance - Customer Care Office HoursAndrew Khoury
 
Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015
Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015
Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015Stephane Manciot
 
Professional deployment
Professional deploymentProfessional deployment
Professional deploymentIvelina Dimova
 
Chef Provisioning a Chef Server Cluster - ChefConf 2015
Chef Provisioning a Chef Server Cluster - ChefConf 2015Chef Provisioning a Chef Server Cluster - ChefConf 2015
Chef Provisioning a Chef Server Cluster - ChefConf 2015Chef
 

Mais procurados (20)

Vagrant
VagrantVagrant
Vagrant
 
Drupal VM for Drupal 8 Dev - MidCamp 2017
Drupal VM for Drupal 8 Dev - MidCamp 2017Drupal VM for Drupal 8 Dev - MidCamp 2017
Drupal VM for Drupal 8 Dev - MidCamp 2017
 
Tips for a Faster Website
Tips for a Faster WebsiteTips for a Faster Website
Tips for a Faster Website
 
Vagrant + Docker provider [+Puppet]
Vagrant + Docker provider [+Puppet]Vagrant + Docker provider [+Puppet]
Vagrant + Docker provider [+Puppet]
 
Ansible + WordPress
Ansible + WordPressAnsible + WordPress
Ansible + WordPress
 
WordCamp LA 2011 - WordPress Server Migration
WordCamp LA 2011 - WordPress Server MigrationWordCamp LA 2011 - WordPress Server Migration
WordCamp LA 2011 - WordPress Server Migration
 
60 Admin Tips
60 Admin Tips60 Admin Tips
60 Admin Tips
 
Drupal VM for Drupal 8 Dev - Drupal Camp STL 2017
Drupal VM for Drupal 8 Dev - Drupal Camp STL 2017Drupal VM for Drupal 8 Dev - Drupal Camp STL 2017
Drupal VM for Drupal 8 Dev - Drupal Camp STL 2017
 
CIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
CIRCUIT 2015 - AEM Infrastructure Automation with Chef CookbooksCIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
CIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
 
A Better WordPress Workflow with WP-CLI
A Better WordPress Workflow with WP-CLIA Better WordPress Workflow with WP-CLI
A Better WordPress Workflow with WP-CLI
 
Go Faster with Ansible (PHP meetup)
Go Faster with Ansible (PHP meetup)Go Faster with Ansible (PHP meetup)
Go Faster with Ansible (PHP meetup)
 
Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
 
Learn you some Ansible for great good!
Learn you some Ansible for great good!Learn you some Ansible for great good!
Learn you some Ansible for great good!
 
How To Set a Vagrant Development System
How To Set a Vagrant Development SystemHow To Set a Vagrant Development System
How To Set a Vagrant Development System
 
DevOps for Humans - Ansible for Drupal Deployment Victory!
DevOps for Humans - Ansible for Drupal Deployment Victory!DevOps for Humans - Ansible for Drupal Deployment Victory!
DevOps for Humans - Ansible for Drupal Deployment Victory!
 
TIAD : Automating the modern datacenter
TIAD : Automating the modern datacenterTIAD : Automating the modern datacenter
TIAD : Automating the modern datacenter
 
Adobe AEM Maintenance - Customer Care Office Hours
Adobe AEM Maintenance - Customer Care Office HoursAdobe AEM Maintenance - Customer Care Office Hours
Adobe AEM Maintenance - Customer Care Office Hours
 
Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015
Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015
Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015
 
Professional deployment
Professional deploymentProfessional deployment
Professional deployment
 
Chef Provisioning a Chef Server Cluster - ChefConf 2015
Chef Provisioning a Chef Server Cluster - ChefConf 2015Chef Provisioning a Chef Server Cluster - ChefConf 2015
Chef Provisioning a Chef Server Cluster - ChefConf 2015
 

Semelhante a WordPress Development Environments

The Modern Developer Toolbox
The Modern Developer ToolboxThe Modern Developer Toolbox
The Modern Developer ToolboxPablo Godel
 
Setting up a local WordPress development environment
Setting up a local WordPress development environmentSetting up a local WordPress development environment
Setting up a local WordPress development environmentZero Point Development
 
Stress Free Deployment - Confoo 2011
Stress Free Deployment  - Confoo 2011Stress Free Deployment  - Confoo 2011
Stress Free Deployment - Confoo 2011Bachkoutou Toutou
 
Rock Solid Deployment of Web Applications
Rock Solid Deployment of Web ApplicationsRock Solid Deployment of Web Applications
Rock Solid Deployment of Web ApplicationsPablo Godel
 
Drupal on your laptop
Drupal on your laptopDrupal on your laptop
Drupal on your laptopSam Moore
 
Using MAMP for Web Development
Using MAMP for Web DevelopmentUsing MAMP for Web Development
Using MAMP for Web DevelopmentEric Greene
 
Varying wordpressdevelopmentenvironment wp-campus2016
Varying wordpressdevelopmentenvironment wp-campus2016Varying wordpressdevelopmentenvironment wp-campus2016
Varying wordpressdevelopmentenvironment wp-campus2016David Brattoli
 
DevOPS training - Day 2/2
DevOPS training - Day 2/2DevOPS training - Day 2/2
DevOPS training - Day 2/2Vincent Mercier
 
Varying WordPress Development Environment WordCamp Columbus 2016
Varying WordPress Development Environment WordCamp Columbus 2016Varying WordPress Development Environment WordCamp Columbus 2016
Varying WordPress Development Environment WordCamp Columbus 2016David Brattoli
 
A Docker-based Development Environment Even I Can Understand
A Docker-based Development Environment Even I Can UnderstandA Docker-based Development Environment Even I Can Understand
A Docker-based Development Environment Even I Can UnderstandJeremy Gimbel
 
Desktop server presentation
Desktop server presentationDesktop server presentation
Desktop server presentationKen Kramer
 
Virtualize and automate your development environment for fun and profit
Virtualize and automate your development environment for fun and profitVirtualize and automate your development environment for fun and profit
Virtualize and automate your development environment for fun and profitAndreas Heim
 
WP Sandbox Presentation WordCamp Toronto 2011
WP Sandbox Presentation WordCamp Toronto 2011WP Sandbox Presentation WordCamp Toronto 2011
WP Sandbox Presentation WordCamp Toronto 2011Alfred Ayache
 
A Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy SystemA Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy Systemadrian_nye
 
Varying WordPress Development Environment WordCamp Cincinnati 2016
Varying WordPress Development Environment WordCamp Cincinnati 2016Varying WordPress Development Environment WordCamp Cincinnati 2016
Varying WordPress Development Environment WordCamp Cincinnati 2016David Brattoli
 
Introduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to ChefIntroduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to ChefNathen Harvey
 
Automation with ansible
Automation with ansibleAutomation with ansible
Automation with ansibleKhizer Naeem
 
Laravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello ProductionLaravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello ProductionJoe Ferguson
 
Extracting twitter data using apache flume
Extracting twitter data using apache flumeExtracting twitter data using apache flume
Extracting twitter data using apache flumeBharat Khanna
 

Semelhante a WordPress Development Environments (20)

The Modern Developer Toolbox
The Modern Developer ToolboxThe Modern Developer Toolbox
The Modern Developer Toolbox
 
Setting up a local WordPress development environment
Setting up a local WordPress development environmentSetting up a local WordPress development environment
Setting up a local WordPress development environment
 
Stress Free Deployment - Confoo 2011
Stress Free Deployment  - Confoo 2011Stress Free Deployment  - Confoo 2011
Stress Free Deployment - Confoo 2011
 
Rock Solid Deployment of Web Applications
Rock Solid Deployment of Web ApplicationsRock Solid Deployment of Web Applications
Rock Solid Deployment of Web Applications
 
Drupal on your laptop
Drupal on your laptopDrupal on your laptop
Drupal on your laptop
 
Using MAMP for Web Development
Using MAMP for Web DevelopmentUsing MAMP for Web Development
Using MAMP for Web Development
 
Varying wordpressdevelopmentenvironment wp-campus2016
Varying wordpressdevelopmentenvironment wp-campus2016Varying wordpressdevelopmentenvironment wp-campus2016
Varying wordpressdevelopmentenvironment wp-campus2016
 
DevOPS training - Day 2/2
DevOPS training - Day 2/2DevOPS training - Day 2/2
DevOPS training - Day 2/2
 
Varying WordPress Development Environment WordCamp Columbus 2016
Varying WordPress Development Environment WordCamp Columbus 2016Varying WordPress Development Environment WordCamp Columbus 2016
Varying WordPress Development Environment WordCamp Columbus 2016
 
A Docker-based Development Environment Even I Can Understand
A Docker-based Development Environment Even I Can UnderstandA Docker-based Development Environment Even I Can Understand
A Docker-based Development Environment Even I Can Understand
 
Desktop server presentation
Desktop server presentationDesktop server presentation
Desktop server presentation
 
Virtualize and automate your development environment for fun and profit
Virtualize and automate your development environment for fun and profitVirtualize and automate your development environment for fun and profit
Virtualize and automate your development environment for fun and profit
 
WP Sandbox Presentation WordCamp Toronto 2011
WP Sandbox Presentation WordCamp Toronto 2011WP Sandbox Presentation WordCamp Toronto 2011
WP Sandbox Presentation WordCamp Toronto 2011
 
A Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy SystemA Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy System
 
Varying WordPress Development Environment WordCamp Cincinnati 2016
Varying WordPress Development Environment WordCamp Cincinnati 2016Varying WordPress Development Environment WordCamp Cincinnati 2016
Varying WordPress Development Environment WordCamp Cincinnati 2016
 
Introduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to ChefIntroduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to Chef
 
Automation with ansible
Automation with ansibleAutomation with ansible
Automation with ansible
 
Laravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello ProductionLaravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello Production
 
Exp-3.pptx
Exp-3.pptxExp-3.pptx
Exp-3.pptx
 
Extracting twitter data using apache flume
Extracting twitter data using apache flumeExtracting twitter data using apache flume
Extracting twitter data using apache flume
 

WordPress Development Environments

  • 2. WordPress Development Environments Ohad Raz WordPress Consultant WordCamp Jerusalem 2013
  • 3. Who Am I? • Father and husband. • Ohad Raz (aka Bainternet). • WordPress Consultant Developer and Designer • Plugin developer 18 published plugins with over 132,000 downloads. • Core Contributor as of 3.5 • Moderator and Editor @ WordPress Answers And I also fight crime at night
  • 4. What's this about? • Development Environments. • Development Environments Workflow. • Tips and Tricks: • Server. • Domain. • Files. • Database. • Some Version Control.
  • 5. Environments Local / Development Staging / Testing Live / Production
  • 6. Development Environment Development usually refers to your local machine where you have your web server, database, IDE, and related tools installed. Its where you actually develop your project.
  • 7. Staging Environment The Staging Environment is a server the resembles where the project is actually going to live and where you upload your work for testing. Its mostly used for testing and showing off your work.
  • 8. Live Environment The live environment is where the project is live on the web with real content and where users actually interact with your work It’s the actual site.
  • 9. But why? All Environments: • Mistakes and accidents happen. • You want to be taken seriously Development: Staging: • Work Faster. • Client approval. • Freedom to experiment. • Test on an environment • Test multiple versions of PHP. similar to production. • Teams can work together (with version control). Live: Because Every Site need a Home.
  • 10. Development Environment Server WAMP MAMP XAMPP Windows Mac X any platform Apache Apache Apache MySQL MySQL MySQL PHP PHP PHP Perl
  • 11. Development Environment Server Install WordPress Locally : 1. Download WordPress. 2. Extract the downloaded zip file. 3. Create a database. 4. Configure wp-config.php 5. Run WordPress Setup Or do it all at once with WordPress Auto Installer This script will download the latest copy of WordPress, extract the files to the directory you named, create a new database and take you straight to where all you have to do is set you sites name, your username and pass and you have a new WordPress Installation ready to roll.
  • 12. Domain Issue Live: domain.com Dev: domain.dev This way you can use a simple Search and Replace on files and database dump. Or use real domain name Using the hosts file. Live & Dev: domain.com # Point domain.com to your computer 127.0.0.1 domain.com Windows: C:WINDOWSsystem32driversetchosts Mac/Linux: /etc/hosts
  • 13. Domain Issue Create A Virtual Host <VirtualHost 127.0.0.1> DocumentRoot "C:/wamp/www/WordCamp/local" ServerName domain.dev <Directory "C:/wamp/www/WordCamp/local"> Options FollowSymLinks Indexes MultiViews AllowOverride All Order deny,allow Allow from all Allow from 127.0.0.1 </Directory> </VirtualHost> [wamp] c:wampbinapacheApacheVERSIONconfhttpd.conf [mamp] /private/etc/apache2/httpd.conf [xampp] ..apacheconfextrahttpd-vhosts.conf
  • 14. Files Sync FTP sync Only copy changed files based on size or date FileZilla - http://filezilla-project.org/ Command line Rsync - http://rsync.samba.org/ Wget - http://www.gnu.org/software/wget/ Capistrano* - http://capistranorb.com/ Version control Git - http://git-scm.com/ SVN - http://subversion.apache.org/ HG - http://mercurial.selenic.com/
  • 15. Files Sync wp-config.php One level above the WordPress Root Directory in all environments and ignored in version control. Or a separate file per each environment: //dev-config.php /* Development Environment */ define('WP_ENV', 'local'); define('WP_DEBUG', true); define('DB_NAME', 'local_db_name'); define('DB_USER', 'local_db_user'); define('DB_PASSWORD', 'local_db_password'); define('DB_HOST', 'local_db_host'); //stage-config.php /* Staging Environment */ define('WP_ENV', 'stage'); define('WP_DEBUG', true); define('DB_NAME', 'stage _db_name'); define('DB_USER', 'stage _db_user'); define('DB_PASSWORD', 'stage _db_password'); define('DB_HOST', 'stage _db_host');
  • 16. Files Sync wp-config.php //First we check for development env if ( file_exists( dirname( __FILE__ ) . '/dev-config.php' ) ) { include( dirname( __FILE__ ) . '/dev-config.php' ); } elseif ( file_exists( dirname( __FILE__ ) . '/stage-config.php' ) ) { //then we check for staging env include( dirname( __FILE__ ) . '/stage-config.php' ); }else { //if we got here then we are at production env. define('WP_ENV', 'production'); define('WP_DEBUG', false); define( 'DB_NAME', 'production_db' ); define( 'DB_USER', 'production_user' ); define( 'DB_PASSWORD', 'production_password' ); define( 'DB_HOST', 'production_db_host' ); } } …
  • 17. Database Sync Native Export Import It's best to import into Dev then move the database over to production because when you import it will download all the new media files from production.
  • 18. Database Sync Database Management tools: Export & import the database using PHPMyAdmin or alternative. Use ”add drop tables” This will delete the old tables when you import. Use the ”INSERT IGNORE INTO” MySQL command to add the new tables from dev. or the ”REPLACE” command to overwrite duplicate rows in the same table.
  • 19. Database Sync Use A plugin: WP Migrate DB Which takes care of serialized data Ex: s:9:“domin.dev" Becomes: s:11:“domain.info"
  • 20. Database Sync Use Command line via SSH: # Export a database to DBdump.sql mysqldump --add-drop-table -u USERNAME –p DATABASE_NAME> DBdump.sql # Import a database into MySQL mysql DATABASE_NAME -u USERNAME -p < DBdump.sql Remote to local and visa-versa: # Export remote database directly to local database ssh user@site.com "mysqldump --add-drop-table -u USERNAME -pPassword DATABASE_NAME" | mysql DATABASE_NAME # Export local database directly to remote database mysqldump --add-drop-table DATABASE_NAME | ssh user@site.com "mysql -u USERNAME -pPassword DATABASE_NAME "
  • 21. All Around Solutions Server / Stack: Bitnami - simple stack with WordPress bundled in. Instant WordPress - The easiest and quickest way to install WordPress! DesktopServer - Another easy way with virtual servers and deploy capability. Plugins: BackupBuddy - Back up, restore and move WordPress. Duplicator – “ability to migrate a site from one location to another location in 3 steps.”
  • 22. Version Control Version Control - track your files over time. But Why? • Easily un-break your code.  Feel free to experiment.  No more of this:  Logo.png  Logo_final.png  Logo_last.png  Logo_last2.png • Never. Lose. Anything.  If You Ever  Lost a file  Written over a file  Made a change that broke your code
  • 23. Version Control Some More reasons • One canonical version.  There is a clear place to go for the primary copy of the code. • Collaboration  Track changes For teams  See what others have done  Ability to reject / avoid bad changes  Simultaneous editing  Merge • Deployment!!!
  • 24. Version Control Methods: • Version Control the entire WordPress environment • Version Control only the WP-Content Directory • Version Control only a specific Theme or Plugin
  • 25. Version Control Simple git commands: • git init - initializes a git repository  git init - initializes a git repository in current folder  git init foldername - initializes a git repository in foldername • git add – tell git to keep track.  git add . - add everything.  git add somefile.php – add somefile.php • git commit - stage files / stores a version of the current code  git commit -m "commit message“ • git status - allows you to see the current state of your code. • git pull – pull updates • git push – push updates
  • 26. Version Control On Local Host: • Download and Install WordPress. • Create a new repository. • Tell git to ignore wp-config.php • Add and commit changes. git init . touch .gitignore | echo wp-config.php >>.gitignore git add . git commit –m”initial WordPress Commit”
  • 27. Version Control Repository Hosts GITHUB - web-based hosting service for software development projects that use the Git revision control system. BitBucket - web-based hosting service for projects that use either the Mercurial or Git revision control systems
  • 28. Version Control Create a new BitBucket Repository
  • 29. Version Control Create a new BitBucket Repository
  • 30. Version Control On Local Host: • Add Bitbucket as remote repository • Push to Bitbucket. git remote add origin https://bitbucket.org/bainternet/some-wordpress-project.git git push
  • 31. Version Control On Stage/Production: • Clone Bitbucket Repository. • Run WordPress install once. git clone https://bitbucket.org/bainternet/some-wordpress-project.git
  • 32. Version Control Workflow: On local On Server git pull git pull git checkout -b dev //make some changes git commit -m "made dev changes" git checkout master git merge dev git commit -m “merged dev changes" git push
  • 33. Version Control On local On Server git pull git checkout -b feature-x git pull //make some changes git commit -m “started feature-x " git checkout master git checkout -b bug-y //fix bug y git commit -m “Fixed bug y" git checkout master git merge bug-y git commit -m “merged bug y fix" git push git checkout feature-x //finish working on feature x git commit -m “finished feature-x " git checkout master git merge dev git commit -m “merged dev changes" git push