I changed VPS and before that I made backup data from first and copied to second server. Since then I have problem with my wordpress which should run on docker. Containers run, wordpress admin panel run, but main page give me a lot of errors in logs. For example:
[core:error] [pid 26] (13)Permission denied: [client 37.7.226.155:0]
AH00035: access to /wp-content/uploads/2021/09/logo.jpg denied
(filesystem path '/var/www/html/wp-content/uploads/2021/09/logo.jpg')
because search permissions are missing on a component of the path,
referer: ...
My docker-compose.yaml file looks like this:
wordpress:
image: wordpress
restart: always
links:
- mariadb:mysql
environment:
- WORDPRESS_DB_PASSWORD=secret
- WORDPRESS_DB_USER=root
ports:
- "10150:80"
volumes:
- ./html:/var/www/html
- ./html/wp-content/themes:/var/www/html/wp-content/themes
- ./html/wp-content/plugins:/var/www/html/wp-content/plugins
- ./html/wp-content/uploads:/var/www/html/wp-content/uploads
- ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
mariadb:
image: mariadb:10.5
restart: always
environment:
- MYSQL_ROOT_PASSWORD=secret
- MYSQL_DATABASE=wordpress
volumes:
- ./database:/var/lib/mysql
- ./additional_files/my.cnf:/etc/mysql/my.cnf
I changed permissions to directories on 755 and to files on 644 but it was not work. What can I do more to fix my problem?
Related
Here is my docker-compose.yml file:
version: '3.9'
services:
db:
image: mysql:5.7
restart: always
command: [
'--disable-partition-engine-check',
'--default_authentication_plugin=mysql_native_password',
'--character-set-server=utf8mb4',
'--collation-server=utf8mb4_unicode_ci',
'--max_allowed_packet=100M'
]
volumes:
- ./db_data:/var/lib/mysql
environment:
MYSQL_DATABASE: wordpress
MYSQL_ROOT_PASSWORD: pswd4!
pma:
image: phpmyadmin/phpmyadmin
environment:
PMA_HOST: db
PMA_PORT: 3306
MYSQL_ROOT_PASSWORD: pswd4!
UPLOAD_LIMIT: 1G
ports:
- 8080:80
depends_on:
- db
wp:
image: wordpress:php8.0
ports:
- 80:80
volumes:
- ./config/php.conf.ini:/usr/local/etc/php/conf.d/conf.ini
- ./:/var/www/html
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: pswd4!
WORDPRESS_DEBUG: 1
depends_on:
- db
links:
- db:mysql
hostname: test.localhost
wpcli:
image: wordpress:cli-php8.0
volumes_from:
- wp
depends_on:
- db
- wp
links:
- db:mysql
entrypoint: wp
command: "--info"
volumes:
db_data:
When I try to use wp-cli in Docker (e.g. docker-compose run --rm wpcli plugin list), it gets an error that it cannot connect to the database:
Error: `Access denied for user 'username_here'#'192.168.32.5' (using password: YES)`
Error establishing a database connection
This either means that the username and password information in your `wp-config.php` file is incorrect or we can’t contact the database server at `mysql`. This could mean your host’s database server is down.
Are you sure you have the correct username and password?
Are you sure you have typed the correct hostname?
Are you sure the database server is running?
If you’re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums. `Access denied for user 'username_here'#'192.168.32.5' (using password: YES)
`
It looks like wp-cli is seeing bad database credentials (username_here instead of root)
Result of executing docker-compose run --rm wpcli config list command:
What could be wrong? I've searched all over the internet, lost several hours and still haven't found the cause of the problem.
You should specify the same set of environment variables as in your wp container for your wpcli container. If not, default variables from a php file in wordpress are used.
Do be careful : volumes_from and link options are deprecated in compose v3. For the link option, docker-compose creates a network automatically (or you can specify one if you prefer) and the embed docker dns automatically attributes aliases to your containers based on their names (or in compose the service name). More info on that here
For volumes, you can find more info here
This is my docker-composer.yml for wordpress:
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- ./all:/var/www/html
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
ports:
- "8084:80"
links:
- db:db
volumes:
db_data: {}
The folder all contains all the files that ship from the wordpress docker image. However, they all have user/group www-data:www-data and the permission of the files is 644 and from folders 755, i.e. even if I add myself to the www-data group I have no right to modfiy or create files.
My research:
I found at write in shared volumes docker that someone had the opposite problem, he created files and his docker image could not access it. The solution seems to be to run docker and create a file with user www-data - but I don't see how I can apply this to my problem.
I tried to add user: "1000:1000 in the worpdress service inside docker-composer.yml, in hope, that all file permissions set by docker would be from my user. However, I get 1000 lines of erros of this form:
wordpress_1 | tar: ./wp-admin: Cannot mkdir: Permission denied
wordpress_1 | tar: ./wp-admin/options-reading.php: Cannot open: No such file or directory
I ended up just to change the file permission of all files and folders from folder all to 777 recursively. Since this is only local development, there is no risk involved.
When I create a new file from my host it only has 644 permission, i.e. it can be read by from localhost but not edited, for that I would manually need to change the permission to 777.
A bit old of a thread but i also was looking on how to update files on a wordpress:latest container.
I ended using a docker cp on the file i need to change. For instance :
docker cp ./functions_edited.php 6666aa5bbd76:/var/www/html/wp-content/themes/twentytwentytwo/functions.php
to edit the theme functions on the running container.
This works for me since i don't need to persists my changes when the container dies and i need just to change a single file. Maybe this is not your use case.
I've a question how exactly docker-compose handles environment variables.
services:
wp:
image: wordpress:latest
container_name: "wp"
restart: unless-stopped
links:
- wpdb
environment:
- TZ=Europe/Berlin
- WORDPRESS_DB_HOST=wpdb:3306
- WORDPRESS_DB_USER=wordpress
- WORDPRESS_DB_PASSWORD=password
- WORDPRESS_DB_NAME=wp
volumes:
- ./data:/var/www/html
labels:
- "traefik.enable=true"
- "traefik.backend=wp"
- "traefik.frontend.rule=Host:MASKED"
- "traefik.port=80"
- "traefik.docker.network=web"
networks:
- internal
- web
wpdb:
image: mariadb:latest
restart: unless-stopped
container_name: "wpdb"
environment:
- MYSQL_ROOT_PASSWORD=1234
- MYSQL_USER=wordpress
- MYSQL_PASSWORD=password
- MYSQL_DATABASE=wp
networks:
- internal
labels:
- "traefik.enable=false"
volumes:
- ./sql:/var/lib/mysql
volumes:
data:
sql:
networks:
web:
external: true
internal:
The compose file works great. The containers will be created and work perfectly.
But when I change the defaults at: WORDPRESS_DB_PASSWORD=password and MYSQL_PASSWORD=password.
The Wordpress container throws access denied for user. I also tried to kill the container and volumes.
Hopefully someone has a hint for me.
You should be doing a docker-compose down -v which would delete the named volumes declared in the volumes section. The only downside is that you would be losing all the data created by the service for the first time.
Here is how I could reproduce it -
Used your compose file as reference and on first time used the default password mentioned by you. The services come up fine, I install it and do a Ctrl+C to bring down the service. So all the MYSQL data is written into sql named volume.
When you do a Ctrl+C OR docker-compose down it only removes the containers and networks defined in the service. Not the volumes. Read more about it here
Now when you change password and bring the service back up it still uses the old volumes which has your old password.
So use a docker-compose down -v to remove the volumes too and give it a try.
Here are the steps how I reproduced it
Ctrl+C to stop all the services and then update the docker-compose.yml to update the password and do a docker-compose up again to get access denied error.
Do a docker-compose down -v to clean all the volume too and then do a docker-compose up
On doing a docker-compose down -v you will be losing all the data created by the prior service. Use it cautiously.
There is problem with symfony cache and logs in docker containers.
Web server executes from www-data user and group and when I do symfony cache clear from docker container using php that is installed on docker, it executes from root.
So if I remove var/logs/dev.log for example and open url in browser, new log.dev gets created with user and group: www-data:www-data, but after i do cache clear, it gets permissions root:root and url in browser gives error dev.log permission denied.
I am not sure whats the problem, but I guess somehow nginx operates under www-data and when I execute console commands they operate from root user.
I have 4 containers: nginx, php-fpm, mysql, rabbit.
I also use version 3 of docker compose, I thought of solution with group_add but its no longer available in version 3
How do I configure this?
=================
docker-compose is similar to this:
version: "3"
services:
nginx:
image: nginx:1.11
depends_on:
- php-fpm
links:
- php-fpm
environment:
- NGINX_PORT=80
- FASTCGI_HOST=php
- FASTCGI_PORT=9000
- DOCUMENT_ROOT=/usr/local/src/test-project/public
ports:
- 8095:80
volumes:
- .:/usr/local/src/test-project
- ./docker/nginx/templates/default.conf.template:/etc/nginx/conf.d/default.conf.template
- ./docker/nginx/entrypoint.sh:/entrypoint.sh
command: "/bin/bash /entrypoint.sh"
php-fpm:
build: docker/php
depends_on:
- db
extra_hosts:
- "test-project:127.0.0.1"
environment:
DATABASE_URL: pgsql://test-project_users:test-project_users#db:5432/test-project_users
APP_URL: 172.19.0.1:8095/
working_dir: /usr/local/src/test-project
volumes:
- .:/usr/local/src/test-project
db:
image: postgres
restart: always
ports:
- '5599:5432'
environment:
POSTGRES_DB: test-project_users
POSTGRES_USER: test-project_users
POSTGRES_PASSWORD: test-project_users
volumes:
- data:/var/lib/db
The problem is, that you are clearing the cache as root user via command-line. you should run the clear statement with su www-data.
I'm trying to setup a drupal 8 installation with docker / docker-compose for local development. What I'd like to have is a local folder that is synchronized with the drupal container's /var/www/html directory, so I could work locally. What is the best way to achieve that?
This is my docker-compose.yml:
mysql:
image: mysql:5.5
ports:
- "3306:3306"
environment:
- MYSQL_USER=xxxxx
- MYSQL_PASSWORD=xxxxxx
- MYSQL_ROOT_PASSWORD=xxxxxxx
- MYSQL_DATABASE=xxxxxxx
drupal:
image: drupal:8.0.4
links:
- mysql
ports:
- "8080:80"
You have to map a folder to your dockerhost. Using docker-compose you would have to add "volumes" to your configuration.
The configuration looks like this (see doc for detailed explanation):
volumes:
- /path/on/your/host:/path/in/your/container
Your configuration would then look like this:
drupal:
image: drupal:8.0.4
volumes:
- /path/on/your/host:/var/www/html
links:
- mysql
cheers,
ceth