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 and
  • db.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:

  1. 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?
  2. 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!


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi @1NF1N17Y,

I believe the issue may lay somewhere in phpmyadmin’s ownership and permissions. It’s possible Nginx can’t read the files or anything at all due to the ownership being root:root rather than the Nginx user.

You also mentioned a symlink exists between /usr/share/phpmyadmin/ and /var/www/db.example.com/, I would take the ownership of that symlink is as well root:root?