先决条件:
> http://box.scotch.io/流浪盒
2.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "scotch/box"
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.network "forwarded_port", guest: 80, host: 80
config.vm.network "forwarded_port", guest: 3306, host: 3306
config.vm.network "forwarded_port", guest: 443, host: 443
config.vm.network "forwarded_port", guest: 1081, host: 1081
config.vm.hostname = "scotchbox"
config.vm.synced_folder "../../../project", "/var/www", :mount_options => ["dmode=777", "fmode=666", "uid=1000", "gid=1000"], type: "nfs"
#config.vm.synced_folder "./mysql", "/var/lib/mysql", :mount_options => ["dmode=700", "fmode=600", "uid=106", "gid=112"], type: "nfs"
config.vm.synced_folder "../../../project/_conf", "/etc/apache2/sites-enabled", :mount_options => ["dmode=755", "fmode=644", "uid=0", "gid=0"], type: "nfs"
#############################
$script = <<SCRIPT
sudo service apache2 restart && sudo service mysql start
SCRIPT
config.vm.provision "shell", inline: $script, privileged: false, run: "always"
end
> symfony2项目在框内运行.这是composer.json的require部分
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.2.*",
"doctrine/orm": "~2.2,>=2.2.3",
"doctrine/doctrine-bundle": "1.2.*",
"twig/extensions": "1.0.*",
"symfony/assetic-bundle": "2.1.*",
"symfony/swiftmailer-bundle": "2.2.*",
"symfony/monolog-bundle": "2.2.*",
"sensio/distribution-bundle": "2.2.*",
"sensio/framework-extra-bundle": "2.2.*",
"sensio/generator-bundle": "2.3.*",
"jms/security-extra-bundle": "1.4.*",
"jms/di-extra-bundle": "1.3.*",
"kriswallsmith/assetic": "v1.1.0-alpha4",
"gedmo/doctrine-extensions": "dev-master",
"stof/doctrine-extensions-bundle": "dev-master",
"doctrine/doctrine-fixtures-bundle": "dev-master",
"mopa/bootstrap-bundle": "2.2.x-dev",
"twbs/bootstrap": "2.3.1",
"jlong/sass-twitter-bootstrap": "2.3.1",
"liip/theme-bundle": "dev-master",
"fkr/cssurlrewrite-bundle": "*",
"knplabs/knp-paginator-bundle": "dev-master",
"knplabs/knp-components": "dev-master#f096dd02136957ce1fba5819261a45b3ee9ed4a7",
"craue/formflow-bundle": "dev-master",
"sonata-project/admin-bundle": "dev-master",
"sonata-project/cache-bundle": "dev-master",
"sonata-project/doctrine-orm-admin-bundle": "dev-master",
"avalanche123/imagine-bundle": "v2.1",
"r1pp3rj4ck/TwigstringBundle": "dev-master",
"raulfraile/ladybug-bundle": "1.0.1"
},
问题:
即使打开像登录表单这样的空白页面,也需要很长时间.正如在分析器中看到的那样,大部分时间都是由twig渲染的:
Twig taking 3.5 seconds to render
我尝试过的:
>正如您在Vagrantfile中看到的,NFS已启用.不知道如何测试它
>阅读this和this.您在上面的屏幕截图中看到的测试是在完成这些更改后运行的
解决方法:
为了使其在主机操作系统为Win(在我的情况下为Windows 7 x64)的情况下更快地在vagrant中工作,您需要:
>添加this修复.我还在列表中添加了“prod”环境:
public function getCacheDir()
{
if (in_array($this->environment, array('dev', 'test', 'prod'))) {
return '/dev/shm/project/cache/' . $this->environment;
}
return parent::getCacheDir();
}
public function getLogDir()
{
if (in_array($this->environment, array('dev', 'test', 'prod'))) {
return '/dev/shm/project/logs';
}
return parent::getLogDir();
}
>利用NFS修复I / O性能.问题是我很困惑:在synced_folders中设置nfs = true选项并不意味着你通过NFS连接.我的主机操作系统是Win7,我必须安装NFS server才能使其正常工作.请注意,它不是免费的.
这是我必须分享的两个文件夹:
另外,使用synced_folder挂载对我来说不起作用,因为NFS服务器只监听特定的IP地址,所以我不得不注释掉这个:
config.vm.synced_folder "../../../project", "/var/www", type: "nfs",:nfs => true
并把它改为:
$script = <<SCRIPT
sudo mount 192.168.178.40:/d/project /var/www/ && sudo mount 192.168.178.40:/d/project/_conf /etc/apache2/sites-enabled && sudo service apache2 restart
SCRIPT
config.vm.provision "shell", inline: $script, privileged: false, run: "always"
,其中192.168.178.40是NFS端口打开的IP.你可以用你的gurest OS扫描它,例如NMAP.
>而且你还需要安装名为vagrant-winnfsd的vagrant插件.它可以通过以下方式完成:
vagrant plugin install vagrant-winnfsd