Skip to content

andreycattalin/dev-web-server

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ubuntu xenial 64 virtual environment for web apps via Vagrant provisioned with Ansible.

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

Ansible is an IT automation tool. It can configure systems, deploy software, and orchestrate more advanced IT tasks such as continuous deployments or zero downtime rolling updates.

What do you get?

A Virtualbox virtual machine with Ubuntu Trusty64 provisioned with this:

  • Common Role:
  • Webtier Role:
    • apache2 with modules: actions, alias, fastcgi, rewrite, ssl, wsgi
    • php with packages: php-dev, php-pear, php-xdebug, php-curl, php-mcrypt, php-imagick, php-intl, php-gd, phpunit, php-mongodb, php-mysql, php-mbstring, php-zip, php-bcmath
    • python with packages: python-setuptools, python-mysqldb, python-pip, python-virtualenv
    • npm with components: bower, gulp-cli, grunt-cli, live-server
    • ruby with packages: ruby-bundler
    • composer
    • nodejs
    • Oracle Java
  • DBtier Role:
    • MySQL
    • MongoDB
    • ElasticSearch
  • Webproject Role:
    • Clone repositories
    • SSL apache config
    • Apache virtual host config
    • Shell script

1. Dependencies

You must have installed the following tools in order to work:

2. How to install dependencies?

Ubuntu/Debian Linux Download and install:

sudo apt-get install software-properties-common
sudo apt-get update
sudo apt-get install git vagrant ansible virtualbox virtualbox-guest-additions-iso

OSX Download and install:

a. Traditional way

b. HomeBrew way http://brew.sh/

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install caskroom/cask/brew-cask
brew cask install vagrant
brew cask install virtualbox
brew install ansible

Windows Download and install:

3. How to use it?

I recommend this directory structure:

Workspace/
├── hittten/
|     ├── dev-server/
|     ├──   .
|     ├──   .
|     └── another-web-project/
├──   .
├──   .
└── another-vendor/
      └── another-web-project/
  • Open a terminal (if you are using windows open git-bash as an Administrator. Why?)
  • Go to your workspace directory
mkdir hittten
cd hittten
git clone git@github.com:hittten/dev-web-server.git
  • Setup your projects config file: Create projects.yml in the config directory (../dev-web-server/config/projects.yml) and build your projects:
Parameter Type Required Default Comments
domain string Yes None Apache ServerName.
See ServerName Directiva and VirtualHost Examples.
ssl string Yes None Only options: 'false' or 'true'.
Note: If there are no single quotes, it will not work.
workspace string Yes None Path of the project code.
host string No '*:80' or '*:443' depends of ssl parameter. This parameter will be in <VirtualHost host>.
See VirtualHost Directiva and VirtualHost Examples.
public_html string No same workspace parameter Path to the project folder that is public from the browser.
See Directory Directiva
repository string No None git, SSH, or HTTP(S) protocol address of the git repository.
version string when repository is defined None What version of the repository to check out. This can be the the literal string HEAD, a branch name, a tag name.

config/projects.yml example:

---
projects:
    - {
      domain: 'domain.com.dev',
      ssl: 'false',
      repository: 'git@github.com:vendor/repository.git',
      version: 'dev',
      workspace: '/home/ubuntu/Workspace/vendor/domain.com.dev',
      public_html: '/home/ubuntu/Workspace/vendor/domain.com.dev/web',
      script: 'cd /home/ubuntu/Workspace/vendor/domain.com.dev && yes | composer install --no-interaction'
    }
    - {
      domain: 'other.domain.com.dev',
      ssl: 'true',
      workspace: '/home/ubuntu/Workspace/vendor/other.domain.com.dev',
    }
  • If you build a project with ssl, you must put the crt file and key file in (../dev-web-server/config/ssl/) path with the same name of the domain parameter:
    • dev-web-server/config/ssl/other.domain.com.dev.crt
    • dev-web-server/config/ssl/other.domain.com.dev.key
  • Edit your local hosts file: Windows: C:\Windows\System32\drivers\etc\hosts, Linux: /etc/hosts or OSX: /etc/hosts:
    • Add new line with your domains projects 192.168.2.100 domain.com.dev
cd dev-web-server # Note: you always have to be in this directory to run these commands

#To manage the virtual machine
vagrant up              #To start the virtual machine.
vagrant ssh             #To connect to the virtual machine.
vagrant reload          #To restart the virtual machine.
vagrant status          #To see the status of virtual machine.
vagrant halt            #To turn off the virtual machine (always turn off your virtual machine before restart or shutdown your host computer).
vagrant destroy         #To delete the virtual machine (you can use this if you have any problem with your machine and start over with a "vagrant up").

#To manage provision
vagrant up --provision  #When you do vagrant up in a first time the ansible will provisioned the machine automatically, if you need reprovision you can use this command with the machine off
vagrant provision       #When you do vagrant up in a first time the ansible will provisioned the machine automatically, if you need reprovision you can use this command with the machine on

Then in your host machine you can use any IDE software to develop in your Workspace directory and you will see all these projects in your virtual machine (~/Workspace)

3.1 Symfony Development Mode

To enable */app_dev.php in your project, remember to add your project ip in web/app_dev.php

if (isset($_SERVER['HTTP_CLIENT_IP'])
    || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
    || !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '192.168.2.1', '::1'], true) || PHP_SAPI === 'cli-server')
) {
    header('HTTP/1.0 403 Forbidden');
    exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}

4. Custom config

Create config.rb in the config directory (../dev-web-server/config/config.rb), copy and paste this:

# Set the ip machine in order to work with your router gateway.
# You can set almost any IP depend of your router configuration.
# Example: router gateway: 192.168.1.1 => 192.168.2.xxx (the 2 can be any number except 1)
# Example: router gateway: 10.1.1.1 => 10.1.2.xxx (the 2 can be any number except 1)

# Note: if you don't have any special config in your router, you can leave the default value.
VIRTUAL_MACHINE_IP = '192.168.2.100'

# The memory RAM of your virtual machine
VIRTUAL_MACHINE_MEMORY = '2048'

GIT_CONFIG_FILE = '~/.gitconfig'
GIT_IGNORE_FILE = '~/.gitignore'
SSH_PATH = '~/.ssh'

Edit whatever you want and save.

About

Vagrant virtual machine

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Shell 100.0%