Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

nginx, php and localhost Ubuntu 13.04

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Help!
View previous topic :: View next topic  
Author Message
duff



Joined: Tue Oct 11, 2005 12:50 pm
Posts: 47

PostPosted: Wed Sep 11, 2013 4:34 pm    Post subject: nginx, php and localhost Ubuntu 13.04 Reply with quote

Hi Everyone

Long time since I posted here.

I'm having a problem with nginx and php on ubuntu 13.04.

I'm very new to web development and php. I want to be able to read a text file (tab or comma sep) on the server using php and pass the resulting array to js for further client side processing.

In order to get nginx to play with php Google tells me I have to install php5-fpm and set this up. So I have followed a couple of web tutorials (tell you more or less the same thing) but the setup isn't working.

Relevant configurations are (note I've left out a load of stuff that's commented out in these files):

Nginx default file
Code:

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

   # Make site accessible from http://localhost/
   server_name localhost;

      root /usr/share/nginx/html;
      index index.php index.html index.htm;

   location / {
      # First attempt to serve request as file, then
      # as directory, then fall back to displaying a 404.
      try_files $uri $uri/ /index.html;
      # Uncomment to enable naxsi on this location
      # include /etc/nginx/naxsi.rules
   }

   location /doc/ {
      alias /usr/share/doc/;
      autoindex on;
      allow 127.0.0.1;
      allow ::1;
      deny all;
   }

   # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
   #
   location ~ \.php$ {
      try_files $uri=404;
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
   #   # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
   #
   #   # With php5-cgi alone:
   #   fastcgi_pass 127.0.0.1:9000;
   #   # With php5-fpm:
      fastcgi_pass unix:/var/run/php5-fpm.sock;
      fastcgi_index index.php;
      include fastcgi_params;
   }

}



In the
Code:
/etc/php5/fpm/php.ini
file I uncommented and changed the line
Code:
cgi.fix_pathinfo=1
to
Code:
cgi.fix_pathinfo=0;
(as per above)

I created a test file:

Code:
cd /usr/share/nginx/html
sudo su
echo '<?php phpinfo(); ?>' > info.php

and this is fine

Both nginx and php5-fpm were restarted.

Browsing to
Code:
http://localhost
let's me see the nginx default page (so I know nginx is working) but
Code:
http://localhost/info.php
does not display the page but only asks if I want to download the info.php file.

Can anyone help with this? I'd like to get nginx and php to play nice on my local machine so I can get the hang of server side programming.

Best

duff
Back to top
View user's profile Send private message
leke
LXF regular


Joined: Mon Oct 22, 2007 6:45 pm
Posts: 500
Location: Oulu, Finland

PostPosted: Wed Sep 11, 2013 6:22 pm    Post subject: Reply with quote

I would be interested to see the output of...
ls -l /usr/share/nginx/html
_________________
I codes here: http://notsure.cz.cc/
Back to top
View user's profile Send private message
duff



Joined: Tue Oct 11, 2005 12:50 pm
Posts: 47

PostPosted: Wed Sep 11, 2013 10:43 pm    Post subject: Reply with quote

Hi leke
Code:

total 12
-rw-r--r-- 1 root root 537 Sep 24  2012 50x.html
-rw-r--r-- 1 root root 612 Sep 24  2012 index.html
-rw-r--r-- 1 root root  20 Sep 11 17:59 info.php


Following another post from someone using Arch Linux I removed nginx, nginx-common, nginx-full, php5-common, php5-fmp and php5-cli. Reinstalled nginx, nginx-common, nginx-full, php5-common and php5-fmp. Now I can display the info.php page as it should be.

But if I try my own code in html it doesn't display properly. For example:
Code:

<!DOCTYPE html>
<html>
   <head>
      <title>Example.com test</title>
   </head>

   <body>
      <p>Success with the virtual server</p>
   <?php
          echo "<p>php says hi</p>";
   ?>
   </body>
</html>


displays as:
Code:

Success with the virtual server
php says hi

"; ?>


i.e. the trailing "; ?> are shown on the page.

So that's strange and annoying enough. If I save the index page as index.php instead of index.html and point my browser at the localhost site (http://locahost:8080) it tries to download the file rather than displaying it.

Thanks for any help/advice.

Best

duff
Back to top
View user's profile Send private message
leke
LXF regular


Joined: Mon Oct 22, 2007 6:45 pm
Posts: 500
Location: Oulu, Finland

PostPosted: Thu Sep 12, 2013 5:01 am    Post subject: Reply with quote

Interesting, I've never seen anything like that before, but then I've never used Nginx Razz
Does the error log report anything?
_________________
I codes here: http://notsure.cz.cc/
Back to top
View user's profile Send private message
duff



Joined: Tue Oct 11, 2005 12:50 pm
Posts: 47

PostPosted: Thu Sep 12, 2013 11:14 am    Post subject: Reply with quote

Hi leke

Tracked the problem down to a misconfigured virtual hosts file for the example site. I'd accidentally included a closing curly bracket where there shouldn't have been one.

i.e.

Code:

server {
   listen 8080;
   listen [::]:8080 default_server ipv6only=on;
   root /var/www/example.com/public_html;
   index index.php index.html index.htm;

   # Make site accessible from http://localhost/
   server_name localhost; # since I'm only testing here

} # THIS SHOULD NOT BE HERE

   # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
   #
   location ~ \.php$ {
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
   #   # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
   #
   #   # With php5-cgi alone:
   #   fastcgi_pass 127.0.0.1:9000;
   #   # With php5-fpm:
      fastcgi_pass unix:/var/run/php5-fpm.sock;
      fastcgi_index index.php;
      include fastcgi_params;
   }

} # THIS IS THE REAL CLOSING BRACKET


Thanks for your input.

Best

Iain
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Help! All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast