title: Docker php apache permission denied
body: <p>I'm working on configuring a docker setup for an old php project with apache, php 7.2 and mariadb. After I got the container up and running I get permission denied when I try to write a file from php.</p>
  <p>What is the best approach to solve this?</p>
  <p>docker-compose.yml</p>
  <pre><code>version: &quot;3&quot;
  
  networks:
    dirtbike:
  
  services:
    webserver:
      build:
        context: .
        dockerfile: Dockerfile
      container_name: dirtbike-webserver
      restart: 'always'
      depends_on:
        - database
      ports:
        - &quot;80:80&quot;
        - &quot;443:443&quot;
      networks:
        - dirtbike
      volumes:
        - ./public_html:/var/www/html
    database:
      image: mariadb:10.3
      container_name: dirtbike-database
      restart: 'always'
      networks:
        - dirtbike
      ports:
        - &quot;127.0.0.1:3306:3306&quot;
      environment:
        MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
        MYSQL_DATABASE: ${MYSQL_DATABASE}
        MYSQL_USER: ${MYSQL_USER}
        MYSQL_PASSWORD: ${MYSQL_PASSWORD}
  </code></pre>
  <p>Dockerfile</p>
  <pre><code>FROM php:7.2-apache-stretch
  
  RUN docker-php-ext-install pdo_mysql
  
  RUN a2enmod ssl &amp;&amp; a2enmod rewrite &amp;&amp; a2enmod headers
  RUN mkdir -p /etc/apache2/ssl
  COPY ./Docker/ssl/*.pem /etc/apache2/ssl/
  
  COPY ./Docker/config/apache/dirtbike.conf /etc/apache2/sites-available/000-default.conf
  </code></pre>
  <p>index.php</p>
  <pre><code>&lt;?php
  
  file_put_contents(__DIR__.DIRECTORY_SEPARATOR.'test.txt', 'lorem ipsum');
  
  </code></pre>