1
votes

Dockerfile

FROM php:5.6-apache
COPY config/php.ini /usr/local/etc/php/
RUN docker-php-ext-install mysql mysqli pdo pdo_mysql
RUN rm /var/log/apache2/access.log
RUN a2enmod rewrite
RUN a2enmod deflate
RUN a2enmod headers

docker-compose.yml

version: "2"
services:
  www:
    build: .
    ports: 
        - "8001:80"
    volumes:
        - ./www:/var/www/html/
    networks:
        - default

I have a folder within www that's called photos. It's at www/photos. I want to write files to it using my php upload function. I'm getting permission denied errors due to the fact that php-apache doesn't have write access to the volume. How to give apache write access?

1
Can you share which exact directory your php code is referring, as inside the docker container, the volume with be named as /var/www/html and not not /wwwAman Chhabra
The file writing to disc is at docker-container: /var/www/html/controllers/file.phpTim Daubenschütz

1 Answers

0
votes

Check the permissions of the directory on your host system, maybe guests do not have permissions to write. If necessary, change them using chmod:

chmod 766 -R your/directory/

Also, you can specify the permission to write inside your docker in a specified mounted volume by adding :rw (for read/write) at the end of the line:

- ./www:/var/www/html/:rw

Since this should be the default value it is not necessary to use it and should not be part of your problem.