I can not access my Laravel 5 project by Vagrant and Nginx

0

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

  • PHP7;
  • PostgreSQL 9.3;
  • Nginx 1.9;
  • Git.

The problem is that when I access the url http://advodocs.local.com/ Chrome returns me:

  

The advodocs.local.com page is not working

     

advodocs.local.com can not fulfill this request at this time.

And accessing the Nginx log I have the following:

PHP 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(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->write
2017/01/06 01:58:23 [error] 2107#0: *1 FastCGI sent in stderr: "PHP 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/Ex...

Explaining the configuration of the environment

Hosts

On my computer I edited /etc/hosts and entered 192.168.68.20 advodocs.local.com .

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"
end

init.sh

#!/usr/bin/env bash

sudo apt-get update -y
sudo apt-get upgrade -y

sudo apt-get install --reinstall -y \
    language-pack-en \
    language-pack-pt

sudo apt-get install -y \
    python-software-properties \
    build-essential \
    zip \
    unzip \
    software-properties-common

php.sh

#!/usr/bin/env bash

sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
sudo apt-get update

sudo apt-get install -y \
    php7.0-fpm \
    php7.0-mysql \
    curl \
    php7.0-mbstring \
    php-xml

sudo cp /vagrant/provision/php/php.ini /etc/php/7.0/fpm/php.ini

sudo service php7.0-fpm restart

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

composer self-update

nginx.sh

#!/usr/bin/env bash

sudo apt-get update
sudo apt-get install -y \
    nginx

sudo service nginx start

# set up nginx server
sudo cp /vagrant/provision/nginx/default /etc/nginx/sites-available/
sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
sudo chmod 644 /etc/nginx/sites-available/default
sudo service nginx reload
sudo service nginx restart

# clean /var/www
sudo rm -Rf /var/www

# symlink /var/www => /vagrant
ln -s /vagrant /var/www

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

/ etc / nginx / sites-enabled / default

I have just modified the part below this file:

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

php.ini

I just modified a part to cgi.fix_pathinfo=0

Summarizing

As you can see, under the dependencies, I copy the Nginx and PHP configuration files to their folder when the VM goes up and I give the permissions in the

    
asked by anonymous 06.01.2017 / 03:13

2 answers

1

After searching you can get the answer. This is a "problem" of Vagrant, which ends up being the owner of all folders, thus modifying some permissions. The right thing to do with PHP is that www-data is the owner, so it was only change in the file Vagrantfile :

config.vm.synced_folder "./", "/vagrant",
owner: "www-data", group: "www-data"

config.vm.synced_folder "./", "/var/www",
owner: "www-data", group: "www-data"
    
04.02.2017 / 21:46
0
  

Permission denied in /vagrant/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107

Hello, try giving permission to the directory you entered.

With VM on, use the

sudo chmod 644 /vagrant/vendor/monolog/monolog/src/Monolog/Handler/
    
17.01.2017 / 13:57