I followed this giude to install wordpress in a container for test purposes but using mariadb
and linux as a host. Here is my docker-compose:
version: '3.8'
services:
database:
image: mariadb
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wordpressDB
MYSQL_USER: user
MYSQL_PASSWORD: password
volumes:
- mysql:/var/lib/mysql
wordpress:
depends_on:
- database
links:
- database
image: wordpress:latest
restart: always
ports:
- '8000:80'
environment:
WORDPRESS_DB_HOST: database:3306
WORDPRESS_DB_USER: user
WORDPRESS_DB_PASSWORD: password
WORDPRESS_DB_NAME: wordpressDB
volumes:
- ./wordpress:/var/www/html
- ./wordpress/plugins:/var/www/html/wp-content/plugins
- ./wordpress/themes:/var/www/html/wp-content/themes
- ./wordpress/uploads:/var/www/html/wp-content/uploads
- ./wordpress/wp-content:/var/www/html/wp-content
volumes:
mysql: {}
For now I can access the wp-admin
dashboard but can’t update/install any plugin with error:
Could not create directory.
As mentioned here I’ve tried to change the permissions of the folders but with no success:
$ mkdir /var/www/html/wp-content/plugins
$ mkdir /var/www/html/wp-content/uploads
$ chown -R www-data:www-data /var/www
$ find /var/www/ -type d -exec chmod 0755 {} ;
$ find /var/www/ -type f -exec chmod 644 {} ;
Here is the output from ls -l
-rwxrwxr-x 1 1000 985 405 Jul 12 06:30 index.php
-rwxrwxr-x 1 1000 985 19915 Jul 12 06:30 license.txt
drwxrwxr-x 1 1000 985 0 Jul 12 06:30 plugins
-rwxrwxr-x 1 1000 985 7345 Jul 12 06:30 readme.html
drwxrwxr-x 1 1000 985 0 Jul 12 06:30 themes
drwxrwxr-x 1 1000 985 0 Jul 12 06:30 uploads
-rwxrwxr-x 1 1000 985 7165 Jul 12 06:30 wp-activate.php
drwxrwxr-x 1 1000 985 20480 Jul 12 06:30 wp-admin
-rwxrwxr-x 1 1000 985 351 Jul 12 06:30 wp-blog-header.php
-rwxrwxr-x 1 1000 985 2328 Jul 12 06:30 wp-comments-post.php
-rwxrwxr-x 1 1000 985 5456 Jul 12 06:30 wp-config-docker.php
-rwxrwxr-x 1 1000 985 2913 Jul 12 06:30 wp-config-sample.php
-rwxrwxr-x 1 1000 985 5592 Jul 12 07:03 wp-config.php
drwxrwxr-x 1 1000 985 0 Jul 12 06:30 wp-content
-rwxrwxr-x 1 1000 985 3939 Jul 12 06:30 wp-cron.php
drwxrwxr-x 1 1000 985 40960 Jul 12 06:30 wp-includes
-rwxrwxr-x 1 1000 985 2496 Jul 12 06:30 wp-links-opml.php
-rwxrwxr-x 1 1000 985 3313 Jul 12 06:30 wp-load.php
-rwxrwxr-x 1 1000 985 44994 Jul 12 06:30 wp-login.php
-rwxrwxr-x 1 1000 985 8509 Jul 12 06:30 wp-mail.php
-rwxrwxr-x 1 1000 985 21125 Jul 12 06:30 wp-settings.php
-rwxrwxr-x 1 1000 985 31328 Jul 12 06:30 wp-signup.php
-rwxrwxr-x 1 1000 985 4747 Jul 12 06:30 wp-trackback.php
-rwxrwxr-x 1 1000 985 3236 Jul 12 06:30 xmlrpc.php
Where am I mistaken?
3
Answers
After a bit of digging, the problem is with this line that I added in my
config.php
that removed the missing FTP error when I started the container:After that I tried many times to
chown
the directories of the site, with no success. Which is strange because I used the root account to change them. However they remained to groupusers
.In the end I added the
www-data
user tousers
androot
(just in case) groups and that solved the problem.Update
Another solution I found is instead of using a bind volume
./wordpress
to use normal volumewordpress
with read/write permissions. Here is the newdocker-compose
:After the mentioned change the output of
ls -l
for the folders is like this:Now wordpress updates/installs plugins and the update of wordpress itself is working flawlessly.
get docker container name
interactive with container shell
give permission to the user
exit the shell
You should make your volumes like shown below:
I found this solution in a discussion at:
https://github.com/docker-library/wordpress/issues/341
The WordPress image copies every file/folder found in /usr/src/worpress folder to the /var/www/html/ folder. When the copy begins it also changes the user and group permissions of the file so that the WordPress application can use it.
Hope this helps. You might also want to look at the links below.
https://salzam.com/dockerize-wordpress-with-themes-plugins-and-common-configuration/
docker/wordpress: seperate default plugins from own plugins
EDIT 30-08-2022
Adding WordPress Themes, Plugins, and/or Media files.
Always add new things through the WordPress Application directly when installing new features. This is needed to save the state of the features within the database correctly.
When altering files within the binding mount the containers must be recreated. You should make your volumes like shown below. This is because of the following:
When altering the files on ones own OS one first must change ownership again or use root. For example, you uploaded a new plugin using the plugin manager of WordPress. It gets installed correctly and is activated. In the database a boolean is made and saved in the wp-options tables to ensure it is activated. Now when changing a file within the plugin or theme files the application will not break or give errors (other than errors from incorrect code that has been added).