PHP-FPM sends empty response from Nginx on macOS

I installed nginx 1.10.3 and php 5.5.38 as development server on macOS 10.12.4

When I try to check the php file in my browser, the body is empty, but the response headers look fine:

HTTP/1.1 200 OK Server: nginx/1.10.3 Date: Wed, 29 Mar 2017 11:35:21 GMT Content-Type: text/html Transfer-Encoding: chunked Connection: keep-alive X-Powered-By: PHP/5.5.38

No errors in php-fpm.log or nginx / error.log

my nginx.conf has:

 server { listen 80; server_name wordpress.bob; root /Users/mark/Sites/wordpress; include /usr/local/etc/nginx/global_restrictions.conf; include /usr/local/etc/nginx/wordpress.conf; location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/usr/local/var/run/php-www.sock; fastcgi_index index.php; include fastcgi_params; } } 

wordpress.bob is the local host name for testing, pointing to 127.0.0.1 in etc / hosts

php-fpm.conf has:

 listen = '/usr/local/var/run/php-www.sock' 

Any ideas what I'm doing wrong?

+5
source share
2 answers

It is difficult to help without the ability to read all configuration files.

You just placed one, not included or php-fpm.conf. This is not disapproval (the wall of configuration files is not entirely appropriate in the question), but simply to indicate that the configuration file that we "don’t see" may differ depending on the installation.

In any case, I see some differences from the configuration file that I have on the server for the wordpress site.

Here are some tips to consider that since you are not getting any php-fpm errors , and nginx can "communicate" with it through a socket (otherwise you will get a bad gateway error).


At the beginning...

 server { listen 80; server_name wordpress.bob; root /Users/mark/Sites/wordpress; index index.php; # <-- ADD THIS 

Make sure you have wordpress.conf enabled

 location / { try_files $uri $uri/ /index.php?$args; } 

The last part...

 location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_buffer_size 128k; fastcgi_buffers 256 16k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 512k; fastcgi_intercept_errors on; fastcgi_max_temp_file_size 0; fastcgi_connect_timeout 3s; fastcgi_send_timeout 5s; fastcgi_read_timeout 5s; include fastcgi.conf; # <--- fastcgi.conf, NOT fastcgi_params fastcgi_pass /usr/local/var/run/php-www.sock; } 

The difference between fastcgi.conf and fastcgi_params (during my installation) is only one line:

 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 

If this line is missing, php code cannot read $_SERVER['SCRIPT_FILENAME'] and (I think), it can break Wordpress code, which will lead to empty conclusions.


Finally, make sure php-fpm workflows have /usr/local/var/run/php-www.sock permissions

Usually the socket has the same owner: a group of workers.

The user and group of workers are installed in php-fpm.conf:

 ; Unix user/group of processes ; Note: The user is mandatory. If the group is not set, the default user group ; will be used. user = ...... group = ...... 
+4
source

To install NGINX with Homebrew:

 $ brew install nginx 

Launch NGINX:

 $ sudo nginx 

Check localhost nginx:

 http://localhost:8080 

The NGINX configuration file must be located in:

 $ /usr/local/etc/nginx/nginx.conf 

If you want to change the default port:

 $ sudo nginx -s stop $ vim /usr/local/etc/nginx/nginx.conf 

Change: listen 8080; To: listen 80;

To save and configure and start NGINX startup:

 $ sudo nginx 

Then, according to your problem, you can simply specify an empty PHP file. Try printing phpinfo () and then search for "DOCUMENT_ROOT" to see where it goes.

+1
source

Source: https://habr.com/ru/post/1266072/


All Articles