PHP Sub Files Not Showing up!

June 5, 2017 1k views
Nginx Block Storage Ubuntu 16.04

Hey!

So this post is mostly releated To my other post which was answered by 2 friends.

Now I have problems my the php files in the subcategory like dashboard.php not showing up.

I really need help as my main file index.php is working except the other files like dashboard.php, login.php, etc not showing up.

You can refer to my old post:-
https://www.digitalocean.com/community/questions/nginx-not-showing-php-files?answer=36315

Thanks/
Kind regards,
/shar

4 Answers

@sharletsings123

Are you seeing any errors, such as a 404? Please run:

tail -20 /var/log/nginx/error.log

We can take a look at the error log and see if there's anything useful that we can gather.

Beyond the error log, you need to make sure all files and directories are owned by the user + group that the PHP-FPM process is running as. Generally that's www-data unless you've changed the pool file.

  • Sorry for the late reply as I had school and tests going on.

    I have executed the command as you have asked me and I have the message given to me by the system.

    2017/06/07 06:49:30 [error] 12987#12987: *115 dir
    ectory index of "/var/www/html/" is forbidden, cl
    ient: 209.126.136.4, server: _, request: "GET / H
    TTP/1.1", host: "192.81.208.50"                  
    2017/06/07 07:08:30 [error] 12987#12987: *121 dir
    ectory index of "/var/www/html/" is forbidden, cl
    ient: 54.255.154.231, server: _, request: "GET / 
    HTTP/1.1", host: "192.81.208.50"                 
    2017/06/07 07:18:06 [error] 12987#12987: *122 dir
    ectory index of "/var/www/html/" is forbidden, cl
    ient: 91.230.47.3, server: _, request: "GET / HTT
    P/1.0"                                           
    2017/06/07 09:54:47 [error] 12987#12987: *146 dir
    ectory index of "/var/www/html/" is forbidden, cl
    ient: 91.230.47.3, server: _, request: "GET / HTT
    P/1.0"                                           
    2017/06/07 10:56:06 [error] 12987#12987: *147 dir
    ectory index of "/var/www/html/" is forbidden, cl
    ient: 91.230.47.3, server: _, request: "GET / HTT
    P/1.0"                                           
    2017/06/07 12:44:59 [error] 12987#12987: *160 dir
    ectory index of "/var/www/html/" is forbidden, cl
    ient: 54.169.252.211, server: _, request: "GET / 
    HTTP/1.1", host: "192.81.208.50"                 
    2017/06/07 13:17:17 [error] 12987#12987: *172 dir
    ectory index of "/var/www/html/" is forbidden, cl
    ient: 91.230.47.3, server: _, request: "GET / HTT
    P/1.0"                                           
    2017/06/07 14:19:12 [error] 12987#12987: *220 dir
    ectory index of "/var/www/html/" is forbidden, cl
    ient: 91.230.47.3, server: _, request: "GET / HTT
    P/1.0"                                           
    2017/06/07 16:52:47 [error] 12987#12987: *259 dir
    ectory index of "/var/www/html/" is forbidden, cl
    ient: 91.230.47.3, server: _, request: "GET / HTT
    P/1.0"                                           
    

    Before I had another error and it had said that I had done something with the code files of the dashboard.php but now it talks about /var/www/html.

    • @sharletsings123

      On NGINX, this error:

      directory index of "/var/www/html/" is forbidden
      

      generally means that your server block or main config file doesn't define an index.

      You need to add:

      index index.php index.html;
      

      to your server block, or to your main NGINX configuration file, and then restart NGINX.

      Once that's fixed, and NGINX has been restarted, try accessing your files again and then do another tail on the error log.

      tail -20 /var/log/nginx/error.log
      
      • Hmm I want to see what errors occur in /var/www/panel.lolol.com, but It shows me /var/www/html which has nothing. And it is redirecting the public to another directory which is fine with me. Anyway to know the errors of panel.Lol.com rather than
        tail -20 /var/log/nginx/error.log as it give me the data for all.

        • @sharletsings123

          Unless you setup logging in the server block for each domain, all of the errors that are globally logged to that one file.

          In the server block for the domain (between server { }), you can add:

          error_log /var/log/nginx/domain.error.log;
          

          Change domain in the above and then restart NGINX and a new error log will be generated for that domain.

          Once NGINX has restarted, you'd simply try to visit the real domain and than you'd be able to run the same tail -20 command on that file instead of the main one.

          You can add the error_log directive to each domain server block, just change the name of the file. That's the best way to separate the logs and also prevent one file from being excessively large.

          Once you have some data logged to that file, you can post that here and we can take a closer look and see if there's something more going on.

          • Ok nice! I tried it and fantastic your awesome :)

            So, to the thing. I had got the error log....

            2017/06/08 10:14:54 [error] 6237#6237: *12 FastCG
            I sent in stderr: "PHP message: PHP Parse error: 
             syntax error, unexpected '" disabled>' (T_CONSTA
            NT_ENCAPSED_STRING), expecting ',' or ';' in /var
            /www/panel.cobrahost.tk/html/dashboard.php on lin
            e 80" while reading response header from upstream
            , client: 37.224.228.128, server: panel.cobrahost
            .tk, request: "GET /dashboard.php HTTP/1.1", upst
            ream: "fastcgi://unix:/run/php/php7.1-fpm.sock:",
             host: "panel.cobrahost.tk"                      
            2017/06/08 10:14:58 [error] 6237#6237: *15 FastCG
            I sent in stderr: "PHP message: PHP Parse error: 
             syntax error, unexpected '" disabled>' (T_CONSTA
            NT_ENCAPSED_STRING), expecting ',' or ';' in /var
            /www/panel.cobrahost.tk/html/dashboard.php on lin
            e 80" while reading response header from upstream
            , client: 66.249.93.63, server: panel.cobrahost.t
            k, request: "GET /dashboard.php HTTP/1.1", upstre
            am: "fastcgi://unix:/run/php/php7.1-fpm.sock:", h
            ost: "panel.cobrahost.tk"                        
            2017/06/08 10:15:00 [error] 6237#6237: *12 FastCG
            I sent in stderr: "PHP message: PHP Parse error: 
             syntax error, unexpected '" disabled>' (T_CONSTA
            NT_ENCAPSED_STRING), expecting ',' or ';' in /var
            /www/panel.cobrahost.tk/html/dashboard.php on lin
            e 80" while reading response header from upstream
            , client: 37.224.228.128, server: panel.cobrahost
            .tk, request: "GET /dashboard.php HTTP/1.1", upst
            ream: "fastcgi://unix:/run/php/php7.1-fpm.sock:",
             host: "panel.cobrahost.tk"                      
            

            Now, After reading the following log ^, I believe that it has to do with my coding....Lol.

            I have used the code which causes error in 2 placed and I is these...

            The normal input method
            <input class="inputA" type="text" value="<?php echo $UserName ?>" disabled>

            And

            I have added it with an if thingy.....
            if($Status == "Online") { echo "<input type='text' class='inputA' value='Online' disabled>";
            } else { echo "<input type='text' class='inputA' value='Offline' disabled>"; }

            The error happend at the place of code :80 so above it is the 1st code on top ^^ and after 80 is the second on the bottom.

@sharletsings123

Looking a the snippet you've provided, it should work, so if you're still seeing an error, then the issue may be elsewhere. Would you be able to post the complete contents of the file in a code block?

You can use the </> icon and place the code between the backticks.

Have another answer? Share your knowledge.