Welcome! Log In Create A New Profile

Advanced

PHP-FPM works fine in one directory, but doesn't work at all in another one...

Posted by OliverK 
PHP-FPM works fine in one directory, but doesn't work at all in another one...
February 28, 2012 03:42PM
Hello,

I don't speak English natively, so I'll come straight to the point. On my server there are three two directories I would like nginx to serve files from: "/srv/www/domain.tld/public" and "/srv/www/domain.tld/private". As a matter of fact I can't just simply move "private" into "public". I would like PHP to be functional in both directories and there's the problem. Every time I try to access "http://sub.domain.tld/phpmyadmin" (or "http://sub.domain.tld/phpmyadmin/" or even "http://sub.domain.tld/phpmyadmin/index.php") I get the "File not found." error message displayed. "http://sub.domain.tld" (and "http://sub.domain.tld/" and "http://sub.domain.tld/index.php") on the other hand works just as expected.

Here is the "server"-part of my configuration file (uploaded on pastebin.com to make it easier to read):
http://pastebin.com/a2Mz5jkn

Thanks in advance!
Re: PHP-FPM works fine in one directory, but doesn't work at all in another one...
February 28, 2012 06:07PM
OliverK Wrote:
-------------------------------------------------------
> Hello,
>
> I don't speak English natively, so I'll come
> straight to the point. On my server there are
> three two directories I would like nginx to serve
> files from: "/srv/www/domain.tld/public" and
> "/srv/www/domain.tld/private". As a matter of fact
> I can't just simply move "private" into "public".
> I would like PHP to be functional in both
> directories and there's the problem. Every time I
> try to access "http://sub.domain.tld/phpmyadmin"
> (or "http://sub.domain.tld/phpmyadmin/" or even
> "http://sub.domain.tld/phpmyadmin/index.php") I
> get the "File not found." error message displayed.
> "http://sub.domain.tld" (and
> "http://sub.domain.tld/" and
> "http://sub.domain.tld/index.php") on the other
> hand works just as expected.
>
> Here is the "server"-part of my configuration file
> (uploaded on pastebin.com to make it easier to
> read):
> http://pastebin.com/a2Mz5jkn
>
> Thanks in advance!

SCRIPT_FILENAME needs a full path.

Since the root for public is /srv/www/domain.tld/public you can do either of these:

fastcgi_param SCRIPT_FILENAME /srv/www/domain.tld/public$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

but the root for the private location is /srv/www/domain.tld so either of these:

fastcgi_param SCRIPT_FILENAME /srv/www/domain.tld/private$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root/private$fastcgi_script_name;
Re: PHP-FPM works fine in one directory, but doesn't work at all in another one...
February 28, 2012 06:22PM
Thanks for you answer,

however, I'm quite sure it does not, since I'm running PHP-FPM chrooted ("chroot = /srv/www/domain.tld/"). Also, this wouldn't explain why one of the folders (the one called "public" is working fine).
Re: PHP-FPM works fine in one directory, but doesn't work at all in another one...
February 28, 2012 09:07PM
OliverK Wrote:
-------------------------------------------------------
> Thanks for you answer,
>
> however, I'm quite sure it does not, since I'm
> running PHP-FPM chrooted ("chroot =
> /srv/www/domain.tld/"). Also, this wouldn't
> explain why one of the folders (the one called
> "public" is working fine).

Fair enough.

So do you expect "http://sub.domain.tld/phpmyadmin" to go to the private subdirectory? I would expect that to be "http://sub.domain.tld/private/phpmyadmin"

Please explain the relationship between the private subdirectory and your phpadmin install.
Re: PHP-FPM works fine in one directory, but doesn't work at all in another one...
February 28, 2012 09:17PM
OliverK Wrote:
-------------------------------------------------------
> Thanks for you answer,
>
> however, I'm quite sure it does not, since I'm
> running PHP-FPM chrooted ("chroot =
> /srv/www/domain.tld/"). Also, this wouldn't
> explain why one of the folders (the one called
> "public" is working fine).

Also, if your nginx is compiled with-debug you can activate that and the error log usually shows you where it's looking for the file.

The "file not found" message is from PHP and looks different than an nginx 404, so it's being passed to PHP correctly, you're just somehow giving it the wrong location.
Re: PHP-FPM works fine in one directory, but doesn't work at all in another one...
February 29, 2012 09:25AM
brianmercer Wrote:
-------------------------------------------------------
> OliverK Wrote:
> --------------------------------------------------
> -----
> > Thanks for you answer,
> >
> > however, I'm quite sure it does not, since I'm
> > running PHP-FPM chrooted ("chroot =
> > /srv/www/domain.tld/"). Also, this wouldn't
> > explain why one of the folders (the one called
> > "public" is working fine).
>
> Fair enough.
>
> So do you expect
> "http://sub.domain.tld/phpmyadmin" to go to the
> private subdirectory? I would expect that to be
> "http://sub.domain.tld/private/phpmyadmin"
>
> Please explain the relationship between the
> private subdirectory and your phpadmin install.

Whoops I meant to say "private" instead of "phpmyadmin" in my first post. I wanted to avoid confusion with the names and therefor replaced the real paths I have on my system with "public" and "private", but I forgot to edit the draft of my first post accordingly. So I'd like to have
"http://sub.domain.tld/private" (, "http://sub.domain.tld/private/" and "http://sub.domain.tld/private/index.php") to go to
"/srv/www/domain.tld/private" (or to be more specific to "index.php" inside that directory)
and
"http://sub.domain.tld" (, "http://sub.domain.tld/" and "http://sub.domain.tld/index.php") to go to
"/srv/www/domain.tld/public" (or to be more specific to "index.php" inside that directory).


brianmercer Wrote:
-------------------------------------------------------
> OliverK Wrote:
> --------------------------------------------------
> -----
> > Thanks for you answer,
> >
> > however, I'm quite sure it does not, since I'm
> > running PHP-FPM chrooted ("chroot =
> > /srv/www/domain.tld/"). Also, this wouldn't
> > explain why one of the folders (the one called
> > "public" is working fine).
>
> Also, if your nginx is compiled with-debug you can
> activate that and the error log usually shows you
> where it's looking for the file.
>
> The "file not found" message is from PHP and looks
> different than an nginx 404, so it's being passed
> to PHP correctly, you're just somehow giving it
> the wrong location.

It's not that one 404 error page that comes from nginx. It's really just that "File not found." message, that comes directly from PHP-FPM. So I edited the configuration files of PHP-FPM (master and worker) to log as well, but somehow it doesn't log this one specific error. I even used "su www-data" (that's the user I used for both, nginx and php-fpm) and "vim /srv/www/domain.tld/private/index.php" to see if PHP-FPM can even access the file and the answer is yes, it should (vim opened "index.php" and I was able to save changes).

Thanks again for your time!
Re: PHP-FPM works fine in one directory, but doesn't work at all in another one...
February 29, 2012 10:31AM
Doh, I think I fixed it. All I did was replacing
fastcgi_param SCRIPT_FILENAME /private$fastcgi_script_name;
with
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
and that did actually do the trick. PHP-FPM now works on both paths. I guess $fastcgi_script_name already contains the relative path "/private" (aka "/phpmyadmin" :-P).

Now I get some odd PHP/PHPmyAdmin specific error (something about not being able to start sessions properly)... well, whatever, hehe.

Thanks!
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 183
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready