Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 26922  / 1 Year ago, mon, may 29, 2023, 1:15:17

before anything i searched everywhere and tested everything
but still not working
i install php5-fpm and nginx
when i open localhost in browser i see this page :



Welcome to nginx!



so its working now configuring php5-fpm with nginx :



/etc/php5/fpm/pool.d/www.conf



  user = www-data
group = www-data
listen = /var/run/php5-fpm.sock
listen.owner = www-data
listen.group = www-data
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
chdir = /


all other lines are commented and this is the nginx conf :



  upstream php {
server unix:/var/run/php5-fpm.socket;
}

server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html;
index index.html index.htm index.php;

# Make site accessible from http://localhost/
server_name localhost;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}

# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
#location /RequestDenied {
# proxy_pass http://127.0.0.1:8080;
#}

#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;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;

}

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


the problem is when i try to run php files nginx will download php file instead of executing it


More From » php

 Answers
7

PHP-FPM socket permissions



Please check that the socket has proper permissions.



$ ll /var/run/php5-fpm.sock
srw-rw---- 1 www-data www-data 0 Aug 6 14:16 /var/run/php5-fpm.sock=


Probably add listen.mode = 0660 to your www.conf if the output is different.



Possibly related: nginx error connect to php5-fpm.sock failed (13: Permission denied)



nginx configuration




  1. Is this really where your files are?



    root /usr/share/nginx/html;
    index index.html index.htm index.php;

  2. What is this block supposed to do?



      upstream php {
    server unix:/var/run/php5-fpm.socket;
    }

  3. I'd suggest removing try_files $uri =404; from the location ~ .php$ block.


  4. Why is the indentation of the lines in 2 and 3 different from the rest? Note that it would affect a proper configuration, but this leaves the impression that they have been carelessly pasted together. Please provide a link to the instructions you used.



[#23822] Wednesday, May 31, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ndaavi

Total Points: 169
Total Questions: 116
Total Answers: 113

Location: Falkland Islands
Member since Wed, Dec 23, 2020
3 Years ago
;