1

I would like to set up a small nginx server on my pi. So far, html and php5 are working, but if I make a mixing, lets say:

<p>It is <?php echo time();?> UTC </p>

It would show me:

It is UTC

But if I put a index.php in root with echo phpinfo(); (index.php comes before index.html) I got no error at all.

I followed this tutorial:

Is there anything else to install in order to use mixings? I installed Rasbian as OS. I am definitely not a pro, any help will be very appreciated.

tomtom
  • 99
  • 1
  • 1
  • 10
  • 4
    Has your file the `php` extension ? Because without special rules most servers wont execute PHP in files with the `html` extension. – LJᛃ Nov 12 '14 at 01:17
  • Post your `nginx.conf` and your `default` config, and whatever else nginx may be loading... – rm-vanda Nov 12 '14 at 01:32
  • first of you show us the page code where you echoing the time(), secondly if you have a separate connection file then use it at the top of the query in the specified page, so it would work properly..... –  Nov 12 '14 at 02:24
  • 1
    Sounds like your file is not .php but .html? Should be .php at the end if you use php in it. – Bolli Nov 12 '14 at 03:12
  • Thank you folks for your efforts. LJ_1102 and Bolli solved it, I just had to change the file extension to .php . I wasn't aware of that, so far it always worked when I needed it ;) What would be the special rules @LJ_1102 mentioned? I mean to make it work in a html file? – tomtom Nov 12 '14 at 14:11
  • The [this post](http://stackoverflow.com/questions/8644783/html-files-as-php-in-nginx) on how to override file extension settings. – LJᛃ Nov 12 '14 at 14:41

2 Answers2

0

Some versions of PHP are not compatible with certain versions of web servers, at least in Apache. I have next to zero experience in nginx, but if I'm not mistaken it's more commonly used for CGI, being event-based and not process-based. CGI still has it's place for some things, but I've found using MySQL more secure, and MSSQL more secure still.

On that note, you might prefer installing Apache over nginx, unless you have specific reason otherwise: I'm not sure how well developed nginx is on the RasPi, but I know many people use Apache to run web servers on it. If you're sure about using nginx, make sure there's no errors when you run the line from that page [sudo apt-get install php5-fpm].

Your issue itself seems that the PHP is not parsing. HTML will process and HTML between carrots (< and >), and not show that output to the user. However, unless PHP is working, it still is visible if you view source. To make sure PHP is installed, view the page source and see if you can see that php code. If you can, PHP isn't installed or working. If it doesn't show up, there's likely a problem with the compatibility of the server. Also, some PHP code ends up deprecated on newer versions, while some instructions are new. Make sure your issue is you're using correct code/syntax for your installed PHP version.

Lastly, but possibly most importantly: Make sure you're following the "TEST THE WEB SERVER" of your tutorial properly, and visit it from ANOTHER computer. If you try from the same IP address, it can result in loopback, where PHP won't parse for the same IP address as the source.

I also found this resource that might lead you in the right direction. https://serverfault.com/questions/593677/php-file-are-not-parsed-by-fastcgi-in-nginx

I know this is a long answer, but it's a good way to troubleshoot with logic and understanding of how it works.

Community
  • 1
  • 1
Reidmere
  • 76
  • 1
  • 9
  • 1
    Hi, thank you for your long ;) answer. Like you mentioned in your 3rd paragraph, I can see the php in the source code. Any Idea to parse php in html correctly? – tomtom Nov 12 '14 at 14:16
  • I'm sorry I didn't see your comment earlier. If your file ends in .php and you enabled PHP in nginx (shown on the link you gave), your best bet is to go with the LAMP combination, Linux Apache MySql PHP. This article can tell you what to do nicely, but you might want to do this on a clean install of Raspbian: something may be missing or not working properly on it right now. – Reidmere Dec 07 '14 at 09:25
0

What is the extension of the file .php or .html ? It should be of type .php when you are using Php script in a file with html ie your file should be saved with extension .php.

Sunil Goli
  • 449
  • 4
  • 11
  • Hi, Yes you are right, thats one way to solve it. Thank you for your efforts, thats already solved (see the comments). Netherless I understood it is also possible to use php in files ending with .htm or .html . If so, can you guys point me in the right direction, so I know what I have to search for? – tomtom Nov 12 '14 at 22:20