Moodle is a bit tricky to work with. As said above by @anon42008019, the moodledata folder needs to be inside htdocs, so the last part of $CFG->dataroot needs to also be configured to /htdocs/moodledata instead of just /moodledata:
There’s a chance you may face an issue with the default session storage setting as well, in which case you also need to follow the steps here: