PROBLEM: Problem i am facing is when I open localhost/phpmyadmin it gives me "No Input file Specified"
I am trying to configure Nginx and php on Windows.
Nginx installed path is E:\server\nginx
php installed path is E:\server\php
PhpMyAdmin installed path is E:\phpmyadmin\
My Root directory path is E:\server\www
Following code is from nginx.conf file.
server {
listen 80;
server_name localhost;
root E:\server\www;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location /phpmyadmin/ {
alias E:/server/phpmyadmin/;
try_files $uri /phpmyadmin/index.php =404;
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
}
I am running nginx and php from command prompt
cd `E:\server\nginx\
nginx.exe`
cd E:\server\php\
php-cgi.exe -b 127.0.0.1
server runs fine. I can access localhost/
I can also access any .php file from www folder.
PROBLEM: Problem I am facing is when I open localhost/phpmyadmin it gives me "No Input file Specified"
Please tell me I am doing wrong. Thank you in advance.
Give this an attempt:
server {
listen 80;
server_name localhost;
root E:\server\www;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location /phpmyadmin {
alias E:/server/phpmyadmin/;
index index.php;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}
}
Related
I'm really giving up on this. I have nginx+PHP-FPM, just trying to alias a path.
Desired:
https://example.com/api/v1.0/ -> /my/folder/v1.0/
I've tried alias:
server {
server_name mysite.com;
index index.php;
location /api/v1.0/ {
index index.php;
alias /my/folder/v1.0/;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
}
Nope. The logs reports that nginx is trying to access:
/etc/nginx/html/api/v1.0
So i changed the root:
server {
server_name mysite.com;
root /my/folder/v1.0/;
index index.php;
location /api/v1.0/ {
index index.php;
alias /my/folder/v1.0/;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
}
Nope. Now the alias is ignored and nginx trying to access:
/my/folder/v1.0/api/v1.0
I'm out of ideas, could you please help me?
Ok I was able to reproduce and fix it locally.
Here's what I ended up with:
# where the actual API is
root /1int/code/test/nginx;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
try_files $uri = 404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# This basically drops /api/1.0 prefix from the URL
location ^~ /api/1.0 {
rewrite ^/api/1.0/(.*)$ /$1 last;
}
With this config, when I access /api/1.0/api.php it fetches <root>/api.php
I'm trying to setup my Laravel project using Nginx. My /etc/nginx/conf.d/default.conf is:
server {
listen 80;
index index.php index.html;
root /var/www/public;
location / {
try_files $uri /index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
I have a problem with routes with ".php" endings, e.g.
Route::get('modules.php', 'ModuleController#index');
Instead of going to index.php and looking there the route, the server tries to open file modules.php, which doesn't exist.
I know, that problem in nginx settings, but I don't have experience with it, so I can't fix it myself.
Look through this page https://www.digitalocean.com/community/tutorials/how-to-install-laravel-with-an-nginx-web-server-on-ubuntu-14-04
Here you can find suitable configuration and description.
For example:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/laravel/public;
index index.php index.html index.htm;
server_name server_domain_or_IP;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Add a try_files statement to the second location block.
For example:
location / {
try_files $uri /index.php?$args;
}
location ~ \.php$ {
try_files $uri /index.php?$args;
fastcgi_pass app:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
Currently I have a Wordpress site under /var/www/html/wordpress and other php projects under /var/www/html/projects. I want my root location to point to wordpress one. Here is my current nginx config:
server {
listen 80 default_server;
server_name _;
set $yii_bootstrap "index.php";
root /var/www/html;
client_max_body_size 2M;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location /projects/inspection/ {
root /var/www/html;
try_files $uri /index.php$is_args$args;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
}
location /projects/ {
root /var/www/html;
index index.html $yii_bootstrap;
try_files $uri $uri/ /$yii_bootstrap?$args /index.php$is_args$args;
}
location / {
root /var/www/html/wordpress;
try_files $uri $uri/ =404;
index index.php index.html index.htm;
}
location ~ \.php{
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_pass php-fpm;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
include fastcgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
}
But it returns 404. I tried to put alias instead and it returns 403 forbidden. How should I handle this?
I'm using Laravel 5.2 and Nginx and works fine on my development server.
For example:
http://example.com/results?page=2
Development Server
LengthAwarePaginator::resolveCurrentPage(); // returns 2
Paginator::resolveCurrentPage(); // returns 2
$request->input('page'); // returns 2
But in production server
LengthAwarePaginator::resolveCurrentPage(); // returns 1
Paginator::resolveCurrentPage(); // returns 1
$request->input('page'); // returns null
Production Server Configuration
server {
listen 80 ;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html/laravel/public;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name example.com www.example.com;
location / {
try_files $uri $uri/ /index.php;
}
location #rewrite {
rewrite ^(.*)$ /index.php?_url=$1;
}
location ~ \.php$ {
try_files $uri $uri/ /index.php$is_args$args;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include /etc/nginx/fastcgi_params;
}
}
Development Server Configuration
server {
listen 80;
server_name example.com;
client_max_body_size 50M;
root /var/www/html/laravel/public;
index index.html index.htm index.php;
try_files $uri $uri/ #rewrite;
add_header 'Access-Control-Allow-Origin' '*';
location #rewrite {
rewrite ^(.*)$ /index.php?_url=$1;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php5.6-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_VALUE "upload_max_filesize=52428800 \n post_max_size=53477376 \n memory_limit=536870912";
fastcgi_param APPLICATION_ENV development;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
What changes should I make in server nginx configuration?
Any help appreciated!
Resolved!
I needed to make some corrections as there were two fastcgi_pass in location ~ \.php$ {} so had to change
location ~ \.php$ {
try_files $uri $uri/ /index.php$is_args$args;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include /etc/nginx/fastcgi_params;
}
To
location ~ \.php$ {
try_files $uri $uri/ /index.php$is_args$args;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include /etc/nginx/fastcgi_params;
}
and modify try_files in location / {} hence had to change
location / {
try_files $uri $uri/ /index.php;
}
To
location / {
try_files $uri $uri/ /index.php?$query_string;
}
I have the following nginx server block in its configuration
server {
listen 80;
server_name mydomain.com;
location /deploy {
alias /home/somedir/deploy/;
}
# pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
I want to execute a php file at the url mydomain.com/deploy/erp/index.php or mydomain.com/deploy/erp
The above thing downloads the php file instead of executing it. I googled and found solutions that asks you to define a www directory or something. I just need to execute the file in a specific directory at specific url. What are my options?
You haven't told nginx what to do with .php files. Assuming you're using php-fpm, you'll need something like this:
server {
listen 80;
server_name mydomain.com;
root /home/somedir;
location / {
try_files $uri $uri/ =404;
}
location /deploy {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
}