我正在使用带有此依赖关系的 Vagrant 创建开发环境:
问题是当我尝试运行php artisan make:controller Test
时收到此消息:
PHP Fatal error: Uncaught UnexpectedValueException: The stream or file "/vagrant/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in /vagrant/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107
Stack trace:
#0 /vagrant/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\StreamHandler->write(Array)
#1 /vagrant/vendor/monolog/monolog/src/Monolog/Logger.php(337): Monolog\Handler\AbstractProcessingHandler->handle(Array)
#2 /vagrant/vendor/monolog/monolog/src/Monolog/Logger.php(616): Monolog\Logger->addRecord(400, Object(UnexpectedValueException), Array)
#3 /vagrant/vendor/laravel/framework/src/Illuminate/Log/Writer.php(202): Monolog\Logger->error(Object(UnexpectedValueException), Array)
#4 /vagrant/vendor/laravel/framework/src/Illuminate/Log/Writer.php(113): Illuminate\Log\Writer->writeLog('error', Object(UnexpectedValueException), Array)
#5 /vagrant/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(71): Illuminat in /vagrant/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 107
PHP Fatal error: Uncaught UnexpectedValueException: The stream or file "/vagrant/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in /vagrant/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107
Stack trace:
#0 /vagrant/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\StreamHandler->write(Array)
#1 /vagrant/vendor/monolog/monolog/src/Monolog/Logger.php(337): Monolog\Handler\AbstractProcessingHandler->handle(Array)
#2 /vagrant/vendor/monolog/monolog/src/Monolog/Logger.php(616): Monolog\Logger->addRecord(400, Object(Symfony\Component\Debug\Exception\FatalErrorException), Array)
#3 /vagrant/vendor/laravel/framework/src/Illuminate/Log/Writer.php(202): Monolog\Logger->error(Object(Symfony\Component\Debug\Exception\FatalErrorException), Array)
#4 /vagrant/vendor/laravel/framework/src/Illuminate/Log/Writer.php(113): Illuminate\Log\Writer->writeLog('error', Object(Symfony\Component\Debug\Exception\FatalErrorException), Array)
#5 /vagrant/v in /vagrant/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 107
我的Laravel项目位于var/www
的根目录,我运行以下命令来更改文件夹权限:
chown -R www-data:www-data /var/www
chmod -R 775 /var/www/storage
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/public;
index index.php index.html index.htm index.nginx-debian.html;
server_name advodocs.local.com;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Vagrant.configure("2") do |config|
# Customiza propriedades do Vagrant
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", 2524]
vb.customize ["modifyvm", :id, "--cpus", 1]
end
# Escolhe a box
config.vm.box = 'ubuntu/trusty64'
# Configura port forwarding
config.vm.network :forwarded_port, guest: 80, host: 8080, auto_correct: true
config.vm.network :private_network, ip: "192.168.68.20"
#Inicia o provisionamento
config.vm.provision :shell, :path => "provision/init.sh"
config.vm.provision :shell, :path => "provision/php.sh"
config.vm.provision :shell, :path => "provision/postgres.sh"
config.vm.provision :shell, :path => "provision/nginx.sh"
config.vm.provision :shell, :path => "provision/node.sh"
config.vm.provision :shell, :path => "provision/git.sh"
#Muda o dono de algumas pastas
config.vm.synced_folder "./", "/vagrant",
owner: "www-data", group: "www-data"
config.vm.synced_folder "./", "/var/www",
owner: "www-data", group: "www-data"
end
Obs:Laravel项目位于/ var / www
的根目录存储库链接here
答案 0 :(得分:4)
由于您正在运行Artisan命令来制作控制器,因此该命令正在尝试通过您的ubuntu用户创建控制器文件,但您的ubuntu用户没有对您的应用程序文件夹具有写入权限来创建控制器。 / p>
让我们说你的ubuntu用户是allan,请执行以下操作来解决此问题:
chown -R allan:allan /var/www
chown -R allan:www-data /var/www/storage
chmod -R 775 /var/www/storage
chown -R allan:www-data /var/www/bootstrap/cache
chmod -R 775 /var/www/bootstrap/cache
现在运行你的工匠命令。它应该工作。如果没有,请检查您的/vagrant/storage/logs/laravel.log
文件并发布错误
或者,快速而肮脏的方式(我不推荐)是你可以通过www-data用户运行命令,如下所示:sudo su -s /bin/bash www-data
然后运行你的Artisan命令
答案 1 :(得分:0)
我只是将config.vm.synced_folder
更改为:
config.vm.synced_folder "./", "/vagrant",
owner: "vagrant", group: "www-data", mount_options: ["dmode=775,fmode=664"]