What i'm trying to do is to access phpmyadmin from IP/phpmyadmin
I have edited the default conficuration file in the Site-available directory
my configuration is :
server {
location /phpmyadmin {
root /usr/share/;
index index.php;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ^~ /phpmyadmin/ {
alias /usr/share/phpmyadmin/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
}
But when I go to IP/phpmyadmin
it redirects me to the maini index file which we see the Welcome to nginx! message
Any help would be great !
I found out what was wrong!
I just needed to add the symbolic link
sudo ln -s /usr/share/phpmyadmin/ /usr/share/nginx/www
Actually you needed to add the server_name with your IP, and maybe also disable the default server, what you did is just tricking nginx.
Related
Ubuntu 16.04.5 LTS Xenial 4.18.8-x86_64-linode117
nginx version: nginx/1.10.3 (Ubuntu)
php v7.0.32-0ubuntu0.16.04.1`
/etc/nginx/sites-available/default
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
No symlink at /var/www/html
Worx well....
But I can't seem to figure out how to change phpmyadmin url.
Tried creating a symlink whatever ->/usr/share/phpmyadmin or whatever ->/usr/share/phpmyadmin/ under /var/www/htmldoes not work,
Even if I change /etc/nginx/sites-available/default to:
location /whatever {
root /usr/share/phpmyadmin/;
Created a symlink as mentioned above, restarted both nginx & php7.0-fpm still the new URL tried to download the page...
Looked up different resources on the net but they dont help:
digitalocean's guide
devanswers guide
As well as other here on SO but couldn't find a solution.
Ideas??
UPDATE
By Richard Smith's remark
location /whatever {
alias /usr/share/phpmyadmin;
index index.php index.html index.htm;
if (!-e $request_filename) { rewrite ^ /phpmyadmin/index.php last; }
# Secure phpMyAdmin Instance
auth_basic "Admin Login";
auth_basic_user_file /etc/nginx/.your_pass_file;
client_max_body_size 68M;
location ~ ^/phpmyadmin/(.+\.php)$ {
if (!-f $request_filename) { return 404; }
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
alias /usr/share/phpmyadmin;
}
}
Try:
location ^~ /whatever {
alias /usr/share/phpmyadmin;
index index.php index.html index.htm;
if (!-e $request_filename) { rewrite ^ /whatever/index.php last; }
# Secure phpMyAdmin Instance
auth_basic "Admin Login";
auth_basic_user_file /etc/nginx/.your_pass_file;
client_max_body_size 68M;
location ~ \.php$ {
if (!-f $request_filename) { return 404; }
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
You need to use /whatever/index.php in the rewrite statement. The nested location blocks only need to match the end of the URI. The ^~ modifier avoids conflicts with other regular expression location blocks at the server block level. Use $request_filename in the SCRIPT_FILENAME. Your last nested location block appears to perform no function.
Avoid try_files with alias due to this issue. See this caution on the use of if.
I want that app.php is executable, just like index.php. How can I set this up?
It's for symfony, because symfony has no index.php.
it'is already executable! I think you mean to make apache to look for app.php instead of index.php, to do that you should config your .htaccess file and add somethink like that :
DirectoryIndex app.php
Example for a local virtual host with php5-fpm
server {
listen 80;
server_name your.site.lan;
root /var/www/your.site.lan/web;
error_log /var/log/nginx/site.error.log;
access_log /var/log/nginx/site.access.log;
# strip app.php/ prefix if it is present
rewrite ^/app\.php/?(.*)$ /$1 permanent;
location / {
index app.php;
try_files $uri #rewriteapp;
}
location #rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}
# pass the PHP scripts to FastCGI server from upstream phpfcgi
location ~ ^/(app|app_dev|index|app_test|config|info|apc)\.php(/|$) {
fastcgi_pass phpfcgi;
fastcgi_read_timeout 600;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}
where phpfcgi is alias configured at nginx.conf at http section
upstream phpfcgi {
server unix:/var/run/php5-fpm.sock;
}
Nginx and PHP5-FPM are installed and running well ...
# I can access both http://www.example.com and http://www.example.com/info.php
$ ls -la /var/www/html
-rw-r--r-- 1 root root 868 Nov 1 08:16 index.html
-rw-r--r-- 1 root root 21 Nov 1 08:13 info.php
I installed phpmyadmin and created a symlink to phpmyadmin files
lrwxrwxrwx 1 root root 21 Nov 1 08:37 phpmyadmin -> /usr/share/phpmyadmin
but trying to get http://www.example.com/phpmyadmin => I get a 403 Forbidden
using a symlink, I should not have to add anything related to phpmyadmin into my nginx.conf ... what could be missing ?
Update 1 : adding index.php to the uri brings the login panel
http://www.example.com/phpmyadmin/index.php
what should I add to my default con file to get it directly ... I guess my try file is not valid ..
here is my default nginx site con file
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/html;
index index.php, index.html index.htm;
server_name example.com;
location / {
try_files $uri $uri/ index.html index.php =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
it's running fine after adding the following location :
location /phpmyadmin {
index index.php;
}
That's my solution for this issue:
Step 1: You should SSH and run command
sudo nano /etc/nginx/sites-available/default
Step 2: find block code
server {
....
}
and then insert before "}" of server block
location /phpmyadmin {
index index.php;
}
It look like this
server{
...(your default)...
location /phpmyadmin {
index index.php;
}
}
Hope this is your!
I have added:
location /pma/ {
alias /usr/share/phpmyadmin/;
index index.html index.htm index.php;
location ~ ^/pma(.+\.php)$ {
alias /usr/share/phpmyadmin$1;
fastcgi_pass unix:/var/run/php5-fpm.sock; #OR fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin$1;
include fastcgi_params;
fastcgi_intercept_errors on;
}
}
So that when the user access the directory /pma/ they get directed to the /usr/share/phpmyadmin which is a slightly 'safer' option too! As previously I was having the 403 error too!
But the main fix for the 403 error is actually implementing the line:
index index.html index.htm index.php;
to nginx.conf file or default ( ../sites-available/default )
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
Here are a couple things you could try. One is the disable_symlinks directive:
location /phpmyadmin {
disable_symlinks off;
}
Another option would be to use an alias instead of a symlink:
location /phpmyadmin {
alias /usr/share/phpmyadmin;
}
Lose the comma and you're fine
index index.php, index.html index.htm;
I'm setting up nginx with php5-fpm on Ubuntu 12.04LTS for wordpress and phpMyAdmin.
My phpMyAdmin locates in/var/www/phpMyAdmin, wordpress in /home/user/workspace/wordpress, MySQL at /var/run/mysqld/mysqld.sock
I want to map / to wordpress, /phpmyadmin to phpMyAdmin, so how can I achieve this??
Wordpress seemed OK, but when accessing /phpmyadmin, the browser "downloads" the request as files...??
This is my current nginx.conf:
server {
listen 8000;
root /home/user/workspace/wordpress;
index index.html index.htm index.php;\
location ~* /phpmyadmin { #TODO: shall here be a tailing slash??
#TODO: root or alias???
}
location ~ \..*/.*\.php$ {
return 403;
}
location / {
#TODO: show the following line be un-commented??
#try_files $uri $uri/ /index.php?q=$uri&$args;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
fastcgi_intercept_errors on;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;#TODO: could this being removed??
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
#FIXME: and how to block all access to /home/user/workspace/wordpress/server.d/*
#This doesn't work??
location /sever\.d {
autoindex on;
deny all;
}
And, what permission should I set for both the directory wordpress/ and phpMyAdmin/ if all the servers are running as www-data:www-data??
Currently I set them as 755 user:www-data, is that correct??
I haven't set up server under linux yet, I was using those servers under WinXP, so I'm trying.
in you between location add this
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
anywhere between
also
your missing a server name. type in a server_name example.com;
I installed Icinga 1.6.0beta and tried to install it's new web interface using this manual. But it was written for Apache. So I used the following configuration file for nginx to run the interface, but no success. I get directory listing denied in error logs. Any help?
Note: /data/developers/icinga-web symlinked to /usr/local/icinga-web
server {
server_name developers.example.com;
access_log /var/log/nginx/dev.access.log;
error_log /var/log/nginx/dev.error.log;
root /data/developers;
location / {
index index.html index.htm index.php;
}
location /icinga-web/js/ext3/ {
alias /usr/local/icinga-web/lib/ext3/;
}
location /icinga-web/ {
if (!-e $request_filename) {
rewrite ^(/icinga-web)(/.*)$ /icinga-web/index.php?$2 last;
}
}
try_files $uri $uri/ /icinga-web/index.php?$args;
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_split_path_info ^(/icinga-web)(/.*)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}
}
I ran into the same problem. I had to put the following line:
security.limit_extensions = .php .php5 .cgi
Into the php-fpm pool configuration file.
Of course, after I put that, I now get the following line error:
Parse error: syntax error, unexpected '<' in /usr/local/icinga/sbin/tac.cgi on line 313
But hey, progress!
Ran into almost the same problems years later, better late than never. (I marked the variables you have to set yourself with " % ")
location #icinga {
include fastcgi.conf;
fastcgi_temp_path fastcgi;
fastcgi_pass %YOUR_SOCKET%;
fastcgi_param SCRIPT_NAME /icingaweb2/index.php;
fastcgi_param SCRIPT_FILENAME %ICINGA_WEB_LOCATION%/index.php;
fastcgi_param ICINGAWEB_CONFIGDIR %ICINGA_CONFIG_DIR%;
}
location /icingaweb2 {
alias %ICINGA_WEB_LOCATION%/public;
try_files $uri #icinga;
}