Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write .htaccess with Nginx #222

Open
magikcypress opened this issue Apr 23, 2017 · 4 comments · May be fixed by #226
Open

Write .htaccess with Nginx #222

magikcypress opened this issue Apr 23, 2017 · 4 comments · May be fixed by #226

Comments

@magikcypress
Copy link

Steps to reproduce

We have the following log error on an application installed on a Debian with the Nginx web server. I think you have to force the PHP script for Nginx servers so that it does not write a .htaccess file in data.

What happens

2017/04/23 06:41:20 [error] 25532#0: *472 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught exception 'Exception' with message 'unable to write to file data/.htaccess' in /var/www/zerobin/lib/Persistence/AbstractPersistence.php:104 Stack trace: #0 /var/www/zerobin/lib/Persistence/AbstractPersistence.php(73): PrivateBin\Persistence\AbstractPersistence::_initialize() #1 /var/www/zerobin/lib/Persistence/TrafficLimiter.php(106): PrivateBin\Persistence\AbstractPersistence::_exists('traffic_limiter...') #2 /var/www/zerobin/lib/PrivateBin.php(223): PrivateBin\Persistence\TrafficLimiter::canPass() #3 /var/www/zerobin/lib/PrivateBin.php(135): PrivateBin\PrivateBin->_create() #4 /var/www/zerobin/index.php(18): PrivateBin\PrivateBin->__construct() #5 {main} thrown in /var/www/zerobin/lib/Persistence/AbstractPersistence.php on line 104" while reading response header from upstream, client: 10.0.2.2, server: ortest.noho.st, request: "POST /zerobin/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:"

What should happen

94         // Create .htaccess file if it does not exist.
 95         $file = self::$_path . DIRECTORY_SEPARATOR . '.htaccess';
 96         if (!is_file($file)) {
 97             $writtenBytes = @file_put_contents(
 98                 $file,
 99                 'Allow from none' . PHP_EOL .
100                 'Deny from all' . PHP_EOL,
101                 LOCK_EX
102             );
103             if ($writtenBytes === false || $writtenBytes < 30) {
104                 throw new Exception('unable to write to file ' . $file, 11);
105             }
106         }

Additional information

Basic information

Debian Jessie

Nginx

Browser:

PrivateBin last version:

@elrido
Copy link
Contributor

elrido commented May 3, 2017

I do use Debian Jessie and nginx, too, but never got that error. I do of course agree, that creating the .htaccess file is pointless for non-apache setups as they will ignore it, so the PR is certainly an improvement.

But I suspect that the problem here isn't nginx, rather the specific setup. Is the directory data (or if that wasn't created yet, the directory PrivateBin was installed into) writeable by the user of the php process? If not sure, are you using php-fpm or php-cgi? In the latter case it would be the nginx user.

@rugk
Copy link
Member

rugk commented May 3, 2017

It is likely not writable, that's why this error happens. However, the error can be prevented, and as you see there is already a PR for it.

@elrido
Copy link
Contributor

elrido commented May 3, 2017

Well, if that dir isn't writeable, then the data store won't work with the filesystem backend and the server salt and trafficlimiter can't be stored either. So apart from helping with the (very welcome) PR I think that we need to support @magikcypress with the access problem, too.

@rugk
Copy link
Member

rugk commented May 3, 2017

No data is writable, but not the parent directory (so the webroot). And this is completely fine as PrivateBin usually does not need to write there…

magikcypress added a commit to magikcypress/PrivateBin that referenced this issue May 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants