PHP not running on nginx with Debian 8 - php

I just configured my Debian 8 server with nginx. I can browse html files. I use let's encrypt which works succesfully, also with redirecting http to https automatically.
What does not work is PHP. Also a simple info.php file with
<?php
phpinfo();
?>
does not work.
On browser client my error message is:
404 Not Found nginx/1.6.2
Nginx' error log shows this:
2018/05/29 19:22:57 [error] 1879#0: *1592 open() "/usr/share/nginx/html/info.php" failed (2: No such file or directory), client: ip_address, server: , request: "GET /info.php HTTP/1.1", host: "domain"
My nginx configuration is:
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
server_name my-server.de www.my-server.de;
return 301 https://$server_name$request_uri;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;
}
location ~ /.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
include snippets/ssl-my-server.de.conf;
include snippets/ssl-params.conf;
}
Even if i move info.php to /usr/share/nginx/html then the client browser just downloads the info.php file.
I went through all steps in this guide. But still it isn't working. So how to fix that?

You have not added in SSL listen port 443, and ssl config of let's encrypt, please comment 301 redirect, test PHP, than go for SSL configuration see https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-debian-8
I have seen you have added SSL configuration, you need fix as below nginx configuration, after redirect, PHP should be configured on 443 not on 80.
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name my-server.de www.my-server.de;
# Redirect to HTTPS
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
include snippets/ssl-my-server.de.conf;
include snippets/ssl-params.conf;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;
}
location ~ /.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}

This is what I'm using:
upstream php {
server 127.0.0.1:9000;
server unix:/var/run/php5-fpm.sock down;
}
location ~* \.php$ {
root /var/www/html/;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_read_timeout 180;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_pass php;
fastcgi_index index.php;
}

Related

Nginx running, but page is blank

I'm trying to configure a MunkiReport (https://github.com/munkireport/munkireport-php) site on an Ubuntu server hosted in DigitalOcean. I have PHP and MySQL installed and configured. When I navigate to my webroot, I get a successful message back from nginx.
My webroot is /usr/share/nginx/html and I'm using /usr/local as my repo for both Munki and MunkiReport. I put a symlink for the /usr/local/report/public folder into /usr/share/nginx/html.
Here is my nginx configuration (/etc/nginx/sites-enabled/default) file:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.php index.html index.htm;
server_name example.com;
location /report {
alias /usr/share/nginx/html/public;
autoindex off;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
location /munki_repo/ {
alias /usr/local/munki_repo/;
autoindex off;
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
}
listen [::]:443 ssl ipv6only=on;
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/mysite.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mysite.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
server {
if ($host = example.com) {
return 301 https://$host$request_uri;
}
}
I have an .env file at the root of my MunkiReport folder which contains the configuration information (MySQL database connection) inside of it.
When I navigate to the https://example.com/report location, nothing loads. The console doesn't show any errors either, it's just blank.

Nginx is using both port 80 and 8080

I changed listening port of nginx from 80 to 8080 in /etc/nginx/site-enabled/default but when in netstat -plnt result it use both of them:
here is my nginx default config
server {
listen 8080 default;
root /home/mosi/workspace;
# Add index.php to the list if you are using PHP
index index.html index.htm index.php;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
}
Problem solved
Since I had many other config file, I just added port listening line in other configs and It work correct now
Tahnks

Nginx - Redirect 404 PHP files

I'm using Laravel's valet on my local. I did not have a problem with this on my local. My remote server uses Ubuntu 16.04.
I have an index.php like so in my website's root:
<?php
require __dir__ . '/src/core/bootstrap.php';
require __dir__ . '/src/controllers/index.php';
src/core/bootstrap.php is stuff for composer and databases. But this is what src/controllers/index.php is:
<?php
session_start();
use App\UserTools\User;
use App\Core\Router;
$page = Router::load()->fetchPage();
include "src/controllers/{$page}.controller.php";
include "src/views/{$page}.view.php";
So, when users visit site.com, it goes to main since it's the home page. But, let's say, for example, they visit: site.com/about, then $page would be about and viola... routing. This was all taught to me on Laracasts, so excuse me if this seems... rudimentary.
The problem lies, when I visit site.com/api, it just shows me a blank page. Or, like, book?id=1 blank page. Or
Here is the nginx block from valet which tells the server what to do with files not found:
location / {
rewrite VALET_SERVER_PATH last;
}
How can I apply that to my site? I tried substituting VALET_SERVER_PATH with /var/www/html but I just got a Server Error 500.
Here is my current nginx block:
server {
server_name www.site.org;
return 301 $scheme://site.org$request_uri;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name site.org;
return 301 https://$server_name$request_uri;
}
server {
# SSL configuration
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
include snippets/ssl-site.org.conf;
include snippets/ssl-params.conf;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name site.org;
location / {
try_files $uri $uri/ /index.php;
}
location ~ /.well-known {
allow all;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
It works. But only for the front page. Yes, I have HTTPS enabled and www traffic gets re-directed to non-www URI.
Make changes on the following directives:
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
}

nginx with php-fpm in https returns blank page in php

I've successfully setuped nginx with php-fpm (with http and https),
but when i run a php file in https connection i goa q blank page.
However running php file in http works fine,i am using the same php-fpm configuration for http and https
nginx-configuration for php-fpm(http and https)
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
index index.php index.html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
SSL configuration
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name localhost;
root /var/www/html/cushbu.com/public;
}
Note.
Running .html file in https returns ouput
eg:
https://<ip>/test.html //returns output
https://<ip>/test.php //returns blank output.
http://<ip>/test.php //returns output

NGINX change phpMyAdmin port within a location block

I have my phpMyAdmin setup as follows. This is within the server block of the default in sites-available and sites-enabled.
How can I change the port to say 8003 within the location block or somewhere without affecting the function of the port 80?
server{
listen 80; ## listen for ipv4
listen [::]:80 default ipv6only=on; ## listen for ipv6
[..........]
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
[..........]
}
You can't set a port in a location block. It wouldn't make sense because the client is connected already when a location is processed. You can make a new server block though, listening on the port you want, and put the location-block in question in the new server block.

Categories