permission with volume docker and wordpress - wordpress

I've created a docker-composer.yml file to run a container for wordpress mysql and phpmyadmin. It starts well bt i have a permission problem. All my files have www-data:www-data for user and group and when i want to create a new theme in wp-content i have a permission denied. Im in ubuntu 18.04.
here is my docker-compose.yml file :
version: '3'
services:
# Database
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
networks:
- wpsite
# phpmyadmin
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- '8080:80'
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: password
networks:
- wpsite
# Wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- '8000:80'
restart: always
volumes: ['./:/var/www/html']
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
networks:
- wpsite
networks:
wpsite:
volumes:
db_data:
i tried to change to "chown -Rf myname:myname ." so there i can create a file but upload for files in wordpress doesn't work now. So i wonder how to set properly permissons with a docker mounted volume in ubuntu.

I just add user: 1000:1000 to container, and everything works fine. Got idea from this tutorial

One solution for this would be to add your own user myname to the www-data group
sudo usermod -aG www-data myname
and make sure the www-data group has write privileges on all files/directories and execute privileges on directories.
Another solution would be to let your own user own all files (myname:www-data as owner) and directories and make sure www-data group has appropriate read/write privileges so the WordPress container's webserver can use the group privileges to read/write files.
Off-topic: also make sure to have a
define('FS_METHOD', 'direct');
line in your wp-config.php.

Related

existing WordPress file into containers?

I am having a WordPress site that runs using xampp , now I want to run that in docker
this is my docker-compose file
version: '3'
services:
db:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: password
wordpress:
build: .
ports:
- "8080:80"
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: password
WORDPRESS_DB_NAME: wordpress
volumes:
["./:/var/www/html"]
depends_on:
- db
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
PMA_HOST: db
PMA_USER: wordpress
PMA_PASSWORD: password
ports:
- "8081:80"
volumes:
mysql: {}
-----------------------------------------------------------------------------
this is my docker file
FROM php:7.4-apache
# copy the WordPress files to the web root
COPY . /var/www/html/
# set the working directory to the web root
WORKDIR /var/www/html/
# set file permissions
RUN chown -R www-data:www-data /var/www/html/
# expose port 80 for the web server
EXPOSE 80
I have a WordPress site in my locally that run in xampp, I want to change that to a docker container

Wordpress - cannot change username or password in docker-compose

If I use this inside docker-compose, it works fine:
db_node_domain:
image: mysql:5.7
volumes:
- ./db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: mystrongpassword
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
container_name: wp_db
networks:
- "proxy-tier"
wordpress:
depends_on:
- db_node_domain
image: wordpress:latest
ports:
- "8080:80"
expose:
- "8080"
restart: always
environment:
VIRTUAL_HOST: blog.mydomain.com
LETSENCRYPT_HOST: blog.mydomain.com
LETSENCRYPT_EMAIL: foo#mydomain.com
WORDPRESS_DB_HOST: db_node_domain:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
container_name: wordpress
networks:
- "proxy-tier"
I want to use different username and stronger passwords for MYSQL_USER and WORDPRESS_DB_USER but if I make any changes at all in them I get 502 Bad Gateway from nginx. Can I not change these?
it is because you have already built the database.
When you have run the docker-compose up for the fist time, these values have been set:
environment:
MYSQL_ROOT_PASSWORD: mystrongpassword
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
and this part:
volumes:
- ./db_data:/var/lib/mysql
means it is a persistence data and after stopping the container, for the next run, the data will be available and new ones will not be set. So you have two options:
new build
remove the data (or maybe image)
modify docker-compose.yml file with new password
running docker-compose again
manually change the password, etc
run the database container
login to the container e.g docker exec -it <CONTAINER-ID> /bin/bash
change the password, etc
logout and commit this new change
and it is obvious that new build is simpler and better option to do.

apache/wordpress when changing domains, assets still use old domain urls

I made the wp site on my local mac using localhost. Then I git commited the entire thing and transferred to my hosting using http://ip:port instead of localhost. Then I edited wp-config define('DOMAIN_CURRENT_SITE', 'localhost'); and mySQL tables wp_blogs, wp_site, wp_sitemeta.
Now all the assets still reference localhost instead of http://ip:port so I see the text but no css/js/images.
I'm guessing it's some apache setting problem?
This is my docker compose:
version: '3.3'
services:
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- ./files:/var/www/html
# basic http auth
- ./apache/000-default.conf:/etc/apache2/sites-enabled/000-default.conf
- ./apache/.htpasswd:/etc/apache2/.htpasswd
ports:
- "80:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: username
WORDPRESS_DB_PASSWORD: password
db:
image: mysql:5.7
volumes:
- ./db:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: username
MYSQL_USER: username
MYSQL_PASSWORD: password
I tried finding what is referencing localhost in apache config but
cat `grep -rl localhost /etc/apache2` | grep localhost
finds nothing useful.

How do I setup a local wordpress using Docker?

So I decided to try Docker for my local Wordpress development.
Luckily, Docker has a quickstart guide for that.
I followed the entire process and I *think* I understood most of it. However, when I had the Docker container up and running, it made a clean installation of Wordpress instead of using the local files I had for a project. I initially thought that changing the directory to the project folder allowed it to read the files in it. Apparently, I was mistaken. I've tried searching the net for an answer and
most of them are just tutorials into how to use Docker for WP.
So with that in mind, how do I create a Docker container (or change the Docker YAML file) that uses the local WP files I have?
docker-compose.yml
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
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
Project structure
/project
/app
/sql
docker-compose.yml
I'm running on Ubuntu 19.04
Wordpress on docker
Create the docker-compose.yml with the follwing
version: '3.1'
services:
wordpress:
image: wordpress
restart: always
ports:
- 8080:80
volumes:
- ./app:/var/www/html
environment:
WORDPRESS_DB_PASSWORD: DoKRteST
WORDPRESS_DB_HOST: mysql
mysql:
image: mysql:5.7
# Uncomment the below code to maintain the persistancy of the data
# volumes:
# - ./wordpress:/var/www/html
restart: always
environment:
MYSQL_ROOT_PASSWORD: DoKRteST
./app folder is the actual wordpress app folder
Simply click on
to run it on Play with docker
You just need to mount wp-content of the host to the container. you can look for wp-content in your current directory structure probably under app/wp-content
wordpress:
depends_on:
- db
image: wordpress:latest
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
WORDPRESS_DB_NAME: wordpress
You can read more details here and here

Install wordpress local site with Docker

I downloaded a github folder with a wordpress site, after the unzip the weight of it is about 1,8 gb.
Inside the master folder I've 9 folders, two of them named:
1: wp-content
2: wp-includes
I already created the docker-compose.yml file and the code inside it is this:
version: '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:5.1.1-php7.3-apache
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
working_dir: /var/www/html
volumes:
- ./wp-content:/var/www/html/wp-content
- ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
volumes:
db_data:
The lines up above are necessary only for install wordpress.
Now my question is, what could I do to install and launch the complete site that i downloaded ?
The entire process must be done with docker, install and launch the site.
Thank you for everything :)
Ensure you have the volume mount points which contains the existing app source code and the db files and the script to do db update.
wordpress section in docker-compose
volumes:
- ./codeblog.dotsandbrackets.com:/var/www/html
mysql section in docker-compose
volumes:
- ./codeblog.dotsandbrackets.com.20170808-024302.sql.gz:/docker-entrypoint-initdb.d/backup.sql.gz
- ./migrate.sql:/docker-entrypoint-initdb.d/migrate.sql
This example uses nginx webserver
Ref : https://codeblog.dotsandbrackets.com/migrate-wordpress-docker/

Resources