Skip to content

Laravel starter - Ansible Provisioner not only for Vagrant

Notifications You must be signed in to change notification settings

msztorc/laravel-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Starter

Build Status License

Laravel-Starter

Quick and easy server provisioning for Laravel using Ansible + Vagrant auto provisioning for local environments.

Default environment setup

  • ubuntu 18.04 (bionic64)
  • laravel:latest
  • php 7.4
  • mysql 5.7
  • nginx

Provisioning methods

  • Vagrant deployment with Ansible local provisioning
  • Ansible provisioning (remote environments)

Quick start

Clone this repo

git clone https://github.com/msztorc/laravel-starter.git
cd laravel-starter

Adjust your config settings like project name, passwords, etc... - see below for more details.

Provisioning variables

provisioning/group_vars/all

web_root: /var/www/my-project # project path
web_host: laravel.host        # project domain
db_root_pass: p4ssvv0rD       # database root password
app_db_name: my-project       # application database name
app_db_user: my-project       # application database user
app_db_pass: p4ssvv0rD        # application database user password

Inventory

provisioning/hosts

[local]
localhost	ansible_connection=local

[vagrant]
10.10.10.10 ansible_connection=local ansible_ssh_user=vagrant ansible_ssh_private_key_file=/vagrant/.vagrant/machines/default/virtualbox/private_key

[sandbox]
X.X.X.X ansible_ssh_user=root

[all:vars]
ansible_python_interpreter=/usr/bin/python3

Vagrant deployment with Ansible local provisioning

Vagrant configurations are stored in Vagrantfile

Box default config

IP & hostname

    config.vm.network "private_network", ip: "10.10.10.10"
    config.vm.hostname = "laravel.host"

Resources (default: memory - 2GB, vCPUs - 2)

   config.vm.provider "virtualbox" do |vb|
     vb.memory = 2048
     vb.cpus = 2
   end

Set synced folder (local, destination)

  # config.vm.synced_folder "../data", "/vagrant_data"

If you want to set synced folder mapping local project to box webroot, you have to uncomment this line:

config.vm.synced_folder "../GIT/my-project", "/var/www/my-project"

Run your VM using Vagrant with Ansible auto-provisioning

vagrant up

Note Remember to run vagrant reload every time when Vagrantfile has been updated

Other useful vagrant commands

Check status of all machines

vagrant global-status

Halt vagrant box (run in box directory)

vagrant halt

Up vagrant box (run in box directory)

vagrant up

Note Remember to run vagrant reload and vagrant provision every time when any provisioning configs were updated

Xdebug

To integrate Xdebug with PhpStorm perform following steps:

  1. Make sure you have php7.4-xdebug extension installed in within the vagrant box.
  2. Append following configuration to the /etc/php/7.4/php.ini file:
[xdebug]
zend_extension=/usr/lib/php/20170718/xdebug.so
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.profiler_enable=1
xdebug.remote_host=10.10.10.10
  1. Execute command: sudo service php7.4-fpm restart.
  2. Install Xdebug helper extension for Chrome (or some kind of equivalent for your browser).
  3. In PhpStorm:
  • Press Ctrl+Shift+A and search Web Server Debug Validation.
  • Choose Local Web Server or Shared Folder.
  • Determine Path to create validation script like so: /<path>/<to>/<project>/my-project/public
  • Determine Url to validation script like so: http://laravel.host.
  • After clicking Validate button you should receive some information with green ticks. If not - you probably messed up with previous settings.
  1. Navigate to: Languages & Frameworks > PHP > Servers and map your local and remote paths. It should be something like: my-project -> /var/www/my-project.
  2. Press Start Listening for PHP Debug Connections button. It should be placed on top right side with phone icon.
  3. Place breakpoint somewhere in your code that will be executed in the next request e.g. index.php.
  4. In the browser:
  • Make sure you have enabled Debug option in previously installed browser extension.
  • Refresh application's page.
  1. In PhpStorm Debug panel should appear. You can toggle it using Alt+5.
  2. Enjoy 🤘

Ansible provisioning

Adjust staging section in inventory file provisioning/hosts and set IP for remote server

[staging]
X.X.X.X ansible_ssh_user=root
cd provisioning
ansible-playbook -i hosts --limit staging playbook.yml

or using user and password

ansible-playbook -i hosts --limit staging playbook.yml -u root -k

-u <REMOTE_USER>, --user <REMOTE_USER>

-k, --ask-pass ask for connection password

if you want to enable debugging just add to ansible-playbook command verbose option -v (-vvv for more, -vvvv to enable connection debugging)

About

Laravel starter - Ansible Provisioner not only for Vagrant

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published