Reputation: 358
I have a vagrant machine to deploy a Symfony application.
Nowadays I can:
Provision script installs php, postgresql, and creates a database and the chema from doctrine.
I want to run symfony web server automatically when the machine ups. In this way, developer will not need to ssh to this vagrant machine to start this server.
I tried to put "php /vagrant/app/console server:start 0.0.0.0:8000" in /etc/rc.local of the vagrant machine. But when I vagrant up, the server is not running :-(
My vagrant file:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "private_network", ip: "10.10.10.10"
config.vm.provision "shell", path: "provision.sh"
end
My provision.sh file:
#!/usr/bin/env bash
apt-get update > /dev/null
apt-get install --assume-yes php5-cli
apt-get install --assume-yes php5-mcrypt php5-intl php5-pgsql php5-curl
apt-get install --assume-yes postgresql
sudo sed -i "s/^;date.timezone =$/date.timezone = \"Europe\/Madrid\"/" /etc/php5/cli/php.ini |grep "^timezone" /etc/php5/cli/php.ini
echo "client_encoding = utf8" >> "/etc/postgresql/9.3/main/postgresql.conf"
php /vagrant/app/console doctrine:database:create
php /vagrant/app/console doctrine:schema:update --force
sed -i "s/^# By default this script does nothing.$/php \/vagrant\/app\/console server:start 0.0.0.0:8000\\n#next free place/" /etc/rc.local |grep "^php" /etc/rc.local
Any idea how to have symfony's web server started on vagrant up?
Thanks!
Jordi
Upvotes: 2
Views: 1130
Reputation: 53733
If you want to run it from vagrant, you can add the following in your Vagrantfile
config.vm.provision "shell", inline: "php /vagrant/app/console server:start 0.0.0.0:8000", run: "always"
basically it will run the php
command every time you run vagrant up
wether you pass the provision
flag or not.
If you want the vagrant user to run the command, you can add privileged: "false"
to the command.
As others suggested, you might want to set up a real web server (apache, nginx) so it can be run from init
Upvotes: 3