最近电脑系统重新安装,然后环境也重新搭建了,这不各种奇葩的vagrant问题一个接一个,现在PHP学习网把遇到的问题记录在下,只要碰到的问题,便会断断续续记录在下。
所用版本
1、VirtualBox-5.1.26-117224-Win.exe2、vagrant_1.9.8_x86_64.msi
4、系统window10
问题一:window数据无法同步到虚拟机
报错信息:mount -t vBoxsf -o uid=1000,gid=1000 vagrant /vagrant
The error output from the command was:
/sbin/mount.vBoxsf: mounting Failed with the error: No such device
vagrant plugin install vagrant-winnfsd
完成后重启,看看效果。
问题二:open_basedir问题(已不属于vagrant的问题)
open_basedir:将 PHP 所能打开的文件限制在指定的目录树,包括文件本身。本指令不受安全模式打开或者关闭的影响。根据我的理解说一下,大体目录如下目录树,我们将网站的运行目录指定到web目录下面,在index.PHP中若是用require引用Model,便会出现报错。
├── Common
├── Domain
├── Model
└── Public
├── Web
│ └── index.PHP
└── init.PHP
报错信息
Warning: require(): open_basedir restriction in effect. File(/home/wwwroot/www.viPHPer.com/vendor/autoload.PHP) is not within the allowed path(s): (/home/wwwroot/www.viPHPer.com/frontend/web/:/tmp/:/proc/) in /home/wwwroot/www.viPHPer.com/frontend/web/index.PHP on line 8
Warning: require(/home/wwwroot/www.viPHPer.com/vendor/autoload.PHP): Failed to open stream: Operation not permitted in /home/wwwroot/www.viPHPer.com/frontend/web/index.PHP on line 8
Fatal error: require(): Failed opening required '/home/wwwroot/www.viPHPer.com/frontend/web/../../vendor/autoload.PHP' (include_path='.:/usr/local/PHP/lib/PHP') in /home/wwwroot/www.viPHPer.com/frontend/web/index.PHP on line 8
此错误在使用Yii2框架时,是比较容易出现的。
解决方法,打开/usr/local/Nginx/conf/fastcgi.conf 文件,在文件的最后一行我们可以看到
fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";
修改为:
fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/home/wwwroot/:/tmp/:/proc/";
注意:/home/wwwroot/ 为你网站的执行目录,根据自己的配置修改。
问题二:vagrant本地目录和虚拟机目录同步问题
vagrant总是给人惊喜,用着用着就坏了,坏了就得解决问题,出现的错误信息如下Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vBoxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant Box. For context, the command attempted was:
mount -t vBoxsf -o uid=1000,gid=1000 vagrant /vagrant
The error output from the command was:
/sbin/mount.vBoxsf: mounting Failed with the error: No such device
仔细阅读以下,说是没办法同步目录。各种查找后找到解决方法,安装增强工具。
sudo apt-get install virtualBox-guest-utils #虚拟机上执行
然后重启 vagrant reoad,问题解决。