-1

i need to solve one problem. I have ngnix with public address, and i need to have access to my DB with phpmyadmin in local network by ip. I have configured it at address /usr/share/phpmyadmin following guide. At the moment i can download the php files from this directory but without execution. What i need to do to connect from browser to phpmyadmin? This is my ngnix config:

server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html;
index index.html index.htm;

server_name 192.168.1.101;

    location ^~ /permanentmark/ {
        alias /usr/share/phpmyadmin/;
        index index.php index.html;
        location ~ /pma(/.*\.php) {
            include fastcgi_params;
            fastcgi_param SERVER_NAME localhost;
            fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin$1;
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
            fastcgi_index index.php;
            }

    }
}
Ken White
  • 123,280
  • 14
  • 225
  • 444
  • Your nested location doesn't match the URI, use `location ~ \.php$` and `fastcgi_param SCRIPT_FILENAME $request_filename;`. See [this answer](https://stackoverflow.com/questions/47319049/nginx-subdirectory-root-with-php/47332159#47332159). – Richard Smith Nov 27 '20 at 20:54

1 Answers1

0

we still need is to tell Nginx to use our PHP processor for dynamic content. We do this on the server block level (server blocks are similar to Apache’s virtual hosts). Open the default Nginx server block configuration file by typing:

sudo nano /etc/nginx/sites-available/default

the Nginx default server block file looks like this:

server {
listen 80 default_server;
listen [::]:80 default_server;

root /var/www/html;
index index.html index.htm index.nginx-debian.html;

server_name _;

location / {
    try_files $uri $uri/ =404;
  }  
}

We need to make some changes to this file for our site.

First, we need to add index.php as the first value of our index directive so that files named index.php are served, if available, when a directory is requested. We can modify the server_name directive to point to our server’s domain name or public IP address. For the actual PHP processing, we just need to uncomment a segment of the file that handles PHP requests by removing the pound symbols (#) from in front of each line. This will be the location ~.php$ location block, the included fastcgi-php.conf snippet, and the socket associated with php-fpm. We will also uncomment the location block dealing with .htaccess files using the same method. Nginx doesn’t process these files. If any of these files happen to find their way into the document root, they should not be served to visitors.

The changes that you need to make are in the text below:

server {
listen 80 default_server;
listen [::]:80 default_server;

root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;

server_name server_domain_or_IP;

location / {
    try_files $uri $uri/ =404;
 }

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
 }

location ~ /\.ht {
    deny all;
  }
}

When you’ve made the above changes, you can save and close the file. Test your configuration file for syntax errors by typing:

sudo nginx -t

If any errors are reported, go back and recheck your file before continuing. When you are ready, reload Nginx to make the necessary changes:

sudo systemctl reload nginx