Question
NGINX picking up fastcgi configuration from a different site config
I’m trying to set up a PHPMyadmin instance at db.example.com
on an NGINX setup on Ubuntu 20.04 machine.
I have in my sites-enabled
directory the config for the following (sub)domains (via symlink from sites-available
):
example.com
sub.example.com
anddb.example.com
When I initially tried to access the phpmyadmin instance at db.example.com
, I was greeted with the error: “No input file specified”, and this answer here provided some hint on a fastcgi misconfiguration.
I’ve changed the fastcgi modular config (conf/php_fastcgi.conf) file referenced in example.com
site config (a different host and dir) from:
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
to
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
This somehow loads the phpmyadmin login page site at db.example.com
without any errors.
THE PROBLEM: Here’s where the problem is: Logging in to the phpmyadmin instance now shows
File ./autoload.php missing or not readable.
Most likely you did not run Composer to install library files.
It’s likely looking for this path at somewhere else (due to symlinks/routing) as the autoload.php exists in /usr/share/phpmyadmin/ directory. The current db.example.com
site config is as mentioned below, in a later section.
I have a few questions in this regard:
- Why is NGINX picking up a fastcgi config file referenced from a different site config file altogether, in the first place and changing it initially had an effect here?
- How do I resolve this issue without opening up security issues by letting broad access to files/permissions?
Below are my relevant files:
/etc/nginx/nginx.conf: (subset)
# Load configs
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
nginx/sites-available/example.com.conf:
# Default server
server {
listen 443 ssl http2 default_server;
server_name __;
# SSL
...
return 444;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name example.com;
set $base /var/www/example.com;
root $base/public;
# SSL
...
# logging
access_log /path/to/log.log;
error_log /path/to/log.log warn;
# index.php
index index.php;
# handle .php
location ~ \.php$ {
include conf/php_fastcgi.conf;
}
}
nginx/sites-available/db.example.com.conf:
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name db.example.com;
root /var/www/db.example.com/;
index index.php index.html index.htm;
#logging
access_log /path/to/log.log;
error_log /path/to/log.log;
# SSL
....
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_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
A symlink exists for /usr/share/phpmyadmin/ <-> /var/www/db.example.com/ such that phpmyadmin exists as a directory symlink in db.example.com
dir and also symlinks exist for all the site configs in sites-available
to sites-enabled
Here’s conf
directory referenced in the above config:
conf/php_fastcgi.conf:
# 404
try_files $fastcgi_script_name =404;
# default fastcgi_params
include fastcgi_params;
# fastcgi settings
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
# fastcgi params
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_ADMIN_VALUE "open_basedir=$base/:/usr/lib/php/:/tmp/";
Thanks!
Questions have been referenced in the above post as “THE PROBLEM:”. Thanks!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×