Unable to see a php page

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Unable to see a php page

Mahmood Naderan
Hi,
For a test, I have installed nginx 1.0.15 with php 5.3 on an Ubuntu 14.04.
The settings related to php in nginx.conf are as below where I removed the comments for simplicity.


    server {
        listen       80;
        server_name  localhost;
        location / {
            root   /home/ubuntu/htdocs/;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~ \.php$ {
            root           /home/ubuntu/htdocs/public_html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /home/ubuntu/htdocs/public_html/$fastcgi_script_name;
            include        fastcgi_params;
        }
    }


The document root is here.

ubuntu@fr13:~$ ls -l htdocs/
total 36
-rw-r--r-- 1 www-data www-data 1422 مارس  15 15:28 build.xml
drwxr-xr-x 2 www-data www-data 4096 مارس  15 15:28 classes
drwxr-xr-x 2 www-data www-data 4096 مارس  15 15:28 controllers
drwxr-xr-x 2 www-data www-data 4096 مارس  15 15:35 etc
drwxr-xr-x 2 www-data www-data 4096 مارس  15 15:28 includes
-rw-r--r-- 1 www-data www-data  152 مارس  15 15:29 index.html
drwxr-xr-x 2 www-data www-data 4096 مارس  15 15:28 lib
drwxr-xr-x 6 www-data www-data 4096 مارس  15 15:28 public_html
drwxr-xr-x 2 www-data www-data 4096 مارس  15 15:28 views


The index.html is a simple welcome message.


Also

ubuntu@fr13:~$ ls -l htdocs/public_html/index.php
-rw-r--r-- 1 www-data www-data 7556 مارس  15 15:28 htdocs/public_html/index.php




When I open the browser and enter localhost, I can see the welcome message. That means the basic functionality is fine.

However, when I enter localhost/public_html/index.php

I get this message in the browser:


The page you are looking for is temporarily unavailable.
Please try again later.


At the same time, I see this entry in /usr/local/nginx/logs/error.log

2020/03/15 15:50:20 [error] 4808#0: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /public_html/index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"


Why I get connection refused?
What else should I check for more debugging?



Regards,
Mahmood




_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Unable to see a php page

Francis Daly
On Sun, Mar 15, 2020 at 03:58:30PM +0330, Mahmood Naderan wrote:

Hi there,

> For a test, I have installed nginx 1.0.15 with php 5.3 on an Ubuntu 14.04.

> At the same time, I see this entry in /usr/local/nginx/logs/error.log
>
> 2020/03/15 15:50:20 [error] 4808#0: *5 connect() failed (111: Connection
> refused) while connecting to upstream, client: 127.0.0.1, server:
> localhost, request: "GET /public_html/index.php HTTP/1.1", upstream:
> "fastcgi://127.0.0.1:9000", host: "localhost"
>
>
> Why I get connection refused?
> What else should I check for more debugging?

nginx does not "do" php. nginx expects that you have a separate thing
-- in this case, a fastcgi server listening on tcp port 9000 -- that
handles php.

"Connection refused" suggests that you are not running a fastcgi server
there that nginx can access.

You will want to find the Ubuntu method of running the PHP fastcgi
service, possibly called "php-fpm"; and making sure that it is listening
for requests in the place where your nginx does "fasctgi_pass" to.

(As an aside -- the version numbers you mention are not the newest. It
is possible that there are some bugs in those versions that mean that
they do not work well together. If that happens, then you may have more
debugging to do, or choose to use newer versions of things.)

And also -- based on your config, you probably want to make a request for
http://localhost/index.php, not http://localhost/public_html/index.php.
But that will only matter after the current error is resolved.

Good luck with it,

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Unable to see a php page

Mahmood Naderan
Thank you for the feedback. I want to do some tests on a VM albeit the versions are old.

I started php-fpm and opened localhost/index.php
This time I see the content of index.php as a plain text.
I have to do more debugging. Thanks.



Regards,
Mahmood





On Sun, Mar 15, 2020 at 4:53 PM Francis Daly <[hidden email]> wrote:
On Sun, Mar 15, 2020 at 03:58:30PM +0330, Mahmood Naderan wrote:

Hi there,

> For a test, I have installed nginx 1.0.15 with php 5.3 on an Ubuntu 14.04.

> At the same time, I see this entry in /usr/local/nginx/logs/error.log
>
> 2020/03/15 15:50:20 [error] 4808#0: *5 connect() failed (111: Connection
> refused) while connecting to upstream, client: 127.0.0.1, server:
> localhost, request: "GET /public_html/index.php HTTP/1.1", upstream:
> "fastcgi://127.0.0.1:9000", host: "localhost"
>
>
> Why I get connection refused?
> What else should I check for more debugging?

nginx does not "do" php. nginx expects that you have a separate thing
-- in this case, a fastcgi server listening on tcp port 9000 -- that
handles php.

"Connection refused" suggests that you are not running a fastcgi server
there that nginx can access.

You will want to find the Ubuntu method of running the PHP fastcgi
service, possibly called "php-fpm"; and making sure that it is listening
for requests in the place where your nginx does "fasctgi_pass" to.

(As an aside -- the version numbers you mention are not the newest. It
is possible that there are some bugs in those versions that mean that
they do not work well together. If that happens, then you may have more
debugging to do, or choose to use newer versions of things.)

And also -- based on your config, you probably want to make a request for
http://localhost/index.php, not http://localhost/public_html/index.php.
But that will only matter after the current error is resolved.

Good luck with it,

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Unable to see a php page

Francis Daly
On Sun, Mar 15, 2020 at 05:19:57PM +0330, Mahmood Naderan wrote:

Hi there,

> I started php-fpm and opened localhost/index.php
> This time I see the content of index.php as a plain text.
> I have to do more debugging. Thanks.

That's useful.

I suggest that the first step is to look at the http headers returned
from your request -- if they include something like "X-Powered-By: php",
then you can be confident that nginx asked php to process the file (and
further investigation should be on the php side); if they do not, then
you should probably check the nginx side (and the error log, possibly
in debug mode for the test), to see what nginx did with the request that
involved it *not* making the fastcgi_pass request.

Good luck with it,

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Unable to see a php page

Ian Hobson-3


On 15/03/2020 14:00, Francis Daly wrote:

> On Sun, Mar 15, 2020 at 05:19:57PM +0330, Mahmood Naderan wrote:
>
> Hi there,
>
>> I started php-fpm and opened localhost/index.php
>> This time I see the content of index.php as a plain text.
>> I have to do more debugging. Thanks.
>
> That's useful.
>
> I suggest that the first step is to look at the http headers returned
> from your request -- if they include something like "X-Powered-By: php",
> then you can be confident that nginx asked php to process the file (and
> further investigation should be on the php side); if they do not, then
> you should probably check the nginx side (and the error log, possibly
> in debug mode for the test), to see what nginx did with the request that
> involved it *not* making the fastcgi_pass request.
>
> Good luck with it,
>

The thing I notice is that you have two root statements.
You only need the one at the /server level.

Then, if you use the line

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

(That is all on one line).
in the localtion clause, things should work.

--
Ian Hobson


--
This email has been checked for viruses by AVG.
https://www.avg.com

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Unable to see a php page

Mahmood Naderan
OK with this configuration:

        location ~ \.php$ {
            root           /home/ubuntu/htdocs/public_html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

and the following folder structure

$ ls ~/htdocs/
build.xml  classes  controllers  etc  includes  index.html  lib  public_html  views
$ ls ~/htdocs/public_html/
addAttendee.php        checkUser.php             fileService.php   logout.php            upcomingEvents.php
addDeleteFriend.php    css                       findUsers.php     phpinfo.php           users.php
addEvent.php           deleteAttendee.php        friends.php       postedEvents.php      xsl
addEventResult.php     deleteCommentsRating.php  getAppConfig.php  rateit.php            yourUpcomingEvents.php
addPerson.php          deleteEvent.php           images            rejectInvite.php
addPersonResult.php    events.php                index.php         requestCityState.php
approveFriendship.php  favicon.ico               js                revokeInvite.php
calendar.php           feedFromDB.php            login.php         taggedEvents.php
$ ls ~/htdocs/public_html/js/
controls.js  dragdrop.js  effects.js  httpobject.js  prototype.js  starrating.js  validateform.js



when I open "localhost/index.php", I can see the php page, however, in the logs/error.log I see these

2020/03/16 21:34:22 [error] 5821#0: *2 FastCGI sent in stderr: "PHP message: PHP Warning:  session_start() [<a href='function.session-start'>function.session-start</a>]: open(/tmp/http_sessions/sess_dd0e14b5b3f5aebcb53015b6bebc3bfa, O_RDWR) failed: No such file or directory (2) in /home/ubuntu/htdocs/public_html/index.php on line 26

Also I see somethings like

2020/03/16 21:34:22 [error] 5821#0: *2 open() "/home/ubuntu/htdocs/js/dragdrop.js" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /js/dragdrop.js HTTP/1.1", host: "localhost", referrer: "http://localhost/index.php"


I don't know why it is using "/home/ubuntu/htdocs/js/dragdrop.js"?
According to the setting, it should look for it at "/home/ubuntu/htdocs/public_html/js/dragdrop.js" where the file actually exists.

I know that is not directly related to nginx, but I appreciate any feedback.


Regards,
Mahmood






_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Unable to see a php page

Francis Daly
On Mon, Mar 16, 2020 at 09:40:40PM +0330, Mahmood Naderan wrote:

Hi there,

> OK with this configuration:
>
>         location ~ \.php$ {
>             root           /home/ubuntu/htdocs/public_html;
>             fastcgi_pass   127.0.0.1:9000;
>             fastcgi_index  index.php;
>             fastcgi_param  SCRIPT_FILENAME
>  $document_root$fastcgi_script_name;
>             include        fastcgi_params;
>         }

> when I open "localhost/index.php", I can see the php page, however, in the
> logs/error.log I see these
>
> 2020/03/16 21:34:22 [error] 5821#0: *2 FastCGI sent in stderr: "PHP
> message: PHP Warning:  session_start() [<a
> href='function.session-start'>function.session-start</a>]:
> open(/tmp/http_sessions/sess_dd0e14b5b3f5aebcb53015b6bebc3bfa, O_RDWR)
> failed: No such file or directory (2) in
> /home/ubuntu/htdocs/public_html/index.php on line 26

That's a PHP thing -- perhaps make the directories, or perhaps configure
your PHP to use a different directory. PHP documentation should indicate
how.

> Also I see somethings like
>
> 2020/03/16 21:34:22 [error] 5821#0: *2 open()
> "/home/ubuntu/htdocs/js/dragdrop.js" failed (2: No such file or directory),
> client: 127.0.0.1, server: localhost, request: "GET /js/dragdrop.js
> HTTP/1.1", host: "localhost", referrer: "http://localhost/index.php"
>
>
> I don't know why it is using "/home/ubuntu/htdocs/js/dragdrop.js"?
> According to the setting, it should look for it at
> "/home/ubuntu/htdocs/public_html/js/dragdrop.js" where the file actually
> exists.

The config you showed only uses /home/ubuntu/htdocs/public_html as the
document root for requests that end in .php.

The request /js/dragdrop.js is not handled in this location. The
configuration in, or inherited into, the location that handles
that request is the one that matters. And that, presumably, has
/home/ubuntu/htdocs as the configured document root.

Possibly setting "root /home/ubuntu/htdocs/public_html;" at server{}
level will cause things to work for you.

Cheers,

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx