Overview
We will build a development environment on CentOS 7.3 using Vagrant and Ansible.
Environment
- PHP 7
- Ruby
- Python
- Nginx
- MySQL 5.7
- Redis
- Mailcatcher
Setup
This directory structure somewhat mimics best practices.
ansible/
├── group_vars
│ └── vagrant.yml
├── host
├── roles
│ ├── common
│ │ └── tasks
│ │ ├── add_remi_repo.yml
│ │ ├── install_common.yml
│ │ ├── install_epel_release.yml
│ │ └── main.yml
│ ├── composer
│ │ └── tasks
│ │ ├── install_composer.yml
│ │ └── main.yml
│ ├── mailcatcher
│ │ └── tasks
│ │ ├── install_mailcatcher.yml
│ │ └── main.yml
│ ├── mysql
│ │ └── tasks
│ │ ├── install_mysql.yml
│ │ └── main.yml
│ ├── nginx
│ │ ├── tasks
│ │ │ ├── install_nginx.yml
│ │ │ └── main.yml
│ │ └── templates
│ │ ├── bmf-tech.com.conf
│ │ └── localdev.conf
│ ├── php
│ │ └── tasks
│ │ ├── install_php.yml
│ │ └── main.yml
│ ├── python
│ │ └── tasks
│ │ ├── install_python.yml
│ │ └── main.yml
│ ├── redis
│ │ └── tasks
│ │ ├── install_redis.yml
│ │ └── main.yml
│ └── ruby
│ └── tasks
│ ├── install_ruby.yml
│ └── main.yml
├── site.retry
└── site.yml
The source is available on github - my-ansible-vagrant, so please refer to that for the contents.
Here is how the Vagrantfile looks.
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "centos7.3"
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.synced_folder "/path/to/directory", "/var/www/html",:mount_options => ["dmode=775,fmode=664"]
config.vm.provision "ansible" do |ansible|
ansible.playbook = "ansible/site.yml"
ansible.inventory_path = "ansible/host"
ansible.limit = 'all'
end
config.vm.network :private_network, ip: "192.168.33.10"
config.vm.hostname = "localdev"
config.hostsupdater.aliases = ["localdev"]
end
You can run provisioning with vagrant provision.
Additional Notes
Is the php-fpm configuration incorrect?
To use PHP 7 with Nginx, it seems necessary to use something called php-fpm as a CGI, which can be tricky. If you encounter a 500 error, reviewing the configuration in this area might resolve the issue.
Building a Laravel Development Environment on CENTOS 7 with NGINX+PHP-FPM+PHP7 on VAGRANT (Part 1)
Unable to access the IP address specified in the Vagrantfile
Although I was able to build it, I struggled to access the IP specified in the Vagrantfile. After reviewing the IP settings and adjusting the firewalld configuration based on the following articles, I managed to resolve the issue. (It seems I encountered a bug in vagrant 1.9.0.)
- [Vagrant] How to deal with not being able to access the IP address specified in the Vagrantfile
- Vagrant cannot ping! Therefore, I had to relearn Vagrant networking
- Cannot connect to the IP set in private_network with vagrant + centos7
Building a virtual environment with CentOS 7 + PHP + MySQL using Vagrant
Impressions
CentOS 7 has quite a few differences from previous OS versions, but I didn't struggle too much with those adjustments. Instead, I had more trouble with the compatibility of MySQL 5.7. It works for now, but I think there is still room for improvement.
References
- github - MiyaseTakurou/vagrant_ansible_laravel - The directory structure for best practices was easy to understand.
- Initializing a virtual machine nicely in a vagrant + ansible + CentOS 7.0 + VirtualBox environment
- Building nginx + wordpress with ansible on CentOS 7
- Building a LAMP environment with Vagrant + ansible (Part 4)
Installing PHP 7 and Nginx on an ubuntu 16.04 environment with Ansible- Setting up a Ruby environment on CentOS with Vagrant + Ansible
- ansible mysql5.7
Mysql 5.7 on Ansible- Building an environment to manipulate Redis with Vagrant + Ansible
- Ansible playbook to install Redis version 2.5 and later
github - heybigname/ansible