The problem
I'm trying to setup my developing environment using Docker for Windows for use with Wordpress. I'm using docker compose with a custom Dockerfile. This works perfectly on MacOS. Using the exact same docker setup on Windows though gets me these messages within Wordpress.Clearly, Worpress doesn't have the correct file permissions.
What I tried
1. Checking Docker for Windows settings and upgrading to WSL 2
I'm using the WSL 2 based engine now, which should give full root permissions to all the files on the system. I upgraded to WPL 2 as I was first using the Hyper-V- based backend (with of course the correct file permissions setup), I tried to fix the problems by upgrading. No luck.
2. Experimenting with chmod
and chown
First, I added chmod -R 777 /var/www/html/
to the Dockerfile. As far as I know, this should give all file permissions to root. It didn't have any effect. So maybe I'm using a different user? The command whoami
did give me root back though.
Maybe I did something wrong and the user is something else. So I added chown -R www-data:www-data /var
, as I saw www-data should be the default Docker user and group. No luck.
Just for the fun of it, I also tried chmod -R 777 /var/www/html/wp-content/uploads/
just to be more specific in the path. Interestingly, this gave me the error chmod: cannot access '/var/www/html/wp-content/uploads/': No such file or directory
. I did link the folders though and this works (I can see in the folder structure in IntelliJ the files indeed are in /var/www/html). The -R
option should make this recursive anyway, so it shouldn't matter.
3. Doing all this while the container is running
So maybe because the files were not yet present, I could not assign permissions. So I tried all this also when the container was actually running. Again, no luck.
4. Running as user root
First, I added user: root
to the service in my docker-compose.yml
. No Luck.
Then I added USER root
to the Dockerfile, just below FROM php:7.4-apache
. No luck.
5. Using the official Wordpress image
As you can see below, I'm using the apache image as a basis for my Dockerfile. I also tried using the wordpress:latest image directly from my docker-compose.yml
(omitting the entire Dockerfile) and I tried using FROM: wordpress:latest
on top of the Dockerfile. Both didn't change anything.
My files
By now, I tried every solution I could find on the internet and nothing works. Crazy thing, all this works fine under MacOS. Here are my docker files, I hope u guys can help me out here.
docker-compose.yml
services:
web:
build:
context: ./
dockerfile: .docker/Dockerfile
user: root
container_name: wolfpackvision.com
ports:
- "8080:80"
volumes:
- .:/var/www/html
Dockerfile
FROM php:7.4-apache
#USER root
RUN apt-get update
RUN docker-php-ext-install mysqli
## Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
## Install PHP-GD
RUN apt-get install -y libpng-dev libjpeg-dev libfreetype6-dev \
&& docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \
&& docker-php-ext-install gd
## Install xdebug
RUN apt-get install --assume-yes --fix-missing git libzip-dev libmcrypt-dev openssh-client \
libxml2-dev libpng-dev g++ make autoconf \
&& docker-php-source extract \
&& pecl install xdebug redis \
&& docker-php-ext-enable xdebug redis \
&& docker-php-source delete \
&& docker-php-ext-install pdo_mysql soap intl zip
## Configure xdebug
RUN echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_port=9000" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_handler=dbgp" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_connect_back=0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.idekey=wolfpackvision.com" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
## Enable mod_rewrite http://httpd.apache.org/docs/current/mod/mod_rewrite.html & mod_headers http://httpd.apache.org/docs/current/mod/mod_headers.html
RUN a2enmod rewrite \
&& a2enmod headers
## Give Full folder permissions to server
#RUN chown -R www-data:www-data /var/www/html
#RUN chmod -R 777 /var/www/html/
#RUN chmod -R 777 /var/www/html/wp-content/uploads/
#RUN chmod -R 777 /var/www/html/
#RUN chmod -R 766 /var/www/html/
## Copy php.ini over
COPY ./.docker/php/php.ini /usr/local/etc/php
## Cleanup
RUN rm -rf /tmp/*
php.ini
## xdebug setup from https://dev.to/_mertsimsek/using-xdebug-with-docker-2k8o
engine = On
precision = 14
output_buffering = Off
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = 100
disable_functions = dl
disable_classes =
zend.enable_gc = On
expose_php = Off
max_execution_time = 30
max_input_time = 60
memory_limit = 256M
error_reporting = E_ALL & ~E_NOTICE
display_errors = On
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = Off
html_errors = On
error_log = error_l
variables_order = "EGPCS"
request_order = "GP"
register_argc_argv = On
auto_globals_jit = On
post_max_size = 64M
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
default_charset = "UTF-8"
include_path = ".:/opt/php72/lib/php"
doc_root =
user_dir =
enable_dl = Off
file_uploads = On
upload_max_filesize = 64M
max_file_uploads = 20
allow_url_fopen = On
allow_url_include = On
default_socket_timeout
cli_server.color
date.timezone = Asia/Riyadh
pdo_mysql.cache_size = 2000
pdo_mysql.default_soc
sendmail_path = /usr/sbin/sendmail -t
mail.add_x_header
sql.safe_mode =
odbc.allow_persistent = Off
odbc.check_persistent = Off
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode
ibase.allow_persistent = 1
ibase.max_persistent = -1
ibase.max_links = -1
ibase.timestampformat = "%Y-%m-%d %H:%M:%S"
ibase.dateformat = "%Y-%m-%d"
ibase.timeformat = "%H:%M"
mysqli.max_persistent = -1
mysqli.allow_persistent = Off
mysqli.max_links = -1
mysqli.cache_size = 2000
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect =
mysqlnd.collect_statistics = Off
mysqlnd.collect_memory_statistics =
pgsql.allow_persistent = Off
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice
bcmath.scale
session.save_handler = files
session.save_path = "/tmp"
session.use_strict_mode = 0
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly = On
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 100
session.gc_maxlifetime = 1440
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 5
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fields"
zend.assertions
tidy.clean_output =
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit
ldap.max_links
-> Please don't go warn me about 777, I know about that. This is all strictly local and I will never use this in production. Plus, if I get the permissions working, I might tighten it. First I want it to work at all.
from Permission problem: How to setup permissions on docker for windows for use with Wordpress
No comments:
Post a Comment