First at all I am new here and new to unix. My previous experience was solely with cPanel, Plesk etc. So please forgive me if there are some mistakes in my approach here.
I have a Centos (release 7.3.1611) VPS with Nginx (1.10.2) and PHP (7.0.17).
I followed some guides to get PHP running and followed some answers given here to similar problems as well to no avail.
Here is my configuration:
www.conf:
listen = /run/php-fpm/php-fpm.sock
listen.owner = nginx
listen.group = nginx
user = nginx
group = nginx
I changed permission and ownership on php-fpm.sock.
nginx.conf:
include /etc/nginx/default.d/*.conf;
nginx/default.d/default.conf:
index index.php index.html index.htm;
server_name _;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Finally I have created a info.php file. When executing it I am getting a nginx error: The page you are looking for is temporarily unavailable. Please try again later.
If disabling the nginx error page the browser is asking me if I want to download the file info.php.
Thank you for helping me out!!!
I initially encountered similar issues but fixed by making sure the path to 'include' and 'fastcgi_pass' were valid. You can verify if something is available at these paths by navigating to those directories.
# PHP 7
# cgi.fix_pathinfo=0 in php.ini
# case-sensitive regex
location ~ \.php$ {
include /usr/local/nginx/conf/fastcgi_params;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
try_files $uri $uri/ =404;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
Hope this helps.
Cheers,
Ian
Related
I know there is so much documentation about this but i can't understand where is the problem.
I have fresh installation of Debian 8 and the first think I install is Nginx fastcgi.
Nginx is working but it can't execute any php file.
i have tried some combination of section location ~ .php$ of nginx configuration file but when i try to load .php file from beowser it's just downloaded. There is the last try;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;
#fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
#include snippets/fastcgi-php.conf;
}
where could be the problem?
Thx all
What do you mean by nothing work? If you get a error of type 500, then it may come from your nginx configuration. However if it is just that your php is not executed, it means that php-fpm service may not be running.
I'm attempting to serve PHP with nginx, i've followed this tutorial successfuly before but on a new server for some reason I get the following error:
nginx: [emerg] open() "/etc/nginx/snippets/fastcgi-php.conf" failed (2: No such file or directory)
In fact, the whole snippets directory of the nginx installation is missing.
I've installed PHP with the following commands:
- sudo apt-get install -y php7.0-cli php7.0-cgi php-fpm php-mysql
- sudo systemctl restart php7.0-fpm
I've installed the most up to date nginx that is available - and yet the directory and file is still not present.
How can this be remedied?
Bonus: What could have caused this?
TLDR:
Final version is:
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
i think it depends on the Nginx version you are using.
For Nate's answer, nginx-full will install 1.10.3 for you.
I'm using Nginx 1.12.2 on Ubuntu 16.04, with this version, it doesn't have sites-enabled and sites-available with it; and it also has a different PHP CGI setup.
You can either use Ulad Kasach's solution, or start to use the new way.
Here's an official doc for how to do it: https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/
BTW, in above post, you should also replace fastcgi.conf with fastcgi_params.
And add one more line which is in default orignially:
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
These are all new changes with Nginx 1.12.2 :(
Final version is:
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
Ended up having to look at a previous, working, configurations file and replicating it manually. Simply made the snippets directory and added a fastcgi-php.conf file with the following content:
# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;
# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_index index.php;
include fastcgi.conf;
You'll also need to replace the last line, include fastcgi.conf; with include fastcgi_params;.
I would have recommended to create the file fastcgi.conf; if it was not literally the same file with the additional line fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; in the case of fastcgi.conf
Had me stumped for a moment too. You want to install the nginx-full package on ubuntu as opposed to just nginx. nginx-full contains the bits you were missing.
i am using
nginx/1.4.6
Ubuntu 14.04.5 LTS
and my site config looks like this
server {
listen 3010;
root /usr/share/nginx/docs;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name phpSetup;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
and working nicely .
so i do recommend to update your
config
include snippets/fastcgi-php.conf;
to
include fastcgi_params;
so the location block is
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
HOPE IT HELPS
read more on :
https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/
thanks,
Based on this question How to install symfony2 app in a subdirectory in nginx
I've created symfony3 application that works in subdirectory called bcms4. I've manged to make php work with PHP-FPM but I have probelms with assets. When I want to GET asset it directs the request to app_dev and shows 404 because obviosly the path does not exist.
My question is how to make assets not to be proccesed by app_dev but downloaded as supposed?
So when I enter
test.localhost/s/asdfad -> it runs symfony
test.localhost/asdf -> it runs other app living in main dir
test.localhost/s/assets/css/test.css -> it will show file in directory /var/www/test.localhost/bcms4/web/assets/css/test.css
My nginx config:
server {
listen 80;
root /var/www/test.localhost;
index index.html index.htm index.php;
# Make site accessible from http://localhost/
server_name test.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
}
location ~ ^/s(/.*)$ {
try_files /s/web$1 /web$1 #sf2dev =404;
}
location #sf2dev {
expires off;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/test.localhost/bcms4/web/app_dev.php;
fastcgi_param SCRIPT_NAME /s/app_dev.php;
fastcgi_param REQUEST_URI /s$1;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_intercept_errors on;
}
}
After hours of trying I've managed to figure it out with little hack.
This is what I've added to my config file
location ~ ^/s(/.*).\w{1,5}$ {
rewrite ^/s(/.*) /bcms4/web$1 break;
return 404;
}
It'll rewrite files that has prefix /s and extension to directory where they are actually.
Maybe it will help someone. I'll leave question open for a while maybe someone has better solution cause it's seems hacky for me.
I'm having an issue where when I go to the /public directory it shows the Laravel app as normal, but navigating away to any other page results in it saying
No input file specified.
I am using an Nginx server with PHP 5.5.9 FPM.
I've scoured google for the last 4 hours or so, looking at every tutorial and stackoverflow page for rewriting issues in Laravel however they all yield the same result.
I've even set all the files and folders to 777 so I could see if it was some sort of permissions issue. I've checked the Laravel config and it's all set, I've no idea what is wrong.
Can anyone point me in the right direction?
The last config I tried is below:
server {
listen 80 default_server;
root /usr/share/sites/base;
index index.php
server_name localhost;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
}
}
I have also tried many others such as:
server {
listen 80;
server_name domain.com;
root /usr/share/sites/base;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
if (!-d $request_filename) {
rewrite ^/(.+)/$ /$1 permanent;
}
location ~* \.php$ {
# Server PHP config.
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
}
The error "No input files specified" will nearly always be related to the fact that the wrong path was sent to php.
Looking at your 'last config tried' I can see that fastcgi_param SCRIPT_FILENAMEis not defined in your php location. You should first begin by defining it in the location :
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name
}
Furthermore you say that you can reach the app so this means that index.php is working but not when you change page. So the problem should also come from /index.php?$args. Indeed, using this line if I try to reach yourserver.com/test and if 'test' is not a file in your root path nginx will then try request /index.php? (I had this probem). You should try only with /index.php.
EDIT : The solution was that root directive should point to the Laravel public folder, in that case /usr/share/sites/base/public.
I try to run a simple Symfony2 application on a virtual machine. I have Nginx on this VM (generated with PuPHPet and Vagrant), but there's a problem.
When I try to access to the demo route /demo (local.dev/Symfony/web/app_dev.php/demo), Nginx force me to download a file. It seems it works the same way when I specify a random route.
I don't know how to solve this problem, I searched while 2 days for a specific configuration of Nginx but I found nothing. Here is my config file for this Symfony app :
server {
server_name test.dev;
root /var/www/local.dev/Symfony/web;
location / {
try_files $uri /app.php$is_args$args;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
error_log /var/log/nginx/sf-error.log;
access_log /var/log/nginx/sf-access.log;
}
Thanks for your help.