PHP unable to get ENV variable set by Vagrant -
i have seen few posts , solutions here, far none of them seem work me. i'm using vagrant 1.8.1 on windows 7 64-bit env plugin installed , enabled config.env.enable
in vagrantfile. [update] i'm perhaps doing wrong or missing something?
i trying set string=123abc
kind of environment variable. started inline provisioning in vagrantfile:
config.vm.provision "shell", inline: <<-shell echo "export my_svr_host=192.168.33.10" > /home/vagrant/.profile shell
i tried source /home/vagrant/.profile
underneath (after echo) did not work..
i tried adding source line provisioning file (bootstrap.sh)
also (in bootstrap file) tried vagrant ssh && source /home/vagrant/.profile && exit
did not work either. note, there line in bootstrap file restarts apache.
i tried set var = value in php.ini
file
; arbitrary, set host ip vagrant vm_host_ip=192.168.33.10
that did not work. tried (in httpd.conf) add setenv vmhostip "192.168.33.10"
then (in shared php file) wanted shell print_r on both $_server , $_env see if of above attempts able set environment var php access value.
the thing came close working, initial attempt of using inline provision echo export command. however, set environment variable if did following:
vagrant --provision vagrant ssh source /home/vagrant/.profile
[edit] i'm doing wrong. based on above, there i'm missing?. i'll source file manually once i've ssh'd host serve?
thanks in advance.
[edit] i'm adding inline provision block in event may others in future.
# privileged false acts sudo, can commands root. config.vm.provision "shell", privileged: false, inline: <<-shell echo "export my_svr_host=192.168.33.10" > /home/vagrant/.profile # add 2 lines (comment , command) .bashrc if not there. if grep -fxq "# source our profile" /home/vagrant/.bashrc # nothing since found target text. echo "we found source line need in .bashrc \n" else # add lines (comment , command) .bashrc echo "# source our profile" | tee -a /home/vagrant/.bashrc echo "source /home/vagrant/.profile" | tee -a /home/vagrant/.bashrc fi shell
this approach:
- is based on helpful tips provided in accepted answer , other research.
- sets variable when doing
vagrant reload --provision
or complete cycle ofvagrant destroy, vagrant up
i
config.vm.provision "shell", privileged: false, inline: <<-shell echo "export my_svr_host=192.168.33.10" > /home/vagrant/.profile shell
as doing .profile
file owned vagrant user - in case file owned root can end issue.
if still issue, can source
within provision block mimic you're doing manually
config.vm.provision "shell", privileged: false, inline: <<-shell echo "export my_svr_host=192.168.33.10" > /home/vagrant/.profile source /home/vagrant/.profile shell
Comments
Post a Comment