Configuring nginx and phpMyAdmin

I did a search but never seemed to find the issue/guidance for my question.

I followed the installation of nginx with Ubuntu 10.10 here on the library. I installed PHP and MySQL following this guide too (LEMP stack).

Now, for additional convenience, I wanted to also setup phpMyAdmin.

I've done everything I need to except create a VirtualHost entry.

I want it to be: http://domain.com/phpmyadmin.

Here is my /etc/nginx/sites-available/domain.com file contents:

server {
     listen     80;
     server_name www.domain.com domain.com;
     access_log /srv/www/domain.com/logs/access.log;
     error_log /srv/www/domain.com/logs/error.log;

     location / {
          root     /srv/www/domain.com/public_html;
          index   index.html index.htm;
     }

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

      location ~ \.php$ {
           include fastcgi_params;
           fastcgi_pass 127.0.0.1:9000;
           fastcgi_index index.php;
           fastcgi_param SCRIPT_FILENAME /srv/www/domain.com/public_html$fastcgi_script_name;
       }
}

The second "location" entry is me testing. I'm probably missing something simple. Not sure!

Any help is greatly appreciated! Thanks!

14 Replies

OK so what is your problem exactly? Maybe it's because I've not woken up yet but I don't see what issue you're having…

Oh… d'oh!

If I go to http://domain.com/phpmyadmin I get 404'd.

Edit: Hmm… nevermind now it's not even recognizing nginx at all (Server not found).

Edit2: Ok nevermind it's working again. The index.html is working and I've tested a phpinfo() as well. But still having that 404 issue.

Edit3: Ugh… weird issue now. index.html works fine but if I F5 (refresh) I get a Server not found. But if I click the address bar and hit Enter (basically another way to refresh) it works fine!???

It's probably due to this part

location ~ .php$ {

include fastcgi_params;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgiparam SCRIPTFILENAME /srv/www/domain.com/publichtml$fastcgiscript_name;

}

The index.php file for phpmyadmin is being passed to /srv/www/domain.com/publichtml with $fastcgiscript_name being /phpmyadmin/index.php

You need to set it up so it sends to /usr/share/phpmyadmin$fastcgiscriptname

Try this

server { 
     listen     80; 
     server_name www.domain.com domain.com; 
     access_log /srv/www/domain.com/logs/access.log; 
     error_log /srv/www/domain.com/logs/error.log; 

     location / { 
          root     /srv/www/domain.com/public_html; 
          index   index.html index.htm; 
     } 

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

      location ~ \.php$ { 
           include fastcgi_params; 
           fastcgi_pass 127.0.0.1:9000; 
           fastcgi_index index.php; 
           fastcgi_param SCRIPT_FILENAME /srv/www/domain.com/public_html$fastcgi_script_name; 
       } 
} 

Thanks.

I've adjust accordingly, but continue to have this "F5 / www. issue. And the /phpmyadmin is Server not found no matter what I try.

Maybe I configured the DNS Manager wrong?

I simply did "ns1.domain.com" for the web address and then in my GoDaddy account "ns1.linode.com" and "ns2.linode.com"

EDIT: Woot! I fixed it :) I had a stupid DNS issue. My bad :) All is working now with the configuration you gave me as well!

Thanks!!

I'll need your linode IP and real domain to diagnose DNS issues.

Fixed :)

I simply changed it back to domain.com (which is what I though it should've been) and now all is working.

You should be able to ditch that redundant PHP FastCGI within your phpmyadmin location by changing your .php location to:

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

Note the changed SCRIPTFILENAME line – by using the variable $documentroot you can avoid redundant hard-codings of your root path, and only write it once. Also, it should mean that alternative root paths -- such as that within your phpmyadmin location -- will automatically "fix" the SCRIPT_FILENAME path for you.

Also, the use of $document_root instead of a redundant hard-coded path is the preferred way, and using it will save you much ridicule from the Nginx community. :wink:

EDIT: I should clarify that I've not tested this solution myself, but it seems like it should work. At any rate, do switch to using $document_root, if nothing else it'll save you some grief when you forget you've got a second hard-coded path down the road when you're moving things around! :wink:

@Kromey:

You should be able to ditch that redundant PHP FastCGI within your phpmyadmin location by changing your .php location to:

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

Note the changed SCRIPTFILENAME line – by using the variable $documentroot you can avoid redundant hard-codings of your root path, and only write it once. Also, it should mean that alternative root paths -- such as that within your phpmyadmin location -- will automatically "fix" the SCRIPT_FILENAME path for you.

Also, the use of $document_root instead of a redundant hard-coded path is the preferred way, and using it will save you much ridicule from the Nginx community. :wink:

EDIT: I should clarify that I've not tested this solution myself, but it seems like it should work. At any rate, do switch to using $document_root, if nothing else it'll save you some grief when you forget you've got a second hard-coded path down the road when you're moving things around! :wink:

I appreciate your help, Kromey!

Unfortunately, I was not able to get this working with that change.

What could possibly be the issue?

Thanks!

EDIT: Actually, I see the reason why. /phpmyadmin is located in an area that is NOT the server directory. In this case, I believe hard-coding that in is the only way. Unless I am mistaken. For most PHP applications, I should be perfect though, because I will simply be utilizing the server directory.

Hmm… I just recently restarted my server and am now receiving "502 Bad Gateway" when accessing www.domain.com/phpmyadmin

Here is my current file contents:

server {
    listen   80;
    server_name www.domain.com domain.com;
    access_log /srv/www/domain.com/logs/access.log;
    error_log /srv/www/domain.com/logs/error.log;

    location / {
        root   /srv/www/domain.com/public_html;
        index  index.html index.htm;
    }

 location ^~ /phpmyadmin/ {
          root /usr/share/phpmyadmin;
          index index.php;
           include fastcgi_params;
           fastcgi_pass 127.0.0.1:9000;
           fastcgi_index index.php;
           fastcgi_param SCRIPT_FILENAME /usr/share$fastcgi_script_name;
     }
 location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /srv/www/domain.com/public_html$fastcgi_script_name;
    }
}

I'm still having this issue :*(

@delibar:

Hmm… I just recently restarted my server and am now receiving "502 Bad Gateway" when accessing www.domain.com/phpmyadmin

Here is my current file contents:

server {
    listen   80;
    server_name www.domain.com domain.com;
    access_log /srv/www/domain.com/logs/access.log;
    error_log /srv/www/domain.com/logs/error.log;

    location / {
        root   /srv/www/domain.com/public_html;
        index  index.html index.htm;
    }

 location ^~ /phpmyadmin/ {
          root /usr/share/phpmyadmin;
          index index.php;
           include fastcgi_params;
           fastcgi_pass 127.0.0.1:9000;
           fastcgi_index index.php;
           fastcgi_param SCRIPT_FILENAME /usr/share$fastcgi_script_name;
     }
 location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /srv/www/domain.com/public_html$fastcgi_script_name;
    }
}

Thoughts?

I think the line that reads:

fastcgiparam SCRIPTFILENAME /usr/share$fastcgiscriptname;

should be:

fastcgiparam SCRIPTFILENAME /usr/share/phpmyadmin$fastcgiscriptname;

Gah! Okay. Well I sat down and played around with this for a while now and finally figured it out.

I had some issue with FastCGI user so I just manually set the user it runs on.

Then I had to adjust the Virtual Host files back to what obs originally provided.

Thanks for the help!

A couple a days ago I was struggling to access to phpmyadmin (or any "webapp" for this matter) in my arch linux machine, after trying a lot of configurations I found that the simpler approach is to make sure php it's working under any configuration and then make a symbolic link under that directory. In my case was:

/home/user/websites/$ ln -s /usr/share/webapps/phpMyAdmin phpmyadmin

And that's all :P

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct