Я пытаюсь настроить сервер WordPress, но перед этим мне нужно, чтобы PHP работал. В настоящее время я установил и настроил nginx и php 7.3, но php не рендерит, он просто показывает текст.
Основной выпуск:
[root@a-knapsack-sav ~]# cat /usr/share/nginx/html/info.php
<?php
phpinfo();
?>
[root@a-knapsack-sav ~]# curl http://localhost/info.php
<?php
phpinfo();
?>
Очевидно, я должен ожидать увидеть что-то из вышеперечисленного, но это не так. Ниже приведены все настройки, которые я сделал. Надеюсь, кто-нибудь увидит это и укажет на мое вероятное упущение.
Какую ОС вы используете?
[root@a-knapsack-sav nginx]# rpm -q centos-release
centos-release-7-6.1810.2.el7.centos.x86_64
Установлен ли даже nginx?
[root@a-knapsack-sav nginx]# nginx -v
nginx version: nginx/1.15.12
Установлен ли php?
[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
Где установлен nginx?
[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
php-fpm даже работает?
[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
Работает ли nginx?
[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
Вы редактировали свой php.ini?
Только cgi.fix_pathinfo
для безопасности.
[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
Обновили ли вы настройки php для conf для nginx?
Я так думаю.
[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
Правильно ли вы обновили настройку nginx?
Насколько я знаю ....
[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;
# }
}
У вас есть файл info.php в правильном месте?
Yezzir.
[root@a-knapsack-sav ~]# ls /usr/share/nginx/html
50x.html index.html info.php
А как насчет вашего 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;
}
А как насчет ваших сайтов, доступных конф?
Я не знаю, нужно ли это, но я всегда пробовал.
[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;
# }
}
Вы забыли связать сайты с включенными и доступными сайтами?
Нету:)
[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
Надеюсь, это все. Я думаю, что это все, что я сделал. Index.html загружается, когда я curl http://localhost
, но, как показано выше, info.php не отображается при вызове. Я думаю, я настроил это почти правильно, но я почти уверен, что что-то пропустил. Пожалуйста, дайте мне знать, если что-то не так. Я пытался следовать https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7 (mysql находится на другом сервере). Также, если есть какая-либо конфигурация, которую мне нужно изменить, чтобы curl http://A.B.C.D
не зависал и возвращался как curl http://localhost
, я был бы признателен. Спасибо:)
Edit:
Какой у вас весь конфиг?
[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;
# }
}