Closed elpado closed 2 months ago
You will need to ensure that the user that Unit is running as has permissions to create the directory. mkdir(2) needs write permission on the parent directory.
Thanks for the quick reply :)
I have now simply set up a small test container and tested it with the following configuration - and it now works. I am now trying to use the same configuration for the actual project and hope that there are no more problems.
Dockerfile
FROM unit:php8.3
WORKDIR /opt/app
RUN mkdir /data-store && chown -R unit:unit /data-store
COPY ./config.json /docker-entrypoint.d/config.json
COPY ./index.php /opt/app/public/index.php
config.json
{
"listeners": {
"*:80": {
"pass": "routes"
}
},
"routes": [
{
"match": {
"uri": "!/index.php"
},
"action": {
"share": "/opt/app/public$uri",
"fallback": {
"pass": "applications/data-exchange"
}
}
}
],
"applications": {
"data-exchange": {
"type": "php",
"root": "/opt/app/public/",
"script": "index.php",
"user": "unit",
"group": "unit"
}
}
}
index.php
<?php
$exchangeDirectory = '/data-store/' . date('Y-m-d');
echo sprintf('Check directory exists %s ... ', $exchangeDirectory);
if (!is_dir($exchangeDirectory)) {
echo sprintf('not found - will create %s ... ', $exchangeDirectory);
mkdir($exchangeDirectory, 0777, true);
}
echo 'done';
Looks like you've got it sussed. Closing this now. Feel free re-open if required.
Hello dear developers,
I would like to test Unit for a small PHP project. I use the Docker Image with PHP 8.3 installed.
The code of the application is stored within the container under "/mnt/code/". But I have a, let's call it, data exchange directory. This directory lives outside of my application root.
My application need to create new folders and files in that exchange directory.
My config.json looks like this:
But when I try to create a new directory or file in the exchange folder, I receive a permission denied :(
It's the very first time I'm trying to use Unit for one of my applications. I've also tried changing my configuration and adding a user/group - but to no success.
Is there something I have overlooked?