# Nginx + PHP-FPM can't run .php scripts



## soulreaver1 (Dec 5, 2011)

Hello,

First i'd like to thanks for all your (freebsd FreeBSD folks) recent valuable help. I've learned a lot already, but still is much to do. I've some problems with running Nginx + PHP-FPM. I can't run any .php scripts using a web browser. Instead of running index.php the web browser just downloads this script. 

PHP-FPM is started and listening on port 9000.

sockstat | grep 9000

```
www      php-fpm    8631  0  tcp4   127.0.0.1:9000        *:*
www      php-fpm    8630  0  tcp4   127.0.0.1:9000        *:*
www      php-fpm    8629  0  tcp4   127.0.0.1:9000        *:*
www      php-fpm    8628  0  tcp4   127.0.0.1:9000        *:*
www      php-fpm    8627  0  tcp4   127.0.0.1:9000        *:*
www      php-fpm    8626  0  tcp4   127.0.0.1:9000        *:*
www      php-fpm    8625  0  tcp4   127.0.0.1:9000        *:*
www      php-fpm    8624  0  tcp4   127.0.0.1:9000        *:*
www      php-fpm    8623  0  tcp4   127.0.0.1:9000        *:*
www      php-fpm    8622  0  tcp4   127.0.0.1:9000        *:*
www      php-fpm    8621  0  tcp4   127.0.0.1:9000        *:*
www      php-fpm    8620  0  tcp4   127.0.0.1:9000        *:*
www      php-fpm    8619  0  tcp4   127.0.0.1:9000        *:*
www      php-fpm    8618  0  tcp4   127.0.0.1:9000        *:*
www      php-fpm    8617  0  tcp4   127.0.0.1:9000        *:*
www      php-fpm    8616  0  tcp4   127.0.0.1:9000        *:*
www      php-fpm    8615  0  tcp4   127.0.0.1:9000        *:*
www      php-fpm    8614  0  tcp4   127.0.0.1:9000        *:*
www      php-fpm    8613  0  tcp4   127.0.0.1:9000        *:*
www      php-fpm    8612  0  tcp4   127.0.0.1:9000        *:*
root     php-fpm    8611  6  tcp4   127.0.0.1:9000        *:*
```


my /usr/local/etc/nginx/nginx.conf :

```
user  www www;
worker_processes  1;

# main server error log
# error_log     /var/log/nginx/error.log ;
pid     /var/run/nginx.pid;

events {
        worker_connections  1024;
}

# main server config
http {
        include       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"';

        sendfile        on;
        #tcp_nopush     on;
        #keepalive_timeout  0;
        keepalive_timeout  65;
        gzip  on;
user  www www;
worker_processes  1;

# main server error log
# error_log     /var/log/nginx/error.log ;
pid     /var/run/nginx.pid;

events {
        worker_connections  1024;
}

# main server config
http {
        include       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"';

        sendfile        on;
        #tcp_nopush     on;
        #keepalive_timeout  0;
        keepalive_timeout  65;
        gzip  on;


server {
        listen  80;
        server_name  localhost;

 #       access_log  /websites/theos.in/logs/access.log  main;

        location / {
            root   /magazyn/www/data;
            index  index.php index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/local/www/nginx-dist;
        }

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

        location ~ /\.ht {
            deny  all;
        }
}
}
```

There is nothing interesting in /var/log/nginx-error.log


----------



## VoViK (Dec 5, 2011)

Hi, you index.php file in /magazyn/www/data/ or in /websites/theos.in/http/ ?


```
location ~ \.php$ {
            root           /magazyn/www/data;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /magazyn/www/data/$fastcgi_script_name;
            include        fastcgi_params;
        }
```


----------



## soulreaver1 (Dec 5, 2011)

VoViK said:
			
		

> Hi, you index.php file in /magazyn/www/data/ or in /websites/theos.in/http/ ?
> 
> 
> ```
> ...



My index.php is in /magazyn/www/data/. Thanks for it, I've changed it as you suggested above, but the problem is still present - index.php is not executed but downloaded.


----------



## soulreaver1 (Dec 7, 2011)

Solved! The Issue has fixed by @VoViK suggestion posted above, but there was a second problem with my browser (google chrome). I've cleaned chrome cache, cookies etc. then it started to work.


----------

