I'm building a PHP/Docker web application. I have an HTML form where a user can upload an image and it will be stored into a local directory. I am using the W3Schools file upload example.
However, I'm getting a Permission Denied error when trying to upload via the form: Warning: move_uploaded_file(image/listingsorchid.jpg): failed to open stream: Permission denied in /var/www/html/process-listing.php on line 59.
I am using the php-docker-simple_php image. I used docker exec -it 9381479b00e6 sh and whoami to confirm the image is running as root. file_uploads = On is enabled in my local php install.
My Dockerfile looks like this:
FROM php:7.4-apache
RUN docker-php-ext-install mysqli
And my docker-compose looks like this:
version: '3.1'
services:
php:
build:
context: .
dockerfile: Dockerfile
ports:
- 80:80
volumes:
- ./src:/var/www/html/
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: example
volumes:
- mysql-data:/var/lib/mysql
adminer:
image: adminer
restart: always
ports:
- 8080:8080
volumes:
mysql-data:
A user in this thread suggested creating an uploads.ini that would set file_uploads = On and including that in the Dockerfile. I've created an uploads.ini, but I'm unsure how to implement this into my Dockerfile or if it would work.
What should I do to resolve this error?