How to grant nginx permissions to phpMyAdmin on synology diskstation - nginx

I have a Synology Diskstation DS216se running DSM 6.2.3-25426. I've installed MariaDB 10, Web Station, PHP 7.2, and myPhpAdmin, but when I open it at http://diskstation/phpMyAdmin/ I get this error message
"Sorry, the page you are looking for is not found."
I'm using an nginx server in Web Station, and the error log at /var/log/nginx/error.log contains multiple entries like the following
*621 open() "/var/services/web/phpMyAdmin/js/vendor/jquery/jquery.debounce-1.0.5.js" failed (13: Permission denied)
The file, and all other files with permission denied entries in the logs, exist in the /var/services/web/phpMyAdmin/ directory - what permissions need to be granted to the directory for this to succeed?

I hit this as well. I managed to recover, but it effectively amounts to hard clearing any evidence of prior installs of Web Station, PHP 7.2, phpMyAdmin, and any other web related services. Then manually ripping out some bad directories with broken symlinks/permissions.
My hypothesis is that I tried to install adminer prior to this and - having not done any set up for Web Station et. al. - it put the filesystem in a bad state.
I am not willing to try installing adminer again to test this hypothesis.
What I did to fix this:
Backup what you need (e.g., any personal web site).
SSH into your diskstation. Please be aware of what you are doing and keep in mind the big picture. Don't go deleting random things.
Uninstall Web Station, PHP 7.2, Apache, phpMyAdmin, etc. Anything that Web Station would ultimately be inclined to read and serve up.
Verify that /var/services/web doesn't contain anything you care about, and delete it (sudo rm -rf /var/services/web).
Verify that /volume1/web doesn't contain anything you care about, and delete everything inside it (sudo rm -rf /var/services/web). You may need to chmod permissions for this - I ended up leaving the web directory itself intact, but nothing inside.
Reboot. Mount any encrypted disks, etc.
Check that /var/services/web now shows it is symlinked to /volume1/web, e.g. sudo readlink -e /var/services/web.
Also check permissions for /volume1/web, e.g. ls -al /volume1. It should be owned by root:root and have permissive (777) bits.
Install Web Station, PHP 7.2, and phpMyAdmin in that order.
After this, I could open phpMyAdmin and be served its log in screen.
Debugging notes:
For me, when I SSH in I see in the logs similar issues:
2020/12/17 10:36:35 [error] 32658#32658: *1028 "/var/services/web/phpMyAdmin/index.php" is forbidden (13: Permission denied),
ps says that the nginx workers run as the http user (uid=1023(http) gid=1023(http) groups=1023(http)).
The directory /var/services/web/ appears to be owned by root, both group and user:
# ls -al /var/services/web/
total 424
drwxr-xr-x 3 root root 4096 Dec 17 10:29 .
drwxr-xr-x 3 root root 4096 Dec 17 10:22 ..
-rw-r--r-- 1 root root 27959 Apr 13 2016 adminer.css
-rw-r--r-- 1 root root 82 Apr 13 2016 .htaccess
-rw-r--r-- 1 root root 387223 Apr 13 2016 index.php
drwxr-xr-x 10 root root 4096 Dec 17 10:29 phpMyAdmin
It's not clear to me how Web Station's nginx is intended to work at all given the mismatch - perhaps some set of actions I took prior caused it to decide to install with bad ownership.
I decided to leave everything owned by root, but changed group permissions so that http can access:
# chown -R root:http /var/services/web/
# chmod -R 775 /var/services/web/
This got past the initial error, but revealed a new one:
"/usr/syno/synoman/phpMyAdmin/index.cgi" is not found (2: No such file or directory)
Indeed, there was no trace of phpMyAdmin anywhere in that directory. Evidence of a bad install.
I decided to uninstall anything web related: phpMyAdmin, PHP 7, Apache (happened to be installed), nginx, and Web Station. Once I did, I still had two files in /var/services/web: adminer.css index.php.
I had tried adminer prior to this. In /var/services, there were symlinks to specific volume locations, e.g.:
# ls -al /var/services/
total 12
drwxr-xr-x 3 root root 4096 Dec 17 10:22 .
drwxr-xr-x 17 root root 4096 Dec 17 10:21 ..
lrwxrwxrwx 1 root root 18 Jan 20 2020 download -> /volume1/#download
lrwxrwxrwx+ 1 root root 14 Dec 17 10:22 homes -> /volume1/homes
lrwxrwxrwx 1 root root 24 Jan 20 2020 pgsql -> /volume1/#database/pgsql
lrwxrwxrwx 1 root root 13 Dec 17 10:22 tmp -> /volume1/#tmp
lrwxrwxrwx 1 root root 13 Dec 17 10:22 web
Interestingly, web was not symlinked. I fully deleted /var/services/web.
Looking over at /volume1, I do see a /volume1/web, again fully owned by root but with extremely constrained permission:
d---------+ 1 root root 52 Dec 17 10:14 web
There are only a few things in here, which look related to a blank install of Web Station. I fully deleted everything within /volume1/web, but left it as is. With everything maximally cleaned I rebooted.
Upon boot, /var/services/web was now symlinked to /volume1/web, which now also had useful permission bits (777), and owned by root:root. Maybe this was done by some boot recover process, who knows. (I still have nothing web related installed at this point.)
I installed Web Station, then PHP 7.2, then phpMyAdmin.

I had the same issue when accessing my server via
<name>.local/phpMyAdmin/
It worked when I accessed it via
<local ip>/phpMyAdmin/

Related

Issue: nginx: [emerg] mkdir() "/var/cache/nginx/client_temp" failed (13: Permission denied)

I am trying to run Nginx on Openshift but facing this directory permissions issues. Due to this error container is not creating.
The following permissions are set to files created manually.
drwxr-xr-x. 3 root root 79 Dec 22 02:50 /etc/nginx
drwxr-xr-x. 2 root root 26 Dec 22 02:50 /etc/nginx/conf.d
-rw-r--r--. 1 root root 5231 Dec 22 02:48 /etc/nginx/mime.types
drwxrwxr-x. 3 root root 25 Dec 22 01:23 /var/cache/nginx
drwxrwxr-x. 2 root root 6 Dec 22 01:10 /var/log/nginx
drwxrwxr-x. 47 root root 1340 Dec 21 06:51 /var/run
like #dbaker mentioned, RedHat being a security company makes their decisions in openshift regarding security more serious or aggressive as one might say, like for example running containers by default with running with random UID's.
you can fix that by reassigning the paths for different Nginx uses.
changing the PID location:
pid /tmp/nginx.pid;
changing the client temp location (your issue):
client_body_temp_path /tmp/nginx/client_temp
and any other paths in a similar fashion.
you can also use the unprivileged nginx image from docker hub aside from the image specified in the other answer from by RedHat as a certified image, ones that should play more nicely with RedHat products oriented towards security. as the other image is due to being deprecated I'm including the other tag recommended by RedHat rhscl/nginx-120-rhel7
Which specific container image are you trying to run? If you use this one -- https://catalog.redhat.com/software/containers/ubi8/nginx-120/6156abfac739c0a4123a86fd -- it will play nicer with OpenShift out of the box.
This sort of problem is almost always due to OpenShift running containers as non-root by default. If you change file permissions to permit write access to GROUP=0 you'll resolve nearly all of them.

404 Errors for files uploaded via SFTP on a Wordpress running on a Google Compute Engine Virtual Machine

I am running a Wordpress Install (OpenLiteSpeed) in a Google Cloud Compute VM running Ubuntu
I can access the main folder of Wordpress via web browser by typing in the static IP - but I cannot access individual files and/or folders on my machine via web browser.
I would like to share files by posting links to files located in on the VM, Wordpress install folder.
How can I do that?
My permissions of the folder inside the worpress install are:
thisisme#wordpress-vm:~$ ls -la /var/www/html/myFolder
total 432
drwxrwxrwx 2 thisisalsome thisisalsome 4096 Mar 21 09:39 .
drwxr-xr-x 6 thisisalsome users 4096 Mar 21 09:59 ..
-rwxrwxrwx 1 thisisalsome thisisalsome 433790 Mar 21 09:02 pic.jpg
You need to move the /var/www/myFolder folder into the /var/www/html folder and access files by hostname/myFolder/myFile.zip or to configure the webserver to serve your myFolder under a different dns.
That is probably because your default webserver's configuration only serves files from the /var/www/html folder.
#Octavian
I did use the same capitalisation - but i just realised I made the mistake of using the wrong access path - i was typing
xx.xx.xxx.xxx/html/myFolder/pic.jpg
but I should have used
xx.xx.xxx.xxx/myFolder/pic.jpg
AND NOW IT WORKS !! Thanks for pointing that out for me! I did not know UNIX servers are case sensitive!! :) Thanks For Your Help!

nagios core on centos (nginx) starts correctly but cant read any hosts or services

guys i have looked and searched and read. yum update changed a permission somewhere but cant find where. Nagios on centos starts correctly i can view the page but for some reason i dont see any hosts or services, only 403 forbidden in the corner.
ive checked my nagios.cfg and no errors or warnings. I have started Nagios as daemon, same. Any other suggestions ?
total 160
drwxrwxr-x 5 root root 4096 May 7 18:14 .
drwxr-xr-x. 78 root root 4096 May 8 22:38 ..
-rw-rw-r-- 1 root root 11339 Sep 23 2014 cgi.cfg
-rw-rw-r-- 1 root root 11658 Aug 30 2013 cgi.cfg.rpmnew
drwxr-x--- 5 root nagios 4096 Aug 30 2013 conf.d
-rw-rw-r-- 1 root root 43443 Oct 2 2014 nagios.cfg
-rw-rw-r-- 1 root root 44533 Aug 30 2013 nagios.cfg.rpmnew
-rw-r--r-- 1 root root 960 Jul 24 2016 nrpe.cfg
-rw-r--r-- 1 root root 899 Mar 31 2015 nrpe.cfg.rpmsave
-rw-r--r-- 1 root root 5332 Feb 24 2015 nsca.cfg
drwxr-x--- 2 root nagios 4096 May 7 17:39 objects
-rw-r----- 1 root apache 27 Aug 30 2013 passwd
drwxr-x--- 2 root nagios 4096 May 7 18:14 private
-rw-r----- 1 root root 1340 Aug 30 2013 resource.cfg
-rw-r--r-- 1 root root 1628 Mar 20 2013 send_nsca.cfg
the check configuration :
Nagios Core 3.5.1
Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-30-2013
License: GPL
Website: http://www.nagios.org
Reading configuration data...
Read main config file okay...
Processing object config directory '/etc/nagios/conf.d'...
Processing object config directory '/etc/nagios/conf.d/servicegroups'...
Processing object config file '/etc/nagios/conf.d/servicegroups/jira-servers.cfg'...
Processing object config file '/etc/nagios/conf.d/servicegroups/routers-servers.cfg'...
Processing object config file '/etc/nagios/conf.d/servicegroups/ups-servers.cfg'...
Processing object config file '/etc/nagios/conf.d/servicegroups/backup-servers.cfg'...
Processing object config file '/etc/nagios/conf.d/servicegroups/clone-servers.cfg'...
Processing object config file '/etc/nagios/conf.d/servicegroups/perforce-servers.cfg'...
Processing object config file '/etc/nagios/conf.d/servicegroups/linux-servers.cfg'...
Processing object config file '/etc/nagios/conf.d/servicegroups/web-servers.cfg'...
Processing object config file '/etc/nagios/conf.d/hostgroups.cfg'...
Processing object config directory '/etc/nagios/conf.d/hosts'...
Processing object config file '/etc/nagios/conf.d/hosts/servers.cfg'...
Processing object config file '/etc/nagios/conf.d/hosts/test.cfg'...
Processing object config file '/etc/nagios/conf.d/hosts/diskstation.cfg'...
Processing object config file '/etc/nagios/conf.d/hosts/clone-servers.cfg'...
Processing object config file '/etc/nagios/conf.d/hosts/wifi.cfg'...
Processing object config file '/etc/nagios/conf.d/hosts/cloud.cfg'...
Processing object config file '/etc/nagios/conf.d/hosts/perforce-servers.cfg'...
Processing object config file '/etc/nagios/conf.d/hosts/printers.cfg'...
Processing object config file '/etc/nagios/conf.d/hosts/switches.cfg'...
Processing object config file '/etc/nagios/conf.d/contacts.cfg'...
Processing object config directory '/etc/nagios/conf.d/commands'...
Processing object config file '/etc/nagios/conf.d/commands/notifications.cfg'...
Processing object config file '/etc/nagios/conf.d/commands/perfdata.cfg'...
Processing object config file '/etc/nagios/conf.d/commands/checks.cfg'...
Processing object config file '/etc/nagios/conf.d/commands/nrpe.cfg'...
Processing object config file '/etc/nagios/conf.d/templates.cfg'...
Read object config files okay...
Running pre-flight check on configuration data...
Checking services...
Checked 124 services.
Checking hosts...
Checked 23 hosts.
Checking host groups...
Checked 8 host groups.
Checking service groups...
Checked 8 service groups.
Checking contacts...
Checked 1 contacts.
Checking contact groups...
Checked 1 contact groups.
Checking service escalations...
Checked 0 service escalations.
Checking service dependencies...
Checked 0 service dependencies.
Checking host escalations...
Checked 0 host escalations.
Checking host dependencies...
Checked 0 host dependencies.
Checking commands...
Checked 27 commands.
Checking time periods...
Checked 1 time periods.
Checking for circular paths between hosts...
Checking for circular host and service dependencies...
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
finally what i see :
what is see
thanks in advance.
Looks like your permissions are all messed up!
When you installed it.. was it from source? If so, did you use the --with-nagios-user= flag during ./configure?
On one of my boxes I have a combination of apache and nagios as the /usr/local/nagios owners. Try this:
chown -R nagios:nagios /usr/local/nagios
chown -R apache:nagios /usr/local/nagios/etc
chmod +x -R /usr/local/nagios/bin /usr/local/nagios/libexec
You'll also want to make sure that the nagios user and group is set in the main configuration file (/usr/local/nagios/etc/nagios.cfg), like this:
nagios_user=nagios
nagios_group=nagios
Also, did you remember to set up your htpasswd file?
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Anyway, hope this helps get you started!

phpmyadmin complains about permissions and open_basedir - but they all appear correct

phpmyadmin has been installed and working fine for months, installed via this repo:
deb http://ppa.launchpad.net/tuxpoldo/phpmyadmin/ubuntu utopic main
Suddenly, I couldn't login; no in-page errors but the logs showed:
PHP message: phpmyadmin: Failed to load /etc/phpmyadmin/config-db.php Check group www-data has read access and open_basedir restrictions"
PHP message: phpmyadmin: Failed to load /var/lib/phpmyadmin/config.inc.php Check group www-data has read access and open_basedir restrictions"
So, I checked:
ll /etc/phpmyadmin
drwxrwxr-x 3 www-data www-data 4096 Nov 16 20:11 ./
drwxr-xr-x 132 root root 12288 Nov 17 15:33 ../
-rw-r----- 1 www-data www-data 549 Nov 16 20:11 config-db.php
and
ll /var/lib/phpmyadmin
drwxr-xr-x 4 www-data www-data 4096 Oct 8 15:51 ./
drwxr-xr-x 62 root root 4096 Nov 12 13:10 ../
-rw-r----- 1 www-data www-data 4478 Nov 16 19:48 config.inc.php
I followed this SO answer and changed the user and group permissions to match the example (user:root, group:www-data) and changed the directory permissions to match.
I double, triple checked that no open-basedir restrictions are in effect, and I checked phpinfo()
I tried changing the permissions to be that of the fpm worker pool.
I rebooted.
I did an sudo apt-get install --reinstall phpmyadmin.
The ONLY thing I've done inbetween is to follow this guide to installing freePBX, and 90% of what it wanted was on my machine anyway; only things like sqlite were installed, and I can't even be sure it was that which stopped it working. Long shot, but perhaps worth mentioning.
Everything else, all other sites etc, are running fine. Before I lose any more hair than I have done in the last 5 hours, I'd really appreciate some ideas. Thanks!
Turns out this is a rather misleading message from phpmyadmin:
Check group www-data has read access and open_basedir restrictions.
But anyone running multiple sites, using php-fpm and concerned at all about security will have separate pools for each site.
The solution, in my particular case was:
chown -R phpma:phpma /var/lib/phpmyadmin
chown -R phpma:phpma /etc/phpmyadmin
chown -R phpma:phpma /usr/share/phpmyadmin
Then sudo dpkg-reconfigure -plow phpmyadmin
Incidentally, it appears that doing a package install on Ubuntu splatters files all over the place, and it goes a little something like this:
/etc/phpmyadmin/config.inc.php
includes the following files in this order, which really won't need touching unless you want to up the login cookie validity.
/var/lib/phpmyadmin/blowfish_secret.inc.php // self explanatory
/var/lib/phpmyadmin/config.inc.php // LoginCookieValidity etc
/etc/phpmyadmin/config-db.php // Leave this one alone
/usr/share/phpmyadmin/config.inc.php // auth, host, connection etc
I hope this helps someone else at any rate.
This is certainly due to the fact you are using mpm_itk_module.
If yes, you have to use in your apache settings :
<ifmodule mpm_itk_module>
AssignUserId myuser www-data
</ifmodule>
instead:
<ifmodule mpm_itk_module>
AssignUserId myuser myuser
</ifmodule>
phpmyadmin need group www-data, and if you use AssignUserId, with another group it fails off course.
And you can add to you apache config in "Directory":
php_admin_value open_basedir "/home/yourpath/htmldir:/etc/phpmyadmin:/var/lib/phpmyadmin"
Replace /home/yourpath/htmldir by your own web dir.
I hope this help

SQLite3: Unable to Open Database

I've been attempting to figure out this problem for quite some time and have looked at all the normal solutions. I am attempting to run a .backup on an sqlite database. I don't think it matters, but this particular database is being used by Membase and is also running on the Amazon cloud. Both the folder that I am backing up to, and the folder that the database is coming from has 777 permissions (which is the normal cause of this message). If I sudo the backup command, it gets partway through the backup and then the process just hangs while consuming CPU usage and leads me to eventually kill the sqlite process. I even went through and chmod 777 the database file itself.
Here is whats happening:
/opt/membase/bin/sqlite3 /mnt/data-store/default-data/default-0.mb '.backup /mnt/data-backup/mbfiles/test.mb'
Error: unable to open database file
When I ls -la the folder:
drwxrwxrwx 2 membase membase 4096 Sep 10 15:41 .
drwxrwxrwx 4 membase root 4096 Aug 5 01:10 ..
-rw-r--r-- 1 membase membase 53248 Sep 10 15:41 default
-rwxrwxrwx 1 membase membase 849593344 Sep 10 15:41 default-0.mb
And the backup folder:
drwxrwxrwx 2 ec2-user ec2-user 4096 Sep 10 15:41 .
drwxrwxrwx 4 root root 4096 Sep 3 00:26 ..
Also, because I hear it matters, the permission of /tmp
drwxrwxrwt 3 root root 4096 Sep 10 03:32 .
I've been trying to fix this for over a week now, and any new ideas would be appreciated. It should be noted that this is a production environment so restarting is not an option.
EDIT: I checked and I can back up the smaller "default" file, just not the larger db, so this rules out any sort of issue with folder permissions. Any help would be hugely appreciated.
Thanks!
This seems like an sqlite issue. We've seen sporadic occurrences of this error at other customers but have not been able to track it down or resolve it yet. According to the sqlite experts, this should never happen ;-)
Can you shutdown the Membase process to test further? If so, trying to take a backup (make sure the 'memcached' process is stopped) at this point would rule out any issue with software accessing the file. If it still doesn't work at this point, I know there are tools to verify a sqlite DB (just don't have them off the top of my head).
You can also use a combo of ".dump" and ".restore" via sqlite, but I wouldn't recommend running that on a running Membase node as we haven't tested out the effects.
Perry

Resources