I want to use wordpress docker image to develop my website locally. However when I try to install a theme fromui, or upload one, Wordpress wants some credentials to FTP. I've read how to solve this with chown -R www-data.www-data /var/www/html
but it's not working at all and I still face the same issue
Here is my DockerFile
FROM library/wordpress:latest
RUN chown -Rf www-data.www-data /var/www/html/
Here is my docker-compose
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: my_docker
ports:
- "8000:80"
restart: always
volumes:
- ./wp-content:/var/www/html/wp-content/
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
Could the reason be that I share a volume between my Windows host and docker image to persist changes on my website?
You can put the following code in the wp-config.php file to directly upload the file bypassing FTP.
define('FS_METHOD', 'direct');
Had the same issue; while there are ways to enable FTP access internally to the docker container, below is much easier and will likely allow the access that themes (as well as plugins and Wordpress core updates) need:
1. Get docker container name for Wordpress (if you don't know it.) It's likely just "wordpress" but some installs change the name.
sudo docker ps
// let's assume the output is wordpress for below continued instructions.
2. Enter the bash shell in your container. - --Note: You can do this through a Docker manager such as Portainer, but the below assumes you're using an SSH/local access to the machine that has the docker containers. --Note: replace "wordpress" below with whatever your container's name actually is.
docker exec -it wordpress /bin/bash
3. Give permissions in the folder (and below folders...) to the required user
chown -R www-data:www-data /var/www/html
4. Exit the shell
exit
Even if it looks like that directory has the correct permissions, all it takes is one file to be incorrect to mess everything up. Better to try this 30 second fix that may resolve the issues before trying to make significant changes.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.