WordPress Development Environments


Published on

My WordCamp Jerusalem 2013 WordPress Development Environments lecture

  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

WordPress Development Environments

  1. 1. Ohad RazWordPress ConsultantWordCamp Jerusalem 2013
  2. 2. WordPress Development Environments Ohad Raz WordPress Consultant WordCamp Jerusalem 2013
  3. 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. 4. Whats this about?• Development Environments.• Development Environments Workflow.• Tips and Tricks: • Server. • Domain. • Files. • Database.• Some Version Control.
  5. 5. EnvironmentsLocal / Development Staging / Testing Live / Production
  6. 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. 7. Staging EnvironmentThe Staging Environment is a server theresembles where the project is actuallygoing to live and where you upload yourwork for testing.Its mostly used for testing and showingoff your work.
  8. 8. Live EnvironmentThe live environment is where theproject is live on the web with realcontent and where users actuallyinteract with your work It’s the actual site.
  9. 9. But why? All Environments: • Mistakes and accidents happen. • You want to be taken seriouslyDevelopment: 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. 10. Development Environment Server WAMP MAMP XAMPP Windows Mac X any platform Apache Apache Apache MySQL MySQL MySQL PHP PHP PHP Perl
  11. 11. Development Environment ServerInstall WordPress Locally :1. Download WordPress.2. Extract the downloaded zip file.3. Create a database.4. Configure wp-config.php5. 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. 12. Domain IssueLive: domain.comDev: domain.devThis way you can use a simple Search and Replace on filesand database dump.Or use real domain name Using the hosts file.Live & Dev: domain.com # Point domain.com to your computer domain.com Windows: C:WINDOWSsystem32driversetchosts Mac/Linux: /etc/hosts
  13. 13. Domain IssueCreate A Virtual Host <VirtualHost> 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 </Directory> </VirtualHost> [wamp] c:wampbinapacheApacheVERSIONconfhttpd.conf [mamp] /private/etc/apache2/httpd.conf [xampp] ..apacheconfextrahttpd-vhosts.conf
  14. 14. Files SyncFTP 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. 15. Files Sync wp-config.phpOne level above the WordPress Root Directory in all environmentsand 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. 16. Files Sync wp-config.php//First we check for development envif ( 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. 17. Database SyncNative Export ImportIts best to import into Dev then move the database over toproduction because when you import it will download all thenew media files from production.
  18. 18. Database SyncDatabase 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. 19. Database SyncUse A plugin:WP Migrate DBWhich takes care ofserialized dataEx: s:9:“domin.dev"Becomes:s:11:“domain.info"
  20. 20. Database SyncUse 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.sqlRemote to local and visa-versa:# Export remote database directly to local databasessh 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. 21. All Around SolutionsServer / 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 3steps.”
  22. 22. Version ControlVersion 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. 23. Version ControlSome 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. 24. Version ControlMethods:• Version Control the entire WordPress environment• Version Control only the WP-Content Directory• Version Control only a specific Theme or Plugin
  25. 25. Version ControlSimple 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. 26. Version ControlOn 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. 27. Version ControlRepository HostsGITHUB - 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. 28. Version ControlCreate a new BitBucket Repository
  29. 29. Version ControlCreate a new BitBucket Repository
  30. 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.gitgit push
  31. 31. Version Control On Stage/Production: • Clone Bitbucket Repository. • Run WordPress install once.git clone https://bitbucket.org/bainternet/some-wordpress-project.git
  32. 32. Version Control Workflow: On local On Servergit pull git pullgit checkout -b dev//make some changesgit commit -m "made dev changes"git checkout mastergit merge devgit commit -m “merged dev changes"git push
  33. 33. Version ControlOn local On Servergit pullgit checkout -b feature-x git pull//make some changesgit commit -m “started feature-x "git checkout mastergit checkout -b bug-y//fix bug ygit commit -m “Fixed bug y"git checkout mastergit merge bug-ygit commit -m “merged bug y fix"git pushgit checkout feature-x//finish working on feature xgit commit -m “finished feature-x "git checkout mastergit merge devgit commit -m “merged dev changes"git push
  34. 34. Questions???
  35. 35. Thank You!