0

I get the Permission denied error every time I try to write a file to (/var/lib/mysql-files) directory with http, but if I restart apache and/or MySQL I can write to that directory with no errors, but only one time, so if I try to write a second file I will get that error, and I have to restart apache again and so on.

This is the ownership and the permissions that i gave that directory:

  groupadd mysql_apache
  usermod -a -G mysql_apache mysql
  usermod -a -G mysql_apache apache
  chown -R :mysql_apache /var/lib/mysql-files
  chmod -R 770 /var/lib/mysql-files

I want to give the rights to read; write; execute on this dir (/var/lib/mysql-files) only to MySQL and apache, What did I do wrong here?

PS: This is on CentOs 8.

gouyez
  • 93
  • 1
  • 2
  • 7
  • can't you use another folder that isn't in var\lib – nbk Dec 12 '20 at 00:50
  • 1
    Sounds like a massive [XY problem](https://en.wikipedia.org/wiki/XY_problem). What do you actually want to achieve here? – sticky bit Dec 12 '20 at 00:59
  • @nbk I am afraid not, as i am not the only one working on that server, i can't change that directory – gouyez Dec 12 '20 at 01:11
  • @stickybit I want to import csv files into MySQL with "LOAD DATA INFILE", i have a php script (that i run through the web Not CLI), this script creates the csv file and move it to (/var/lib/mysql-files) that's when i get the Permission denied error, the weird thing is that i can do this successfully if i restart apache, but only one time, if i want to do it again i need to restart apache before running the script – gouyez Dec 12 '20 at 01:20
  • i am bit worried about security, – nbk Dec 12 '20 at 10:28
  • @nbk unfortunately it does not, i don't want to grant any permissions to a file as it will be a random name every time (for security reasons) – gouyez Dec 12 '20 at 12:43
  • you see in the answer, which user must have the access so use that information – nbk Dec 12 '20 at 13:08
  • I already did that, it doesn't work, i need to know why are the ownership and the permissions that i've granted to those users are only effective when i restart mysql and/or apache and for one time only, i have to restart one of those services every time i want to write to that folder. I think the problem is something other than the permissions and ownership of the folder – gouyez Dec 12 '20 at 13:31
  • Is there any good reason to write to such a folder? – Nico Haase Dec 19 '20 at 13:23

1 Answers1

0

We moved to Ubuntu 20.04 since CentOs 8 EOL changed to 2021, and I didn't have this problem in Ubuntu.

gouyez
  • 93
  • 1
  • 2
  • 7