6

I'm trying to create a workflow in docker. It's simple: just PHP and MySQL to little tests.

My docker-compose.yml:

web:
  build: .docker
  links:
    - mysql:mysql
  ports:
    - "80:80"
    - "443:443"
  volumes:
    - ./public_html:/var/www/html
mysql:
  image: mysql:5.7
  environment:
    - MYSQL_ROOT_PASSWORD=root
  volumes:
    - "./.data/db:/var/lib/mysql"
phpmyadmin:
  image: phpmyadmin/phpmyadmin
  ports:
    - "8080:80"
  links:
    - mysql:mysql
  environment:
    - PMA_HOST=mysql
  volumes:
    - /sessions

And my Dockerfile:

FROM php:5.6-apache

RUN docker-php-ext-install mysqli

It's all ok: I can up containers but PHP itself cannot write in directories (like fwrite() or similar).

I researched a lot and tried a lot of tutorials, but nothing...

2
  • can you show me your php Dockerfile? i think its caused by a permission issue. Commented Oct 4, 2016 at 6:19
  • I guess you are write @Gabbax0r but I'm new in Linux... My Dockerfile is already in question and points to php5.6-apache in HUB. Commented Oct 5, 2016 at 1:42

1 Answer 1

10

Apache runs PHP with the user www-data, this user needs to have write access on your host directory ./public_html

To fix that, go to your docker-compose directory and execute the following command to change the owner of your public_htmldirectory and all files inside.

sudo chown -R www-data:www-data public_html

After that you need to allow users in the group "www-data" to edit files

# To change all the directories to 775 
# (write for user & group www-data, read for others):
find public_html -type d -exec chmod 775 {} \;

# To change all the files to 664
# (write for user & group www-data, read for others):
find public_html -type f -exec chmod 664 {} \;

In order for your current user to edit these files you need to add it to the www-data group :

sudo usermod -aG www-data $USER
Sign up to request clarification or add additional context in comments.

2 Comments

It's chown -R
I just delete everything and tried to create a new repository with your solution and worked. Thank you @ChVuagniaux

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.