14 Replies - 810 Views - Last Post: 14 April 2018 - 04:31 PM

#1 LinuxProg   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 11-April 18

LEMP phpMyAdmin 403 and 404 error

Posted 11 April 2018 - 09:24 AM

So I have LEMP stack installed with phpMyAdmin all the latest updates on Ubuntu 16.04. I'm trying to use phpMyAdmin but when I do navigate to /phpmyadmin/ in my browser I get 403 Forbidden and when I do my /pma/ I get 502 Bad Gateway. Everywhere I search setting "index" makes this problem go away but it doesnt work for me. I'm just trying to test a PHP site that uses mySQL databases on my local machine. When I navigate to any other part of the site it works including the PHP. Here is my sites-available file:

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

	#Create access and error logs in /var/log/nginx
	#access_log /var/log/nginx/testsite.access_log main; 
	error_log /var/log/nginx/testsite.error_log info; 

	root /var/www/testsite;
	index index.php index.html;
	server_name testsite.com;
	location / {
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
		try_files $uri $uri/ =404;
	}

	#Specifies that Nginx is looking for .php files
	location ~ \.php$ { 
		#try_files $uri =404;
		#Include Nginx’s fastcgi configuration
		#include /etc/nginx/fastcgi.conf;
		include snippets/fastcgi-php.conf;
		#Look for the FastCGI Process Manager at this location 
		fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
		
		include fastcgi_params;
		fastcgi_split_path_info ^(.+\.php)(/.+)$;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
	} 

	location /pma/ {
    		alias /usr/share/phpmyadmin/;

    		index index.php index.html index.htm ;

		location ~ ^/pma(.+\.php)$ {
        	alias /usr/share/phpmyadmin$1;
        	fastcgi_pass unix:/var/run/php7-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;
    		}
	}

	location ~ /\.ht {
		deny all;
	}

}


Anybody know how to get phpMyAdmin working on the Ubuntu 16.04 LEMP stack and what I need to change?

Is This A Good Question/Topic? 0
  • +

Replies To: LEMP phpMyAdmin 403 and 404 error

#2 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6822
  • View blog
  • Posts: 31,459
  • Joined: 10-May 07

Re: LEMP phpMyAdmin 403 and 404 error

Posted 11 April 2018 - 01:05 PM

Who owns the /phpmyadmin/ directory? Do you have SELinux running? If so, did you properly re-label the directory & the files after installation?

Since your document root for the webserver is configured as /var/www/testsite, why are you trying to access a directory outside of that directory?

If this were me, I would make a symbolic link from /usr/share/phpmyadmin to /var/www/testsite/phpmyadmin/ & place that within the config, restart the server. Also, taking any corrective action based on my previous comment about directory:file ownership & SELinux labelling.
Was This Post Helpful? 1
  • +
  • -

#3 LinuxProg   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 11-April 18

Re: LEMP phpMyAdmin 403 and 404 error

Posted 11 April 2018 - 09:36 PM

Well I only have one account installed on the machine and I always have to use "sudo gedit filename" to edit the files. I'm new to Linux. Is there a permission I need to set somewhere?
Was This Post Helpful? 0
  • +
  • -

#4 LinuxProg   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 11-April 18

Re: LEMP phpMyAdmin 403 and 404 error

Posted 11 April 2018 - 09:47 PM

When I go to properties all the files say root. I had my symbolic link link to /etc/phpmyadmin/ rather than /usr/share/phpmyadmin/

Replaced it with proper symlink and now localhost/phpmyadmin/ works but I still get 502 bad gateway for /pma/
Was This Post Helpful? 0
  • +
  • -

#5 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6822
  • View blog
  • Posts: 31,459
  • Joined: 10-May 07

Re: LEMP phpMyAdmin 403 and 404 error

Posted 12 April 2018 - 07:55 AM

What user is your webservice running as? That's whom should own the directory & files.

Also, verify that SELinux is or is not running with : getenforce

Lastly, note that 502 is a processing error, where as 403/404 are access errors. Is it possible that phpmyadmin is not configured correctly?
Was This Post Helpful? 1
  • +
  • -

#6 LinuxProg   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 11-April 18

Re: LEMP phpMyAdmin 403 and 404 error

Posted 12 April 2018 - 11:28 AM

View Postno2pencil, on 12 April 2018 - 07:55 AM, said:

What user is your webservice running as? That's whom should own the directory & files.

Also, verify that SELinux is or is not running with : getenforce

Lastly, note that 502 is a processing error, where as 403/404 are access errors. Is it possible that phpmyadmin is not configured correctly?


When I run getenforce it says its not installed. What does that program do? Everything is running except my /pma/ alias is giving me the 502 error in the web browser. I only have one account on the machine and all the files that arent in my /home/ folder are read only unless I use "sudo" or nauculus to browse the files. I do have an encrypted home folder that decrypts when I enter the account password on boot. When I click properties it says root is the owner. I'm guessing root user and the administrator account are treated separately? How do I find out if its being run under root vs my us4r account?
Was This Post Helpful? 0
  • +
  • -

#7 LinuxProg   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 11-April 18

Re: LEMP phpMyAdmin 403 and 404 error

Posted 12 April 2018 - 12:22 PM

I'm using nginx server.
Was This Post Helpful? 0
  • +
  • -

#8 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6822
  • View blog
  • Posts: 31,459
  • Joined: 10-May 07

Re: LEMP phpMyAdmin 403 and 404 error

Posted 12 April 2018 - 01:30 PM

The nginx process is going to run as it's own user. Don't think of it as "/home/" type users. If you issue the following command, you can see what user the worker processes are running as ps aux | grep nginx. This user, most likely nginx, needs to own the phpmyadmin directory & files in order to access them. You do not, EVER want root to own a directory or files that you are server to the world, MUCH LESS phpmyadmin.

Also you can check the nginx log files for your 502 error.
Was This Post Helpful? 1
  • +
  • -

#9 LinuxProg   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 11-April 18

Re: LEMP phpMyAdmin 403 and 404 error

Posted 12 April 2018 - 03:05 PM

So how would nginx "own" the directories? How do I do that? I'm assuming you're correct about nginx running as the user for the worker process with the following displaying after I run the command you gave. On a side note do you have any resources you'd recommend that explains what worker and master processes are and what they are used for?

root     23725  0.0  0.0 125112  1476 ?        Ss   Apr11   0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 23726  0.0  0.1 125476  5064 ?        S    Apr11   0:00 nginx: worker process
www-data 23727  0.0  0.0 125476  3128 ?        S    Apr11   0:01 nginx: worker process
adminis+ 29860  0.0  0.0  21292   972 pts/0    S+   17:00   0:00 grep --color=auto nginx

Was This Post Helpful? 0
  • +
  • -

#10 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2411
  • View blog
  • Posts: 7,379
  • Joined: 15-January 14

Re: LEMP phpMyAdmin 403 and 404 error

Posted 12 April 2018 - 03:10 PM

The chown command will change file or directory ownership:

https://www.computer...unix/uchown.htm
Was This Post Helpful? 0
  • +
  • -

#11 LinuxProg   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 11-April 18

Re: LEMP phpMyAdmin 403 and 404 error

Posted 12 April 2018 - 03:43 PM

View PostArtificialSoldier, on 12 April 2018 - 03:10 PM, said:

The chown command will change file or directory ownership:

https://www.computer...unix/uchown.htm


So nginx is already set up as a user in my machine? Like this is the same as if I were switching it from root to a user named Admin or to a user named JohnDoe that I'd pick and type the password for on boot? Like I said I'm new to Linux and switched cause I heard its more secure than Windows so sorry if these are newbie questions.
Was This Post Helpful? 0
  • +
  • -

#12 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2411
  • View blog
  • Posts: 7,379
  • Joined: 15-January 14

Re: LEMP phpMyAdmin 403 and 404 error

Posted 12 April 2018 - 04:07 PM

Yes, it's a user, but it's probably set so that it can't log in like a regular user. Each user is also part of a group, which you can also specify when changing ownership, so files can have different permissions for the owner, group, and everyone. You should see an entry for nginx inside /etc/passwd.
Was This Post Helpful? 1
  • +
  • -

#13 LinuxProg   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 11-April 18

Re: LEMP phpMyAdmin 403 and 404 error

Posted 14 April 2018 - 01:42 PM

So having the site in a directory owned by nginx will make it more secure? How so specifically?
Was This Post Helpful? 0
  • +
  • -

#14 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6822
  • View blog
  • Posts: 31,459
  • Joined: 10-May 07

Re: LEMP phpMyAdmin 403 and 404 error

Posted 14 April 2018 - 01:59 PM

View Postno2pencil, on 12 April 2018 - 04:30 PM, said:

You do not, EVER want root to own a directory or files that you are server to the world, MUCH LESS phpmyadmin.


Root is the admin account, by hosting files owned by root, you are 1 step away from handing the keys to your server to the outside world. So you offer something that is harmless.
Was This Post Helpful? 1
  • +
  • -

#15 LinuxProg   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 11-April 18

Re: LEMP phpMyAdmin 403 and 404 error

Posted 14 April 2018 - 04:31 PM

Do you have any comprehensive resources for known Linux based nginx hacks and how to prevent them you could recommend?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1