无法解释RHEL + nginx上的PHP

时间:2017-06-08 17:33:57

标签: php linux nginx

我正在执行以下步骤,似乎无法解释PHP。我做了很多变种,在网上广泛搜索并向朋友展示:我们不明白我们做错了什么。你能帮忙吗?

  1. 启动RHEL 7.3亚马逊免费套层实例
  2. 使用MAC终端应用程序连接SSH

    sudo yum install wget
    wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    sudo rpm -Uvh epel-release-latest-7*.rpm
    sudo yum install nginx
    sudo service nginx restart
  3. 在rehl实例入站规则中打开端口80

  4. 检查http://[my_instance_name].eu-central-1.compute.amazonaws.com/,它在Fedora页面上显示对nginx的欢迎

  5. 安装php并配置nginx

  6. sudo yum install php-fpm
    sudo yum install nano
    sudo nano /etc/php.ini, and in the file, set cgi.fix_pathinfo=0
    sudo nano /etc/nginx/nginx.conf, and set the worker processes to 4 (value was: auto)
    sudo nano /etc/nginx/conf.d/default.conf and have the following conf:
    
        server {
            listen       80;
            server_name localhost;
    
    
            location / {
                root   /usr/share/nginx/html;
                index index.php  index.html index.htm;
            }
    
            error_page  404              /404.html;
            location = /404.html {
                root   /usr/share/nginx/html;
            }
    
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   /usr/share/nginx/html;
            }
    
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            location ~ \.php$ {
                root           /usr/share/nginx/html;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
                include        fastcgi_params;
            }
        }
    
    1. 配置php
    2. sudo nano /etc/php-fpm.d/www.conf and confirm user and group are php-fpm
      sudo service php-fpm restart
      sudo nano /usr/share/nginx/html/info.php containing phpinfo(); (with the php tags, stackoverflow seems to hide it)
      sudo service nginx restart
      sudo chkconfig --levels 235 nginx on
      sudo chkconfig --levels 235 php-fpm on
      
      1. 浏览到http://[my_instance_name].eu-central-1.compute.amazonaws.com/info.php:它下载php文件而不是解释它

      2. 更改步骤/etc/php-fpm.d/www.conf并说用户和组是nginx,重启nginx,php文件仍然下载而不是解释

      3. 更改步骤/etc/nginx/conf.d/default.conf并说server_name = [我的实例的IP],重启nginx,php文件仍然下载而不是解释

      4. 我错过了什么?

2 个答案:

答案 0 :(得分:1)

首先检查/ var / log / nginx和/ var / log / php-fpm的日志

其次,使用php-fpm在端口9000上监听的netstat -lnp进行检查

第三,这是适用于我的nginx配置:

location ~ [^/]\.php(/|$) {
                fastcgi_split_path_info  ^(.+\.php)(/.*)$;
                try_files $uri =404;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param   PATH_INFO $fastcgi_path_info;
                include fastcgi_params;
    }

答案 1 :(得分:0)

您是否使用简短的php open标签<??如果是这样,请仔细检查php.ini中的short_open_tag是否已启用,因为在某些发行版中默认未启用它。

可能实际上是/ is /,但是PHP没有看到任何“ php代码”。