dongshen7407 2019-05-03 23:23 采纳率: 0%
浏览 481
已采纳

为什么我的php没有呈现? 为什么我的php页面空白?

I'm trying to setup a wordpress server, but before that I need to get PHP working. Currently I have installed and configured nginx and php 7.3, but the php is not rendering, it is just showing text.

Main Issue:

[root@a-knapsack-sav ~]# cat /usr/share/nginx/html/info.php
<?php
phpinfo();
?>
[root@a-knapsack-sav ~]# curl http://localhost/info.php
<?php
phpinfo();
?>

Obviously I should expect to see some content from the above, but I'm not. The following is all of the setup that I've done. Hopefully someone can see this and point out my likely omission.

What OS are you using?

[root@a-knapsack-sav nginx]# rpm -q centos-release
centos-release-7-6.1810.2.el7.centos.x86_64

Is nginx even installed?

[root@a-knapsack-sav nginx]# nginx -v
nginx version: nginx/1.15.12

Is php even installed?

[root@a-knapsack-sav nginx]# php -v
PHP 7.3.5 (cli) (built: Apr 30 2019 08:37:17) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.5, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.5, Copyright (c) 1999-2018, by Zend Technologies

Where is nginx installed?

[root@a-knapsack-sav nginx]# pwd
/etc/nginx
[root@a-knapsack-sav nginx]# ls
conf.d  fastcgi_params  koi-utf  koi-win  mime.types  modules  nginx.conf  scgi_params  sites-available  sites-enabled  uwsgi_params  win-utf

Is php-fpm even running?

[root@a-knapsack-sav nginx]# systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2019-05-03 10:42:25 CDT; 7h ago
 Main PID: 2772 (php-fpm)
   Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec"
   CGroup: /system.slice/php-fpm.service
           ├─2772 php-fpm: master process (/etc/php-fpm.conf)
           ├─2773 php-fpm: pool www
           ├─2774 php-fpm: pool www
           ├─2775 php-fpm: pool www
           ├─2776 php-fpm: pool www
           └─2777 php-fpm: pool www

Is nginx even running?

[root@a-knapsack-sav nginx]# systemctl status nginx
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2019-05-03 17:19:55 CDT; 31min ago
     Docs: http://nginx.org/en/docs/
  Process: 4299 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
  Process: 4302 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
 Main PID: 4303 (nginx)
   CGroup: /system.slice/nginx.service
           ├─4303 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
           └─4304 nginx: worker process

Did you edit you php.ini? Only the cgi.fix_pathinfo for security.

[root@a-knapsack-sav nginx]# cat /etc/php.ini | grep cgi.fix
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's
; http://php.net/cgi.fix-pathinfo
cgi.fix_pathinfo=0

Did you update php's conf settings to for nginx?
I think so.

[root@a-knapsack-sav ~]# cat /etc/php-fpm.d/www.conf | grep listen
; - 'listen' (unixsocket)
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific IPv4 address on
;   '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
;   'port'                 - to listen on a TCP socket to all addresses
;   '/path/to/unix/socket' - to listen on a unix socket.
listen = /var/run/php-fpm/php-fpm.sock
; Set listen(2) backlog.
;listen.backlog = 511
listen.owner = nobody
listen.group = nobody
;listen.mode = 0660
; When set, listen.owner and listen.group are ignored
;listen.acl_users = apache,nginx
;listen.acl_groups =
; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
listen.allowed_clients = 127.0.0.1
;   listen queue         - the number of request in the queue of pending
;                          connections (see backlog in listen(2));
;   max listen queue     - the maximum number of requests in the queue
;   listen queue len     - the size of the socket queue of pending connections;
;   listen queue:         0
;   max listen queue:     1
;   listen queue len:     42
[root@a-knapsack-sav ~]# cat /etc/php-fpm.d/www.conf | grep nginx
user = nginx
group = nginx
;listen.acl_users = apache,nginx

Did you update nginx's conf properly? As far as I know to....

[root@a-knapsack-sav ~]# cat /etc/nginx/conf.d/default.conf
server {
    listen       80;
#   listen       [::]:80;
    server_name  A.B.C.D;
    root   /usr/share/nginx/html;
    index  index.php index.html index.htm;
    location / {
        try_files $uri $uri/ =404;
    }
    error_page   404 /404.html;
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    location ~* \.php$ {
         try_files $uri =404;
         fastcgi_index index.php;
         include fastcgi_params; 
         fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#        fastcgi_param SCRIPT_NAME     $fastcgi_script_name;
     }
#    location ~ /.ht {
#        deny  all;
#    }
}

Do you have your info.php file in the correct place?
Yezzir.

[root@a-knapsack-sav ~]# ls /usr/share/nginx/html
50x.html  index.html  info.php

What about your nginx.conf?

[root@a-knapsack-sav ~]# cat /etc/nginx/nginx.conf

    user  nginx;
    worker_processes  1;

    error_log  /var/log/nginx/error.log warn;
    pid        /var/run/nginx.pid;


    events {
        worker_connections  1024;
    }


    http {
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;

        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';

        access_log  /var/log/nginx/access.log  main;

        sendfile        on;
        #tcp_nopush     on;

        keepalive_timeout  65;

        #gzip  on;

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*.conf;
        server_names_hash_bucket_size 64;
    }

What about your sites-available conf? I don't know if this is needed but I tried it anways.

[root@a-knapsack-sav ~]# cat /etc/nginx/sites-available/default.conf
server {
    listen       80;
    server_name A.B.C.D;
    root   /usr/share/nginx/html;
    index  index.php index.html index.htm;
    location / {
        try_files $uri $uri/ =404;
    }
    error_page   404 /404.html;
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    location ~ .php$ {
        try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
     }
#    location ~ /.ht {
#        deny  all;
#    }
}

Did you forget to link sites-enabled and sites-available? Nope :)

[root@a-knapsack-sav ~]# ls -lrt /etc/nginx/sites-enabled
total 0
lrwxrwxrwx. 1 root root 39 May  3 12:40 default.conf -> /etc/nginx/sites-available/default.conf

I hope this is everything. I think this is everything I've done. The index.html loads when I curl http://localhost but as shown above the info.php is not rendered when called. I think, I've set this up almost correct, but I'm pretty sure I missed something. Please let me know if something seems off. I tried to follow https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7 (mysql is on another server). Also if there is any configuration that I need to change so that curl http://A.B.C.D doesn't hang and returns like curl http://localhost, I'd appreciate it. Thanks :)

Edit:

What is your entire config?

[root@a-knapsack-sav ~]# nginx -T
nginx: [warn] conflicting server name "A.B.C.D" on 0.0.0.0:80, ignored
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# configuration file /etc/nginx/nginx.conf:

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*.conf;
    server_names_hash_bucket_size 64;
}

# configuration file /etc/nginx/mime.types:

types {
    text/html                                        html htm shtml;
    text/css                                         css;
    text/xml                                         xml;
    image/gif                                        gif;
    image/jpeg                                       jpeg jpg;
    application/javascript                           js;
    application/atom+xml                             atom;
    application/rss+xml                              rss;

    text/mathml                                      mml;
    text/plain                                       txt;
    text/vnd.sun.j2me.app-descriptor                 jad;
    text/vnd.wap.wml                                 wml;
    text/x-component                                 htc;

    image/png                                        png;
    image/svg+xml                                    svg svgz;
    image/tiff                                       tif tiff;
    image/vnd.wap.wbmp                               wbmp;
    image/webp                                       webp;
    image/x-icon                                     ico;
    image/x-jng                                      jng;
    image/x-ms-bmp                                   bmp;

    font/woff                                        woff;
    font/woff2                                       woff2;

    application/java-archive                         jar war ear;
    application/json                                 json;
    application/mac-binhex40                         hqx;
    application/msword                               doc;
    application/pdf                                  pdf;
    application/postscript                           ps eps ai;
    application/rtf                                  rtf;
    application/vnd.apple.mpegurl                    m3u8;
    application/vnd.google-earth.kml+xml             kml;
    application/vnd.google-earth.kmz                 kmz;
    application/vnd.ms-excel                         xls;
    application/vnd.ms-fontobject                    eot;
    application/vnd.ms-powerpoint                    ppt;
    application/vnd.oasis.opendocument.graphics      odg;
    application/vnd.oasis.opendocument.presentation  odp;
    application/vnd.oasis.opendocument.spreadsheet   ods;
    application/vnd.oasis.opendocument.text          odt;
    application/vnd.openxmlformats-officedocument.presentationml.presentation
                                                     pptx;
    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
                                                     xlsx;
    application/vnd.openxmlformats-officedocument.wordprocessingml.document
                                                     docx;
    application/vnd.wap.wmlc                         wmlc;
    application/x-7z-compressed                      7z;
    application/x-cocoa                              cco;
    application/x-java-archive-diff                  jardiff;
    application/x-java-jnlp-file                     jnlp;
    application/x-makeself                           run;
    application/x-perl                               pl pm;
    application/x-pilot                              prc pdb;
    application/x-rar-compressed                     rar;
    application/x-redhat-package-manager             rpm;
    application/x-sea                                sea;
    application/x-shockwave-flash                    swf;
    application/x-stuffit                            sit;
    application/x-tcl                                tcl tk;
    application/x-x509-ca-cert                       der pem crt;
    application/x-xpinstall                          xpi;
    application/xhtml+xml                            xhtml;
    application/xspf+xml                             xspf;
    application/zip                                  zip;

    application/octet-stream                         bin exe dll;
    application/octet-stream                         deb;
    application/octet-stream                         dmg;
    application/octet-stream                         iso img;
    application/octet-stream                         msi msp msm;

    audio/midi                                       mid midi kar;
    audio/mpeg                                       mp3;
    audio/ogg                                        ogg;
    audio/x-m4a                                      m4a;
    audio/x-realaudio                                ra;

    video/3gpp                                       3gpp 3gp;
    video/mp2t                                       ts;
    video/mp4                                        mp4;
    video/mpeg                                       mpeg mpg;
    video/quicktime                                  mov;
    video/webm                                       webm;
    video/x-flv                                      flv;
    video/x-m4v                                      m4v;
    video/x-mng                                      mng;
    video/x-ms-asf                                   asx asf;
    video/x-ms-wmv                                   wmv;
    video/x-msvideo                                  avi;
}

# configuration file /etc/nginx/conf.d/default.conf:
server {
    listen       80;
#   listen       [::]:80;
    server_name  A.B.C.D;
    root   /usr/share/nginx/html;
    index  index.php index.html index.htm;
    location / {
        try_files $uri $uri/ =404;
    }
    error_page   404 /404.html;
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    location ~* \.php$ {
         try_files $uri =404;
         fastcgi_index index.php;
         include fastcgi_params; 
         fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#        fastcgi_param SCRIPT_NAME     $fastcgi_script_name;
     }
#    location ~ /.ht {
#        deny  all;
#    }
}

# configuration file /etc/nginx/fastcgi_params:

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REQUEST_SCHEME     $scheme;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

# configuration file /etc/nginx/conf.d/default_original.conf:
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

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


# configuration file /etc/nginx/sites-enabled/default.conf:
server {
    listen       80;
    server_name A.B.C.D;
    root   /usr/share/nginx/html;
    index  index.php index.html index.htm;
    location / {
        try_files $uri $uri/ =404;
    }
    error_page   404 /404.html;
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    location ~ .php$ {
        try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
     }
#    location ~ /.ht {
#        deny  all;
#    }
}
  • 写回答

1条回答 默认 最新

  • dongyu9667 2019-05-04 18:01
    关注

    Following Richard Smith's question, nginx -T showed that I had another conf active that was interfering with my config, /etc/nginx/conf.d/default_original.conf. So I did mv /etc/nginx/conf.d/default_original.conf /etc/nginx/conf.d/default.conf.original to get it to no longer load and I changed the include /etc/nginx/fastcgi_params; to include fastcgi_params; in /etc/nginx/sites-available/default.conf. After doing this I restarted nginx (systemctl restart nginx) and curl http://localhost return an expected output of html tables.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何使用SC92F8003固件库解析私有协议数据?
  • ¥15 如何在音频中嵌入字符串(水印)信息进行传递
  • ¥30 plc怎么以设计说明书申请软著
  • ¥15 硬盘识别不了,需要初始化,可我的数据怎么办
  • ¥15 lvm2被mask了,怎么unmask都没用(标签-ubuntu|关键词-apt)
  • ¥15 交叉注意力机制的残差问题
  • ¥15 微信小程序:渲染收货地址时页面不显示
  • ¥20 win7 64位DirectShow提示初始化失败如何解决?
  • ¥15 关于Java对接海康威视车牌识别一体机SDK是否需要固定外网的IP?
  • ¥15 Linux扩容时,格式化卡住了:vgdispaly查看卷组信息,没有输出