dousi6405 2017-02-04 21:09
浏览 79
已采纳

无法在流浪汉nginx中运行php artisan make

I'm creating a development environment using Vagrant with this dependencies:

  • PHP7;
  • Nginx 1.9;
  • Laravel 5.3.

The problem is when I try to run php artisan make:controller Test I received this message:

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

Describing my enviroment

My Laravel project is at the root of var/www, and i run the following commands to change folders permissions:

chown -R www-data:www-data /var/www
chmod -R 775 /var/www/storage

/etc/nginx/sites-enabled/default

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;
    }
}

Vagrantfile

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 project is at the root of /var/www

Repository link here

  • 写回答

2条回答 默认 最新

  • doujindou4356 2017-02-07 06:28
    关注

    Since you are running an Artisan command to make your controller, the command is trying to create your controller file through your ubuntu user but your ubuntu user doesn't have write permissions to your app folders to create the controller.

    Let's say your ubuntu user is allan, do the following to solve this:

    1. chown -R allan:allan /var/www
    2. chown -R allan:www-data /var/www/storage
    3. chmod -R 775 /var/www/storage
    4. chown -R allan:www-data /var/www/bootstrap/cache
    5. chmod -R 775 /var/www/bootstrap/cache

    Now run your artisan command. It should work. If it doesn't, just check your /vagrant/storage/logs/laravel.log file and post the error

    Alternatively, a quick and dirty way (that I don't recommend) is that you can just run your command through your www-data user like so: sudo su -s /bin/bash www-data and then run your Artisan command

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?