简体   繁体   English

流浪汉和symfony2

[英]Vagrant and symfony2

I'm having kind of a bizzare issue related to installing Symfony2 from within a vagrant environment. 我有一个与在流浪者环境中安装Symfony2有关的古怪问题。 The environment is set up correctly and is running a web server that is serving files from a folder that is shared with the vagrant environment that is located in the base directory of vagrant. 环境设置正确,并且正在运行Web服务器,该服务器从与vagrant的基本目录中的vagrant环境共享的文件夹中提供文件。

Basically, vagrant is initiated in directory foo and then within foo, there is a directory called webroot. 基本上,vagrant是在目录foo中启动的,然后在foo中,有一个名为webroot的目录。 Vagrant automagically shares the foo directory. Vagrant自动共享foo目录。 An apache server is set up to run so that webroot is the base http directory. 设置apache服务器以运行,以便webroot是基本http目录。 This all works fine and I am able to serve basic HTML, PHP and the MySQL connection is tested to be fine. 这一切都很好,我能够提供基本的HTML,PHP和MySQL连接测试没问题。

I used composer to install vagrant the recommended way, into directory inside /webroot/ called Symfony. 我使用composer以推荐的方式将vagrant安装到/ webroot /中称为Symfony的目录中。 All of the files now exist within the correct directory. 现在所有文件都存在于正确的目录中。 The configuration is correct and there are no items that Symfony claims need to be changed in /config.php. 配置正确,并且没有Symfony声称需要在/config.php中更改的项目。

The issue comes when I attempt to load /app_dev.php. 当我尝试加载/app_dev.php时出现问题。 It throws an exception claiming that it cannot create a file named cache in the /app directory. 它抛出一个异常,声称它无法在/ app目录中创建名为cache的文件。

As chmod +a is not supported within the vagrant box I am using, I elected to set permissions by uncommenting umask(0000) in app_dev. 由于chmod + a在我正在使用的流浪盒中不受支持,我选择通过在app_dev中取消注释umask(0000)来设置权限。 Assuming it was a permission problem, I tried using chmod to adjust the permissions both within the vagrant environment and within osx to 777 for everything. 假设这是一个权限问题,我尝试使用chmod来调整流浪者环境和osx内的权限,以便将所有权限调整到777。

What's strange is that when I chmod a file or directory inside the vagrant environment, it claims to set 777 correctly but then when I ls -l, the permissions have not changed. 奇怪的是,当我在流浪者环境中chmod一个文件或目录时,它声称正确设置了777但是当我ls -l时,权限没有改变。 However, when I chmod a file or directory from OUTSIDE The vagrant environment within the webroot folder, the permissions persist. 但是,当我从OUTSIDE chmod webroot文件夹中的vagrant环境chmod文件或目录时,权限仍然存在。 As symfony does not have r/w permissions within the environment, it cannot create the necessary cache and log files. 由于symfony在环境中没有r / w权限,因此无法创建必要的缓存和日志文件。 When i run symfony from the command from osx, everything works fine. 当我从osx的命令运行symfony时,一切正常。

Does anyone have any insight as to how to change the permissions for the /webroot directory so things within the vagrant environment can actually read and write to it as chmod doesn't appear to work? 有没有人对如何更改/ webroot目录的权限有任何见解,因此流浪者环境中的事物实际上可以读取和写入它,因为chmod似乎不起作用?

Update as of 15th Jan 2016. Instructions for Vagrant 1.7.4+ and Symfony 3. This works. 更新截至2016年1月15日.Vagrant 1.7.4+和Symfony 3的说明。 这是有效的。

On a fresh Ubuntu 14.04 install, ACL was installed but I couldn't use +a or setfacl to fix the permissions issues, and of course, as soon as you change any permissions in terminal in vagrant, they're reset to vagrant:vagrant again. 在新的Ubuntu 14.04安装上,安装了ACL,但我无法使用+ a或setfacl来修复权限问题,当然,只要您在vagrant中更改终端中的任何权限,它们就会重置为vagrant:vagrant再次。

I added the following to my vagrant file: 我将以下内容添加到我的vagrant文​​件中:

# Symfony needs to be able to write to it's cache, logs and sessions directory in var/
config.vm.synced_folder "./var", "/vagrant/var",
 :owner => 'vagrant',
 :group => 'www-data',
 :mount_options => ["dmode=775","fmode=666"]

This tells Vagrant to sync var/logs and var/cache (not to be confused with /var/, these are in the root Symfony directory) and have them owned by vagrant:www-data. 这告诉Vagrant同步var / logs和var / cache(不要与/ var /混淆,这些是在根Symfony目录中)并让它们归vagrant:www-data所有。 This is the same as doing a sudo chown vagrant:www-data var/ , except Vagrant now does it for you and enforces that instead of enforcing vagrant:vagrant. 这与做一个sudo chown vagrant:www-data var/ ,除了Vagrant现在为你执行它并强制执行而不是强制vagrant:vagrant。

Note there are no 777 'hacks' here . 注意这里没有777'黑客'

As soon as I added that, I didn't get any more permissions errors in the apache log and I got a nice Symfony welcome screen. 一旦我添加了这个,我在apache日志中没有得到任何更多的权限错误,我得到了一个很好的Symfony欢迎屏幕。 I hope that helps someone! 我希望能帮助别人!

I think it's a question of user rights. 我认为这是一个用户权利问题。 Your apache + php is probably launched by root. 你的apache + php可能是root用户启动的。 You have to set rights with root. 您必须使用root设置权限。

Two possibilities : 两种可能性:

sudo su
chmod -R 777 app/cache

or 要么

sudo chown -v app/cache
sudo chmod -R 777 app/cache

You will probably have to do the same thing with the log file. 您可能需要对日志文件执行相同的操作。

My vagrant file if you need it : 如果你需要我的流浪文件:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "precise64"  #Box Name
  config.vm.box_url = "http://files.vagrantup.com/precise64.box" #Box Location
  config.vm.provider :virtualbox do |virtualbox|
      virtualbox.customize ["modifyvm", :id, "--memory", "2048"]
  end
  config.vm.synced_folder ".", "/home/vagrant/synced/", :nfs => true
  #config.vm.network :forwarded_port, guest: 80, host: 8080 # Forward 8080 rquest to vagrant 80 port
  config.vm.network :private_network, ip: "1.2.3.4"
  config.vm.network :public_network
  config.vm.provision :shell, :path => "vagrant.sh"
end

vagrant.sh vagrant.sh

#!/usr/bin/env bash

#VM Global Config
apt-get update

#Linux requirement
apt-get install -y vim git

#Apache Install
apt-get install -y apache2

#Apache Configuration
rm -rf /var/www
ln -fs /home/vagrant/synced/web /var/www
chmod -R 755 /home/vagrant/synced

#Php Install
apt-get install -y python-software-properties
add-apt-repository -y ppa:ondrej/php5
apt-get update

apt-get install -y php5 libapache2-mod-php5

#Php Divers
apt-get install -y php5-intl php-apc php5-gd php5-curl

#PhpUnit
apt-get install -y phpunit
pear upgrade pear
pear channel-discover pear.phpunit.de
pear channel-discover components.ez.no
pear channel-discover pear.symfony.com
pear install --alldeps phpunit/PHPUnit


#Php Configuration
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 10M/" /etc/php5/apache2/php.ini
sed -i "s/short_open_tag = On/short_open_tag = Off/" /etc/php5/apache2/php.ini
sed -i "s/;date.timezone =/date.timezone = Europe\/London/" /etc/php5/apache2/php.ini
sed -i "s/memory_limit = 128M/memory_limit = 1024M/" /etc/php5/apache2/php.ini
sed -i "s/_errors = Off/_errors = On/" /etc/php5/apache2/php.ini

#Reload apache configuration
/etc/init.d/apache2 reload

#Composer
php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"
mv -f composer.phar /usr/local/bin/composer.phar
alias composer='/usr/local/bin/composer.phar'

#Postgres
apt-get install -y postgresql postgresql-client postgresql-client php5-pgsql
su - postgres -c "psql -U postgres -d postgres -c \"alter user postgres with password 'vagrant';\""

nfs的更新答案:

config.vm.synced_folder "www", "/var/www", type:nfs, :nfs => { :mount_options => ["dmode=777","fmode=777"] }

Nothing worked for me other than changing location of cache and logs folder to /tmp 除了将缓存和日志文件夹的位置更改为/ tmp之外,对我来说没有任何作用

AppKernel.php AppKernel.php

public function getCacheDir()
{
    if (in_array($this->getEnvironment(), ['test','dev'])) {
        return '/tmp/sfcache/'.$this->getEnvironment();
    }
    return parent::getCacheDir();
}

public function getLogDir()
{
    if (in_array($this->getEnvironment(), ['test','dev'])) {
        return '/tmp/sflogs/'.$this->getEnvironment();
    }
    return parent::getLogDir();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM