0

So I tried following this guide, but seems to fail at this step. When accessing the /index.php my browser(both chromium and firefox) downloaded the page as a file, then I decided to delete the file from sites-available and begin from the default file again, now it doesnt download the site but just shows a plain white site with no source code.

I am pretty sure its just me who screwed something up in the code. Here is my nginx conf from sites-available:

# Default server configuration
#
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /data/randomsite10101.org/www;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.php index.nginx-debian.html;

    server_name randomsite10101.org.local randomsite10101.org;
    error_log /data/randomsite10101.org/logs/error.log error;
    access_log /data/randomsite10101.org/logs/access.log;


    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    location ~ [^/].php(/|$) {
    fastcgi_split_path_info ^(.+?.php)(/.*)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    }
}

New config:

# Default server configuration
#
server {
    listen 80 default_server;
    #listen [::]:80 default_server;
    error_log /data/randomsite10101.org/logs/error.log error;
    access_log /data/randomsite10101.org/logs/access.log;

    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;

    root /data/randomsite10101.com/www;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;

    server_name randomsite10101.org;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #   include snippets/fastcgi-php.conf;
    #
    #   # With php5-cgi alone:
    #   fastcgi_pass 127.0.0.1:9000;
    #   # With php5-fpm:
    #   fastcgi_pass unix:/var/run/php5-fpm.sock;
    #}
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+?.php)(/.*)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }   


    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #   deny all;
    #}

    listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/randomsite10101.org/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/randomsite10101.org/privkey.pem; # managed by Certbot
ssl_session_cache shared:le_nginx_SSL:1m; # managed by Certbot
ssl_session_timeout 1440m; # managed by Certbot

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # managed by Certbot
ssl_prefer_server_ciphers on; # managed by Certbot

ssl_ciphers "ECDHE-ECDSA-AES128-GCM-SHA256 ECDHE-ECDSA-AES256-GCM-SHA384 ECDHE-ECDSA-AES128-SHA ECDHE-ECDSA-AES256-SHA ECDHE-ECDSA-AES128-SHA256 ECDHE-ECDSA-AES256-SHA384 ECDHE-RSA-AES128-GCM-SHA256 ECDHE-RSA-AES256-GCM-SHA384 ECDHE-RSA-AES128-SHA ECDHE-RSA-AES128-SHA256 ECDHE-RSA-AES256-SHA384 DHE-RSA-AES128-GCM-SHA256 DHE-RSA-AES256-GCM-SHA384 DHE-RSA-AES128-SHA DHE-RSA-AES256-SHA DHE-RSA-AES128-SHA256 DHE-RSA-AES256-SHA256 EDH-RSA-DES-CBC3-SHA"; # managed by Certbot



    if ($scheme != "https") {
        return 301 https://$host$request_uri;
    } # managed by Certbot

}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#   listen 80;
#   listen [::]:80;
#
#   server_name example.com;
#
#   root /var/www/example.com;
#   index index.html;
#
#   location / {
#       try_files $uri $uri/ =404;
#   }
#}

David Cullen asked me for the output from ls -hl /data/sitename.com/www/:

-rw-r--r-- 1 www-data www-data  8 Jan  9 04:10 index.html
-rw-r--r-- 1 root     root     21 Jan  9 04:20 index.php

Then I tried to chown the folder to www-data with following command:

$ sudo chown -R www-data:www-data /data/randomsite.com/www/

And my output is now:

-rw-r--r-- 1 www-data www-data  8 Jan  9 04:10 index.html
-rw-r--r-- 1 www-data www-data 21 Jan  9 04:20 index.php

But it's still not working.

David asked me to remove the index.html, and with only index.php it still shows an empty page.

He asked me to comment some line out aswell and edit my index.php file, both tings done and still empty page.

  • 1
    Your code belongs in your question not on a third party site. This is designed to prevent link rot. Please edit your question and include your code. – Steve Robillard Jan 9 '17 at 4:26
  • I really tried doing that. But some code kept staying below and over the table. Here is an extra link to the config from github: gist.github.com/anonymous/d8b275379cd54e43e35c9977896f1aac – Hal9k Jan 9 '17 at 4:34
0

Try changing your index.php to look like this:

<html>
  <body>
    <?php
      phpinfo();
    ?>
  <body>
<html>

Apparently, the <html> and <body> tags are important. I got the idea from this Stack Overflow answer.

Also, I had to comment out the line

# listen [::]:80 default_server;

I was getting the following error message:

nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol)
nginx: configuration file /etc/nginx/nginx.conf test failed

I don't have IPv6 enabled on the network interface on the Raspberry Pi I am using.

Original Answer

Try simplifying your PHP location match to

location ~ \.php$

Also, make sure you have php5 and php5-fpm installed:

$ dpkg --get-selections | grep php

If you see php-fpm instead of php5-fpm, you probably have php7 installed. If you have php7 installed, you will need to change your location stanza:

    location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }
| improve this answer | |
  • Thank you very much for trying to help. I have php5 installed, gets no errors when restarting nginx anymore. I tried to edit the location line to what you suggested, but still shows an empty webpage, according to the guide it should output a pile of information about my php config due to the index.php site with following content:"<?php phpinfo(); ?>" – Hal9k Jan 9 '17 at 21:55
  • What is the output of ls -hl /data/randomsite10101.org/www? Put the output in your question, not in a comment. – David Cullen Jan 9 '17 at 22:01
  • Done. Should I edit my nginx config file in the question aswell? Atm. It's simply location ~ \.php$ And I checked for php version, I got php5-fpm installed along with alot other php5. – Hal9k Jan 9 '17 at 22:11
  • I added my new config, since i added lets encrypt certificates and your location string instead of the original. Furthermore i noticed that in the new config file root is /var/www/html; where it was /data/randomsite/www before. I tested if the /data/randomsite10101/www worked, It didnt. – Hal9k Jan 9 '17 at 22:40
  • I recommend using the simple nginx configuration until you get phpinfo working. I have updated my answer. I was wrong about index.html. – David Cullen Jan 9 '17 at 22:54
0

This answer helped me and resolved it.

I replaced

include fastcgi_params;

with

include fastcgi.conf;

And restarted php with

sudo service php5-fpm restart

and nginx with

sudo nginx -s reload

Last command helped me alot during all the edits, because it's outputting the error and eventually linenumber.

Thank you very much for trying to help me David.

| improve this answer | |
  • Don't forget to accept your answer. – David Cullen Jan 10 '17 at 4:10
  • Please accept your own answer with a click on the tick on its left side. Only this will finish the question and it will not pop up again year for year. – Ingo Apr 18 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.