Configure Phpmyadmin in NGINX to combine with NODEJS or another non-php applications


Configuring Phpmyadmin to be able working with another non-PHP applications is a little bit tricky. For instance, you have NODEJS application running in NGINX with root (“/”). When you’re opening http://yourdomain.com, then it will running NODEJS applications. Then, you want to make this domain have “/phpmyadmin” which it will running phpmyadmin. At this steps, you should handle this path from NGINX and pass it into PHP-FASTCGI.

This is example NGINX Configuration:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
server {
    listen 80;
    server_name yourdomain.com;

    location ~ ^/(js/|stylesheets/|images/|img) {
        root /mypath/public;
        access_log off;
        expires max;
    }

    location / {
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
       
        # proxy_http_version 1.1;
        proxy_pass http://127.0.0.1:3000;
    }
}


At this configuration, opening “http://yourdomain.com” will passed into NODEJS services in 127.0.0.1:3000.
Now, we need to configure phpmyadmin. You will need to know where the phpmyadmin location by:

1
2
sudo updatedb
locate phpmyadmin

After you got the path, then you can set NGINX virtualhost to serve “/phpmyadmin” by:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
server {
    listen 80;
    server_name yourdomain.com;

    location ~ ^/(js/|stylesheets/|images/|img) {
        root /mypath/public;
        access_log off;
        expires max;
    }

    location /phpmyadmin {
        alias /usr/share/phpmyadmin/;
        index index.php;
    }

    location ~ ^/phpmyadmin.+.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location / {
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
       
        # proxy_http_version 1.1;
        proxy_pass http://127.0.0.1:3000;
    }
}

If you facing error, please check the NGINX log in “/var/log/nginx/error.log” and see what the problem there.
Then after fixing, don’t forget to restart your NGINX services to make it works! 🙂


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.