1

I'm using a Vagrant box with Debian 8.5 with the following stuff packages.

tmux curl wget nginx php7.0-fpm php7.0-cli php7.0-curl php7.0-gd php7.0-intl php7.0-mysql php7.0-memcached memcached php-mbstring php-xml mariadb-server nodejs git unzip zip

My problem is, that when I try to write a session (e.g. after a login) in any directory I'm getting a 502 Bad Gateway error.

The /var/log/nginx/error.log has the following contents

2016/07/18 21:31:59 [error] 15674#15674: *8 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.60.1, server

When I enable debug log this is the output. The thing is, I don't really think it's a permission problem since the files are getting written into the directory and there are even contents. But I still get the 502.

My vHost conf

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/project/www/web;
    index app_dev.php

    # Important for Virtualbox
    sendfile off;

    # Make site accessible from http://www.project.dev/
    server_name www.project.dev;

    location / {
        try_files $uri $uri/ /app_dev.php$is_args$args;
    }

    # pass the PHP scripts to FastCGI server listening on /var/run/php/php7.0-fpm.sock
    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_cache off;
        fastcgi_index app_dev.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_buffer_size 1024k;
        fastcgi_buffers 4 2048k;
        fastcgi_busy_buffers_size 2048k;
    }
}

My vagrant bootstrap scripts

#!/usr/bin/env bash
projectname='project'
projectpath="/var/www/$projectname/www"
r_password=password
u_password=secret

echo "Initial update of the box"
apt-get update
cp ${projectpath}/vagrant_ressources/locale.gen /etc/
locale-gen de_DE.UTF-8
echo -e 'LANG=de_DE.UTF-8\nLC_ALL=de_DE.UTF-8' > /etc/default/locale
timedatectl set-timezone Europe/Berlin
mkdir -p ${projectpath}/static

echo "Adding Dotdeb repository"
cp ${projectpath}/vagrant_ressources/sources.list /etc/apt/
wget https://www.dotdeb.org/dotdeb.gpg
apt-key add dotdeb.gpg
apt-get update

echo "Installing PHP 7.0 tools and extra software (tmux, curl, wget, nginx, fpm, cli, curl, gd, intl)"
apt-get install -y tmux curl wget nginx php7.0-fpm php7.0-cli php7.0-curl php7.0-gd php7.0-intl php7.0-mysql php7.0-memcached memcached

echo "Installing Laravel dependent stuff"
apt-get install -y php-mbstring php-xml

echo "Creating user and setting permissions"
adduser --disabled-login ${projectname}
adduser www-data ${projectname}
chown -Rf ${projectname}:${projectname} ${projectpath}
chmod 755 ${projectpath}/
chmod 750 ${projectpath}/web
chmod 750 ${projectpath}/static

echo "Initializing database"
debconf-set-selections <<< "mariadb-server-10.0 mysql-server/root_password password $r_password"
debconf-set-selections <<< "mariadb-server-10.0 mysql-server/root_password_again password $r_password"
apt-get install -y mariadb-server
/etc/init.d/mysql restart
# allow remote access (required to access from our private network host. Note that this is completely insecure if used in any other way)
mysql -u root -p${r_password} -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '$r_password' WITH GRANT OPTION; FLUSH PRIVILEGES;"
mysql -u root -p${r_password} -e "CREATE DATABASE $projectname CHARACTER SET utf8;"
mysql -u root -p${r_password} -e "CREATE USER '$projectname'@'%' IDENTIFIED BY '$u_password';"
mysql -u root -p${r_password} -e "GRANT ALL PRIVILEGES ON $projectname.* TO '$projectname'@'%';"



echo "Setting up Nginx"
cp ${projectpath}/vagrant_ressources/${projectname} /etc/nginx/sites-available/${projectname}
ln -s /etc/nginx/sites-available/${projectname} /etc/nginx/sites-enabled/
rm -rf /etc/nginx/sites-available/default

echo "Setting up nodejs"
curl --silent --location https://deb.nodesource.com/setup_0.12 | bash -
apt-get install --yes nodejs
npm install -g gulp

echo "Setting up composer"
apt-get install -y git unzip zip
php -r "readfile('https://getcomposer.org/installer');" > composer-setup.php
php composer-setup.php
php -r "unlink('composer-setup.php');"
mv composer.phar /usr/local/bin/composer

echo "===================================================================================================="
echo "Installation finished. Run composer install in your working dir: $projectpath"
echo "===================================================================================================="

service nginx restart

If you need any more information I'll give it to you. Just ask.

UPDATES
I just switched from Debian to Ubuntu and the problem still exists, so it's not a debian problem (and since I switched from Symfony to Laravel, it's also no Symfony/Laravel problem). This means it could be Vagrant, NFS maybe? or Nginx doing something not right


When using laravel this is the log.

[2016-07-23 19:03:56] local.ERROR: ErrorException: file_put_contents(): Exclusive locks are not supported for this stream in /var/www/project/www/vendor/laravel/framework/src/Illuminate/Filesy$
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'file_put_conten...', '/var/www/pingpo...', 109, Array)
#1 /var/www/project/www/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(109): file_put_contents('/var/www/pingpo...', 'a:4:{s:6:"_toke...', 2)
#2 /var/www/project/www/vendor/laravel/framework/src/Illuminate/Session/FileSessionHandler.php(83): Illuminate\Filesystem\Filesystem->put('/var/www/pingpo...', 'a:4:{s:6:"_toke...', true)
#3 /var/www/project/www/vendor/laravel/framework/src/Illuminate/Session/Store.php(262): Illuminate\Session\FileSessionHandler->write('4fd3fb4a7820527...', 'a:4:{s:6:"_toke...')
#4 /var/www/project/www/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(88): Illuminate\Session\Store->save()
#5 /var/www/project/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(155): Illuminate\Session\Middleware\StartSession->terminate(Object(Illuminate\Http\Request), Object(I$
#6 /var/www/project/www/public/index.php(58): Illuminate\Foundation\Http\Kernel->terminate(Object(Illuminate\Http\Request), Object(Illuminate\Http\Response))
#7 {main}

Somehow I think this must be a Vagrant error, since when trying to do sudo chown -R project:project /var/www/project/www I'm getting the error

chown: changing ownership of ‘{ANY FILE/FOLDER}’: Operation not permitted

5
  • How are you storing php sessions from your php ? what's in your php.ini and specifically session.save_path. If you're using memcached it should be session.save_handler = memcache and session.save_path = "tcp://localhost:11211" Jul 21, 2016 at 11:12
  • Hey. I tried native file as well as memcache. I'm getting the errors on both cases. Jul 23, 2016 at 9:44
  • Where are the logs from PHP? Jul 23, 2016 at 18:51
  • I updated my post with the log message I'm getting when using Laravel, but I think it has to be an NFS/Vagrant problem Jul 23, 2016 at 19:06

1 Answer 1

1

Old question, so I really hope you sorted it out by now.

For anybody else still facing this, I was able to fix the file_put_contents(): Exclusive locks are not supported for this stream issue by setting up my Vagrantfile this way:

config.vm.synced_folder ".", "/vagrant", 
    :nfs => true, 
    :nfs_version => 4, 
    :nfs_udp => false, 
    :mount_options => ['sec=sys']

Don't forget to run vagrant reload after updating Vagrantfile.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .