NGINX not loading PHP inside phpmyadmin - php

Problem
I currently have a simple PHP page displaying phpinfo() correctly on localhost/info.php. However, when trying to open phpmyadmin by inputting "localhost/phpmyadmin" it gives me this:
I don't even mind if I have to input "localhost/phpmyadmin/index.php" to get it to work but that's not even working. It basically has the same popup but asking if I want to download the PHP file:
I've tried various nginx configurations but the one below is what gets me to this point. Any help would be greatly appreciated.
Current setup
PHP 7.2.7
nginx 1.15.0
Xubuntu 18.04
nginx.conf:
server {
listen 80;
listen [::]:80;
root /var/www/;
index index.php index.html index.htm index.nginx-debian.html;
server_name bacon.com;
location / {
try_files $uri $uri/ =404;
}
location ~ [^/]\.php(/|$) {
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
}

Turns out if you misconfigure it once your browser cache will hold onto that regardless of a correct configuration afterwards... cleared the cache and it worked!

Related

PHP 7.4, NGINX, Laravel 8 - only shows index page, all routes show 404

I have put a Laravel 8 application on a AWS t2.nano Linux AMI ec2 instance. I would like to start up front by saying I have been at this for about a day now. I have tried a few configurations.
Here's some configurations I have tried:
The default nginx config file from the Laravel 8 documentation
https://laravel.com/docs/8.x/deployment#nginx
Another very similar stackoverflow question referenced here
Laravel on nginx says 404 for all routes except index
At the end of the day, I cannot get it to work properly. My index page loads, but any of the other routes end up at a 404 page. You can view the application here.
https://technology.dvemedia.com/
So here are some tech specs and the current state of my conf file.
Laravel - 8
PHP - 7.4
NGINX - 1.12.2
# HTTP
server {
listen 80;
listen [::]:80;
server_name technology;
return 301 https://$host$request_uri; # Redirect to www
}
server {
listen 80;
listen [::]:80;
server_name technology.dvemedia.com;
root /var/www/html/technology/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fixes timeouts
fastcgi_read_timeout 600;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
What am I missing or doing wrong, because I cannot get it to route to save my life.
Try this:
## Nginx php-fpm Upstream
upstream dvemedia {
server unix:/var/run/php/php7.4-fpm.sock;
}
## Web Server Config
server
{
## Server Info
listen 80;
listen [::]:80;
server_name technology.dvemedia.com;
root /var/www/html/technology/public;
index index.html index.php;
## DocumentRoot setup
location / {
try_files $uri $uri/ #handler;
expires 30d;
}
## Disable .htaccess and other hidden files
location /. {
return 404;
}
## Rewrite all request to index
location #handler {
rewrite / /index.php;
}
## Execute PHP scripts
location ~ \.php$ {
try_files $uri = 404;
expires off;
fastcgi_pass dvemedia;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
and put all your optimisation/tweaks (like fastcgi_buffers ...) in fastcgi_params file
I made a bad assumption by thinking my php-fpm socket would stay the same. After looking at the directory structure, my socket for 7.4 ended up being here.
fastcgi_pass unix:/var/run/php-fpm/www.sock;
That actually fixed it and everything worked. I gave bad information when I wrote the path for my socket was actually this.
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
#Latheesan answer would most likely have worked had I had given the correct information, minus the spelling mistake of course.

Moodle installation error on Homestead VM

I have installed the Homestead VM and setup the Moodle installation folder on my Mac (OSX Yosemite). I also created the 'moodledata' folder and gave it the permissions 0777 as well as the folder 'moodledata/sessions' via my system command line (I tried doing this via SSH inside the VM but it didn't appear to change the permissions). However checking the permissions after doing it via my system showed the folder was writable from inside the VM.
I then moved on to the installation which ran through and created the DB tables and did the check which showed 2 check warnings:
Intl and xmlrpc to check
I don't believe these are essential for initial installation so carried on. It is when I get to the admin user creation where I am getting a problem. The page (/user/editadvanced.php?id=2) stops loading any images and when I post the form I get an error: 'Incorrect sesskey submitted, form not accepted!'
I thought this could be down to the session not being writable in the moodledata folder but as I have checked that now I am out of ideas!
I have attached a couple of screenshots.
Many thanks, Mike.
Ok after a good few days of head scratching I fixed my own issue by editing the NGINX config file. Below is what it was by default:
server {
listen 80;
server_name example.com;
root /home/forge/example.com;
# FORGE SSL (DO NOT REMOVE!)
# ssl_certificate;
# ssl_certificate_key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/example.com-error.log error;
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
And this is what I changed it to and it now works:
server {
listen 80;
server_name example.com; #REPLACE SERVER NAME
root /var/www/example.com/www/; #REPLACE MOODLE INSTALL PATH
error_log /var/www/example.com/log/example.com_errors.log; #REPLACE MOODLE ERROR LOG PATH
access_log /var/www/example.com/log/example.com_access.log; #REPLACE MOODLE ACCESS LOG PATH
rewrite ^/(.*\.php)(/)(.*)$ /$1?file=/$3 last;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php;
}
fastcgi_intercept_errors on;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
I haven't had time to see which part/parts of the above config fixed the issue, maybe someone who knows can see straight away? I suspect it could be the rewrite rule? Either way I hope this helps someone else in the future and I am really happy to get this working!
I can confirm is just the rewrite part for that specific config file, although in the Moodle Nginx page it's not documented that way.
My guess is that the location ~ [^/]\.php(/|$) { part is doing the same thing as the rewrite rule rewrite ^/(.*\.php)(/)(.*)$ /$1?file=/$3 last; and the location ~ \.php$ { directive. Will need to make some test changing the location directive to see if that works as well.

Nginx Site Configuration for Development Environment

I'm currently trying to setup a generic, multi-project development environment in Vagrant for students of a web-development mentoring project. The idea is the domain <project>.vagrant maps to ~/code/<project>
I thought I had enough experience with Nginx to solve this, but it turns out I don't.
Assuming that PHP-FPM is correctly setup, I need help with the try_files/routing for the site-configuration.
Whilst the homepage (/) works fine, any request to a non-static file (which should therefore be passed to PHP-FPM) results in either a 301 Moved Permanently to the homepage, or downloads the contents of the PHP script instead of executing it.
And yes I know listing so many index files is not ideal but the students will be dealing with multiple projects (phpMyAdmin, WordPress) and frameworks (Symfony, Silex, Laravel, etc).
Any help with this would be greatly appreciated!
The contents of the single site-available configuration file so far is:
map $host $projectname {
~^(?P<project>.+)\.vagrant$ $project;
}
upstream phpfpm {
server unix:/var/run/php5-fpm.sock;
}
server {
listen 80;
server_name *.vagrant;
server_tokens off;
root /home/vagrant/code/$projectname/web;
index app_dev.php app.php index.php index.html;
autoindex on;
client_max_body_size 5M;
location / {
try_files $uri $uri/ / =404;
}
# Pass all PHP files onto PHP's Fast Process Manager server.
location ~ [^/]\.php(/|\?|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
try_files $fastcgi_script_name =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# Specify the determined server-name, not the literal "*.vagrant".
fastcgi_param SERVER_NAME $projectname.vagrant;
fastcgi_pass phpfpm;
}
}

Laravel 5 - Nginx/PHP config issue

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.

Cannot get PHP to serve on Nginx — Error 404

I'm fairly new to nginx and assumed it would be very straightforward to serve php with it since that setup is so common, but it seems like it's much more complex than I anticipated.
Here's my config..
server {
listen 80;
server_name domain.com www.domain.com;
location / {
root /srv/www/domain.com/public_html;
index index.php;
}
# serve static files directly
#location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt)$
# access_log off;
# expires 30d;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass /var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
If I replace the "index.php" with a "index.html" file, nginx serves up the html perfectly.
I've seen guides that recommend modifying anything from iptables to php-fpm to the php.ini, to fast-cgi to sites-available..?
I'm not sure what many of these tutorials are trying to do exactly... for now I'd just like my index.php to serve up phpinfo(). What's the next step to troubleshoot the 404 error?
Is there a clear guide that goes over the various options available for serving php with nginx?
Debian Wheezy 7.3 on xen
Try this config:
server {
listen 80;
server_name domain.com www.domain.com;
root /srv/www/domain.com/public_html;
index index.php;
location ~ ^(.+\.php)(/.*)?$ {
fastcgi_pass localhost:9000;
include fastcgi_params;
}
}
(assuming your index.php file is in /srv/www/domain.com/public_html)

Categories