Nginx + PHP-FPM serving .php files as downloads
It's a matter asked thousand times and since I hate write posts, I read and search for all possible documentation before get to the annoying part (for me) which is writing.
So I have Nginx & PHP-FPM up and running with CentOS 7.2. PHP-FPM is working with /var/run/php-fpm/php-fpm.sockproperly declared in www.conf:
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses on a
; specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /var/run/php-fpm/php-fpm.sock
This is my mywebsite.conf:
server {
listen 80;
server_name www.mywebsite.net;
# note that these lines are originally from the "location /" block
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_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Also I have cgi.fix_pathinfo=0 in php.ini.
I have restarted/reloaded Nginx and PHP-FPM services, restarted the whole server, and got nothing. I can't display .php files, they're just downloads.
What am I missing?
Thanks in advance.
centos php nginx
add a comment |
It's a matter asked thousand times and since I hate write posts, I read and search for all possible documentation before get to the annoying part (for me) which is writing.
So I have Nginx & PHP-FPM up and running with CentOS 7.2. PHP-FPM is working with /var/run/php-fpm/php-fpm.sockproperly declared in www.conf:
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses on a
; specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /var/run/php-fpm/php-fpm.sock
This is my mywebsite.conf:
server {
listen 80;
server_name www.mywebsite.net;
# note that these lines are originally from the "location /" block
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_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Also I have cgi.fix_pathinfo=0 in php.ini.
I have restarted/reloaded Nginx and PHP-FPM services, restarted the whole server, and got nothing. I can't display .php files, they're just downloads.
What am I missing?
Thanks in advance.
centos php nginx
add a comment |
It's a matter asked thousand times and since I hate write posts, I read and search for all possible documentation before get to the annoying part (for me) which is writing.
So I have Nginx & PHP-FPM up and running with CentOS 7.2. PHP-FPM is working with /var/run/php-fpm/php-fpm.sockproperly declared in www.conf:
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses on a
; specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /var/run/php-fpm/php-fpm.sock
This is my mywebsite.conf:
server {
listen 80;
server_name www.mywebsite.net;
# note that these lines are originally from the "location /" block
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_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Also I have cgi.fix_pathinfo=0 in php.ini.
I have restarted/reloaded Nginx and PHP-FPM services, restarted the whole server, and got nothing. I can't display .php files, they're just downloads.
What am I missing?
Thanks in advance.
centos php nginx
It's a matter asked thousand times and since I hate write posts, I read and search for all possible documentation before get to the annoying part (for me) which is writing.
So I have Nginx & PHP-FPM up and running with CentOS 7.2. PHP-FPM is working with /var/run/php-fpm/php-fpm.sockproperly declared in www.conf:
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses on a
; specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /var/run/php-fpm/php-fpm.sock
This is my mywebsite.conf:
server {
listen 80;
server_name www.mywebsite.net;
# note that these lines are originally from the "location /" block
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_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Also I have cgi.fix_pathinfo=0 in php.ini.
I have restarted/reloaded Nginx and PHP-FPM services, restarted the whole server, and got nothing. I can't display .php files, they're just downloads.
What am I missing?
Thanks in advance.
centos php nginx
centos php nginx
asked Nov 19 '16 at 15:20
AlainAlain
871614
871614
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Are there any other server blocks in Nginx configuration, especially with listen 80 default or default_server directives?
Also try to add access_log and error_log to Nginx configuration to find out are there any access to that server and are there any errors.
Yes, there's actually another server block:server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
– Alain
Nov 19 '16 at 18:02
So it means that right now you have to usewww.mywebsite.netname to access your site with php configured. For all other names evenmywebsite.netyou will access default section and simply download files as is. Simple solution would be removedefault_serverfrom default server block and use it on yourwww.mywebsite.netserver block. But also I recommend you to put all server names here and place files on different document root, so there will be no chance to download source php files with any fake server name.
– Fedor Dikarev
Nov 20 '16 at 9:20
add a comment |
sudo vim /etc/php-fpm.d/www.conf
DO NOT UNCOMMENT listen.mode = 0660
New contributor
Oner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f324532%2fnginx-php-fpm-serving-php-files-as-downloads%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Are there any other server blocks in Nginx configuration, especially with listen 80 default or default_server directives?
Also try to add access_log and error_log to Nginx configuration to find out are there any access to that server and are there any errors.
Yes, there's actually another server block:server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
– Alain
Nov 19 '16 at 18:02
So it means that right now you have to usewww.mywebsite.netname to access your site with php configured. For all other names evenmywebsite.netyou will access default section and simply download files as is. Simple solution would be removedefault_serverfrom default server block and use it on yourwww.mywebsite.netserver block. But also I recommend you to put all server names here and place files on different document root, so there will be no chance to download source php files with any fake server name.
– Fedor Dikarev
Nov 20 '16 at 9:20
add a comment |
Are there any other server blocks in Nginx configuration, especially with listen 80 default or default_server directives?
Also try to add access_log and error_log to Nginx configuration to find out are there any access to that server and are there any errors.
Yes, there's actually another server block:server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
– Alain
Nov 19 '16 at 18:02
So it means that right now you have to usewww.mywebsite.netname to access your site with php configured. For all other names evenmywebsite.netyou will access default section and simply download files as is. Simple solution would be removedefault_serverfrom default server block and use it on yourwww.mywebsite.netserver block. But also I recommend you to put all server names here and place files on different document root, so there will be no chance to download source php files with any fake server name.
– Fedor Dikarev
Nov 20 '16 at 9:20
add a comment |
Are there any other server blocks in Nginx configuration, especially with listen 80 default or default_server directives?
Also try to add access_log and error_log to Nginx configuration to find out are there any access to that server and are there any errors.
Are there any other server blocks in Nginx configuration, especially with listen 80 default or default_server directives?
Also try to add access_log and error_log to Nginx configuration to find out are there any access to that server and are there any errors.
answered Nov 19 '16 at 15:53
Fedor DikarevFedor Dikarev
1,063310
1,063310
Yes, there's actually another server block:server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
– Alain
Nov 19 '16 at 18:02
So it means that right now you have to usewww.mywebsite.netname to access your site with php configured. For all other names evenmywebsite.netyou will access default section and simply download files as is. Simple solution would be removedefault_serverfrom default server block and use it on yourwww.mywebsite.netserver block. But also I recommend you to put all server names here and place files on different document root, so there will be no chance to download source php files with any fake server name.
– Fedor Dikarev
Nov 20 '16 at 9:20
add a comment |
Yes, there's actually another server block:server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
– Alain
Nov 19 '16 at 18:02
So it means that right now you have to usewww.mywebsite.netname to access your site with php configured. For all other names evenmywebsite.netyou will access default section and simply download files as is. Simple solution would be removedefault_serverfrom default server block and use it on yourwww.mywebsite.netserver block. But also I recommend you to put all server names here and place files on different document root, so there will be no chance to download source php files with any fake server name.
– Fedor Dikarev
Nov 20 '16 at 9:20
Yes, there's actually another server block:
server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }– Alain
Nov 19 '16 at 18:02
Yes, there's actually another server block:
server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }– Alain
Nov 19 '16 at 18:02
So it means that right now you have to use
www.mywebsite.net name to access your site with php configured. For all other names even mywebsite.net you will access default section and simply download files as is. Simple solution would be remove default_server from default server block and use it on your www.mywebsite.net server block. But also I recommend you to put all server names here and place files on different document root, so there will be no chance to download source php files with any fake server name.– Fedor Dikarev
Nov 20 '16 at 9:20
So it means that right now you have to use
www.mywebsite.net name to access your site with php configured. For all other names even mywebsite.net you will access default section and simply download files as is. Simple solution would be remove default_server from default server block and use it on your www.mywebsite.net server block. But also I recommend you to put all server names here and place files on different document root, so there will be no chance to download source php files with any fake server name.– Fedor Dikarev
Nov 20 '16 at 9:20
add a comment |
sudo vim /etc/php-fpm.d/www.conf
DO NOT UNCOMMENT listen.mode = 0660
New contributor
Oner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
sudo vim /etc/php-fpm.d/www.conf
DO NOT UNCOMMENT listen.mode = 0660
New contributor
Oner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
sudo vim /etc/php-fpm.d/www.conf
DO NOT UNCOMMENT listen.mode = 0660
New contributor
Oner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
sudo vim /etc/php-fpm.d/www.conf
DO NOT UNCOMMENT listen.mode = 0660
New contributor
Oner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Oner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 9 mins ago
OnerOner
1
1
New contributor
Oner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Oner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Oner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f324532%2fnginx-php-fpm-serving-php-files-as-downloads%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown