Configuring nginx and phpMyAdmin
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:
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
If I go to
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!???
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;
}
}
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
Thanks!!
I simply changed it back to domain.com (which is what I though it should've been) and now all is working.
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.
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!
@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.
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;
}
}
@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?
fastcgiparam SCRIPTFILENAME /usr/share$fastcgiscriptname;
should be:
fastcgiparam SCRIPTFILENAME /usr/share/phpmyadmin$fastcgiscriptname;
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!
/home/user/websites/$ ln -s /usr/share/webapps/phpMyAdmin phpmyadmin
And that's all