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

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.

Related

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.

Wordpress Docker site can't be reached

I'm trying to create a local WordPress environment using Docker and existing WordPress db dump. PHPMyAdmin is loading correctly and the db is in that but the localhost:8000 where I am trying to load the site says it can't be reached. Is there something I am missing in this docker-compose.yml file?
version: '3'
services:
db:
image: mysql:8
volumes:
- ./data:/docker-entrypoint-initdb.d
restart: always
command: "--default-authentication-plugin=mysql_native_password"
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wpdb
MYSQL_USER: user
MYSQL_PASSWORD: password
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_NAME: wpdb
WORDPRESS_DB_USER: user
WORDPRESS_DB_PASSWORD: password
WORDPRESS_DB_PREFIX: unti54
volumes:
- ./wp-content:/var/www/html/wp-content
phpmyadmin:
image: phpmyadmin/phpmyadmin
restart: always
ports:
- 3333:80
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORT: password
If you are sure that both the db and the wordpress volume are correct and the logs aren't showing any errors about them, check the definition of the wordpress ports. You use quotation marks, but in the db service you don't. Try to execute the script without those quotation marks.

Wordpress not running on Docker port 8000

I'm trying to set up wordpress with Docker Desktop on Mac. I followed this guide: https://docs.docker.com/compose/wordpress/
When I run docker-compose up -d, it tells me db & wordpress are up-to-date. But, visiting localhost:8000 results in this error: This page isn’t working localhost didn’t send any data. ERR_EMPTY_RESPONSE . I also tried 127.0.0.1:8000 - same result.
Again, curl localhost:8000 just gives me: (52) Empty reply from server
I'm also using Local by Flywheel on my machine. Could that cause a conflict perhaps?
My 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: {}
I solved it, but I don't know why it worked. I followed what someone had done here: https://forums.docker.com/t/wordpress-example-in-docker-compose-fails/30438/3
Basically I changed volume to db_data:/var/lib/mysql2, and also changed wordpress image to wordpress:php7.1. After running docker-compose up it worked.

Docker: I can't map ports other than 80 to my WordPress container

I want to map some random port on my computer e.g. localhost:7006 to my WordPress docker container's port 80.When I change the port of WordPress from 80:80 to 7006:80 it's not only stops working on localhost(port 80) but also don't respond on localhost:7006.
docker-compose.yml file looks like this:
version: '3'
services:
wordpress:
depends_on:
- db
image: wordpress:4.7.1
restart: always
volumes:
- ./wp-content:/var/www/html/wp-content
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_PASSWORD: p4ssw0rd!
ports:
- 80:80 # Expose http and https
- 8443:443
networks:
- wp_nwk
db:
image: mysql:5.7
restart: always
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: p4ssw0rd!
networks:
- wp_nwk
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- 7005:80
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: p4ssw0rd!
networks:
- wp_nwk
networks:
wp_nwk:
volumes:
db_data:
After a bit of research I found out that the WordPress container sets it's ports once since it needs to save the URLs(localhost:7006) in the db because I am persisting the db data.
I ran the docker-compose up once with the default port 80:80 configuration which caused the localhost:80 or localhost to be saved in the db. So when I changed the ports again and ran docker-compose up, I actually messed up the URLs that are stored in the linked mysql db container with my WordPress container.
I ran docker-compose down --volumes (this causes the persisted data destruction)
and then changed the ports of my WordPress container in docker-compse.yml. Running the following command again created my WordPress container live on port 7006 (localhost:7006).
docker-compose up
wordpress:
depends_on:
- db
image: wordpress:4.7.1
restart: always
volumes:
- ./wp-content:/var/www/html/wp-content
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_PASSWORD: p4ssw0rd!
ports:
- 7006:80 # Expose http and https
- 8443:443
networks:
- wp_nwk
IMPORTANT: I am just playing with docker, so I don't want to save my
volumes data. Anyone wanting to keep their data must not use the
docker-compose down --volumes
It's running on the desired port now
I|f you want to change the port, you need to do the follow step. I successfully changed my WordPress port
run WordPress with default 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: {}
login wordpress and change site url and home in setting to you want
use follow command in wordpress container
docker exec -it *wordpres_container_id* bash
add the follow line to wp_config.php
define( 'WP_HOME', 'http://example.com' );
define( 'WP_SITEURL', 'http://example.com' );
change docker-compose.yml ports to 80
restart container use follow command
docker-compose down
docker-compose up -d
you will need to change the [WordPress Address (URL) and Site Address (URL)] from wordpress admin, and then change the port in docker-compose without destroying the data in the volume.

Cannot host more than one Wordpress site with docker and nginx as reverse proxy

I am trying to host multiple sites on a single Digital Ocean VPS. I am using docker to achieve this. Each Wordpress site has its own database.
Using the docker-compose file of any of the two sites works fine and the site goes live. Adding a second does not work. (Navigating to the domain gives an nginx error of 'service temporarily unavailable')
I tried launching a static website from a container based on an apache image, and it does indeed work. So the nginx reverse proxy does successfully route traffic.
I am guessing that there is something more that I need to change between the two docker-compose files. Every tutorial or sample I've found stops after creating the first, and never actually shows a second Wordpress site being created.
Wordpress site 1:
docker-compose.yml
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
container_name: site1_db
wordpress:
depends_on:
- db
image: wordpress:latest
expose:
- 80
restart: always
environment:
VIRTUAL_HOST: www.site1.com
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
container_name: site1_wp
volumes:
db_data:
networks:
default:
external:
name: nginx-proxy
Wordpress site 2:
docker-compose.yml
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
container_name: site2_db
wordpress:
depends_on:
- db
image: wordpress:latest
expose:
- 80
restart: always
environment:
VIRTUAL_HOST: www.site2.com
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
container_name: site2_wp
volumes:
db_data:
networks:
default:
external:
name: nginx-proxy
A network named nginx-proxy was created beforehand to link all the containers. I left out the details about the nginx instance as it uses the well known jwilder image and like I said, it does seem to work just fine.
I finally found the answer. It is two-fold:
The WORDPRESS_DB_HOST environmental variable should not be the service, but rather the container that it is referencing
Thus change:
WORDPRESS_DB_HOST: db:3306
to:
WORDPRESS_DB_HOST: site1_db:3306
The same obviously goes for site2
The fix above still does not result in a working setup. When changing the database container to build from mariadb instead of mysql, it starts working! I have no idea in the slightest why this is true. Especially since the mysql instances can work on their own, but when running simultaneously, only mariadb works

Resources