Steps to better manage and deploy code

Matteo Magni
The Joel test : 12 Steps to Better Code
  1. Do you use source control?
  2. Can you make a build in one step?
  3. Do you make daily builds?
  4. ...
Version control, also known as revision control or source control,[1] is the management of changes to documents, computer programs, large web sites, and other collections of information.
Changes are usually identified by a number or letter code, termed the "revision number", "revision level", or simply "revision"
For example, an initial set of files is "revision 1". When the first change is made, the resulting set is "revision 2", and so on. Each revision is associated with a timestamp and the person making the change. Revisions can be compared, restored, and with some types of files, merged.

Git was created by Linus Torvalds in 2005 for development of the Linux kernel
Torvalds sarcastically quipped about the name git (which means unpleasant person in British English slang):
"I'm an egotistical bastard, and I name all my projects after myself.
First 'Linux', now 'git'."
The man page describes Git as "the stupid content tracker".

Git as a service


That is, the construction of something that has an observable and tangible result
The term build may refer to the process by which source code is converted into a stand-alone form that can be run on a computer or to the form itself.

repetitive tasks

  • Install dependencies
  • Compile
  • Minify code
  • Run tests
  • ...

Install dependencies

don't versioning the code of others

Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.
composer init
	"name": "ilbonzo/wp-site",
	"type": "project",
	"require": {}
Repetitive tasks in multi environments
  • Development
  • Testing
  • Staging
  • Production
  • Apache version and modules
  • Php version and extensions
  • Mysql version
  • Linux filesystem or Windows
  • ...



Vagrant is a tool for building and managing virtual machine environments in a single workflow. With an easy-to-use workflow and focus on automation, Vagrant lowers development environment setup time, increases production parity, and makes the "works on my machine" excuse a relic of the past.

Vagrant support VirtualBox, Hyper-V, VMWare and Docker as provider

    vagrant up
    vagrant halt
    vagrant ssh
    vagrant destroy

Vagrant boxes


  • Linux
  • Apache
  • MySQL
  • PHP
	vagrant init beet/box
	vagrant up
	mkdir -p site/web
	vagrant ssh
	sudo ln -s /vagrant/site/web /var/beetbox
	mysqladmin -u root password password
	// site/index.php
	composer require johnpbloch/wordpress
	"require": {
		"johnpbloch/wordpress": "^5.2"
		"name": "ilbonzo/wp-site",
		"type": "project",
		"config": {
			"vendor-dir": "web/content/vendor"
		"extra": {
			"wordpress-install-dir": "web/wp"
		"require": {
			"johnpbloch/wordpress": "^5.2"
						// wp-config.php
	// Load Composer’s autoloader
	require_once (__DIR__.'/../content/vendor/autoload.php');

	// Move the location of the content dir
	define('WP_CONTENT_DIR', dirname(__FILE__).'/../content');
	define( 'WP_CONTENT_URL', '/content');
						// index.php
	/** Loads the WordPress Environment and Template */
	require( dirname( __FILE__ ) . '/wp/wp-blog-header.php' );
	RewriteEngine on
	RewriteCond %{REQUEST_URI} !^/phpmyadmin
	RewriteRule ^(.*)$ /wp/$1

	"repositories": [
			"type": "composer",
			"url" : ""
	"extra": {
		"installer-paths": {
			"web/content/plugins/{$name}/": ["type:wordpress-plugin"],
			"web/content/themes/{$name}/": ["type:wordpress-theme"]
	"require": {
		"wpackagist-theme/twentynineteen": "*"

	// wp-config.php
	define('WP_THEME_DIR',  dirname(__FILE__).'/../content/themes' );
	define('WP_PLUGIN_DIR',  dirname(__FILE__).'/../content/plugins' );
	composer update




Wordpress Child theme

Theme Name:   Luna FL partner theme
Description:  Twenty Nineteen Child Theme
Author:       John Doe
Author URI:
Template:     twentynineteen
Version:      1.0.0
License:      GNU General Public License v2 or later
License URI:
Tags:         light, dark, two-columns
Text Domain:  twentynineteenchild

Negate gitignore pattern

	$ git status

	new file:   .gitignore
	new file:   Vagrantfile
	new file:   site/composer.json
	new file:   site/composer.lock
	new file:   site/web/content/themes/luna-fl-theme/style.css
	new file:   site/web/index.php

Do the same for a plugin

Does it works?


	curl -LO
	mv deployer.phar /usr/local/bin/dep
	chmod +x /usr/local/bin/dep
	dep init
	namespace Deployer;

	require 'recipe/common.php';

	// Project name
	set('application', 'my_project');
	// Hosts

		->set('deploy_path', '~/{{application}}');

	// Tasks

	// [Optional] If deploy fails automatically unlock.
	after('deploy:failed', 'deploy:unlock');

	desc('Deploy your project');
	task('deploy', [
		dep deploy
		dep rollback

Demo repository

Matteo Magni

Twitter @ilbonzo

Github @ilbonzo