+1
Yes, this problem was discussed at length under 'How to ensure I "own" everything -Ubuntu Moodle install' https://moodle.org/mod/forum/discuss.php?d=246408.
+ see that notes and the end of the Installing_Moodle page about what to do if it goes wrong Have you (the OP I mean) done that stuff?