Skip to content

Instantly share code, notes, and snippets.

@acodeninja
Last active September 24, 2018 10:17
Show Gist options
  • Save acodeninja/649387bc8d82ed1f91669e7790eaa353 to your computer and use it in GitHub Desktop.
Save acodeninja/649387bc8d82ed1f91669e7790eaa353 to your computer and use it in GitHub Desktop.
A drop in `Vagrantfile` for Symfony3

A drop in Vagrantfile for Symfony3

vagrant up

Ensure you have the hostupdater plugin installed:

$ vagrant plugin install vagrant-hostupdater

And that the Vagrantfile is in the root of your symfony project (same place as your composer.json)

$ vagrant up

parameters.yml

Either use this as your parameters.yml file, or enter these details when running composer install

# This file is auto-generated during the composer install
parameters:
    database_host: localhost
    database_port: null
    database_name: symfony
    database_user: symfony
    database_password: symfony
    secret: ThisTokenIsNotSoSecretChangeIt
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.network "private_network", ip: "192.168.190.#{2 + rand(255)}"
config.vm.hostname = "symfony-app.test"
config.hostmanager.enabled = true
config.hostmanager.manage_host = true
config.vm.synced_folder "./", "/vagrant", id: "vagrant-root",
owner: "vagrant",
group: "www-data",
mount_options: ["dmode=775,fmode=664"]
config.vm.provision "shell", inline: <<-SHELL
echo "Installing requirements: php7.2, nginx, mysql"
add-apt-repository -y ppa:ondrej/php
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y \
php7.2-fpm php-mysql php-xdebug php-xml php-curl php-zip composer \
mysql-server \
nginx
echo "Creating Symfony user on database"
sudo mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'symfony'@'localhost' IDENTIFIED BY 'symfony';"
echo "Creating Symfony nginx configuration"
cat << 'EOF' > /etc/nginx/sites-enabled/default
server {
server_name _;
root /vagrant/web;
location / {
try_files $uri /app_dev.php$is_args$args;
}
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
location ~ ^/app\.php(/|$) {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
EOF
echo "Testing and restarting nginx service"
/etc/init.d/nginx configtest
systemctl restart nginx.service
SHELL
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment