What config option links a Wordpress database to its files? - wordpress

I'm trying to restore my online Wordpress site to my localhost.
Install
This little Dockerfile successfully downloads & runs Wordpress in a container on my machine:
version: '2'
services:
db:
image: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: lkj
volumes:
- ./mysql:/var/lib/mysql
ports:
- 60001:3306
wordpress:
image: wordpress:latest
restart: always
depends_on:
- db
links:
- db
ports:
- 60000:80
environment:
WORDPRESS_DB_PASSWORD: lkj
WORDPRESS_DB_HOST: db
working_dir: /var/www/html
volumes:
- ./data:/var/www/html
I can browse & install the default site on 0.0.0.0:60000 and explore the MySql database on 0.0.0.0:60001.
Restore files
Then I overwrite all my WP files in my wp-content folder with files from my site backup. Everything still works. (The wp-config isn't changed).
Restore db
Then I delete the wordpress database and create a new one, and run my online site's backup script. All tables are successfully created.
But now when I browse to 0.0.0.0:60000 I get the messageThis site can’t be reached. 0.0.0.0 refused to connect.
Why is it broken?
Why is this? What settings do I need to check in the database? I tried looking in wp_options and changing the home and site_url settings but that didn't help.
Update -------
I ran this on my db update wordpress.wp_options set option_value='http://0.0.0.0:60000' where option_name in ('siteurl', 'home') (http://www.wpbeginner.com/wp-tutorials/how-to-fix-the-error-establishing-a-database-connection-in-wordpress/ said it might help).
I can now log in to wp-admin but the main site error hasn't changed.

change wp-config.php file in which you have to set localhost's,
DB_NAME
DB_USER
DB_PASSWORD
DB_HOST

Run the following query against your MySql database:
update wordpress.wp_options set option_value='http://0.0.0.0:60000' where option_name in ('siteurl', 'home')
Then close your browser, reopen it, and open incognito mode and try browsing to 0.0.0.0:60000. If that fails, reopen and try browsing to 127.0.0.1:60000, or finally localhost:60000.
As well as altering your database wp_options table you have to be careful with how your Docker network is set up (especially if you are on a VM already using either NAT or bridged connection), and remember that most browsers won't clear their cache and retry the site even if it now works.

Related

Problems when migrating a Wordpress-Site into Docker

Solved: I found the solution to my problem here:
https://serverfault.com/a/955471
This is the docker entry in my wp-config.php:
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) {
$_SERVER['HTTPS'] = 'on';}
but it seems, in my case it was not recognized, that my docker installation is behind a reverse proxy. I needed to write the "$_SERVER['HTTPS'] = 'on';" entry without the if query.
Edit: The Problem is not the migration, but it seems a wrong apache2 configuration
I am trying to migrate my wordpress site into docker. I have successfully inserted my database with the command:
docker exec -i wordpress_db_1 mysql -u exampleuser -pexamplepass exampledb < /home/dockerNutzer/datenbanken/wpdatabase.sql
and i have copied my old wp-content into the new Docker volume:
rsync -avc /home/dockerNutzer/wordpressSeite/wp-content/ /var/lib/docker/volumes/wordpress_wordpress/_data/wp-content/
The site is up and running, but it doesn't look like expected:
I can browse through the site, but when I try to log in, I get a redirect error from firefox with the message, that an error occurred during the connection with my address. A connection to a page like
/my-wordpress.site/?m=202210
is working, but not
/my-wordpress.site/wp-login.php
I am using the standard docker-compose file for installation:
version: '3.1'
services:
wordpress:
image: wordpress
restart: always
ports:
- 8050:80
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: exampleuser
WORDPRESS_DB_PASSWORD: examplepass
WORDPRESS_DB_NAME: exampledb
volumes:
- wordpress:/var/www/html
db:
image: mariadb:10.5
restart: always
ports:
- 3307:3306
environment:
MYSQL_DATABASE: exampledb
MYSQL_USER: exampleuser
MYSQL_PASSWORD: examplepass
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
- db:/var/lib/mysql
volumes:
wordpress:
db:
I tried to clear the rewrite rules in the apache config file and the .htaccess file.
I tried to insert my whole old site into the docker volume and not only the wp-content folder.
Edit:
I tried with this site
https://ithemes.com/blog/wordpress-login-redirect-loop/
to fix the redirect loop. But it doesn't worked.
I also checked the database with db check, like it is described here:
https://ithemes.com/blog/error-establishing-database-connection/
It showed no error:
docker exec -i wordpressaltepw_wpcli_1 wp db check
wpdatabase.wp_commentmeta OK
wpdatabase.wp_comments OK
...
Success: Database checked.

Docker & Wordpress - The uploaded file could not be moved to wp-content/uploads/.../

Error:
The uploaded file could not be moved to wp-content/uploads/.../....
Environment:
Wordpress Docker image is created from a base Wordpress image then the files are mapped in and out, for development:
version: '3'
services:
wordpress:
restart: always
environment:
WORDPRESS_DB_NAME: ...
WORDPRESS_DB_HOST: ...
WORDPRESS_DB_USER: ...
WORDPRESS_DB_PASSWORD: ...
image: wordpress:latest
ports:
- 38991:80
volumes:
- ./:/var/www/html
We talk to a dev database hosted external to the Docker container.
Image is built - and sent up to the server. Then, CMS user attempts to upload an image and the Wordpress build moans that the uploaded file could not be moved to wp-content/uploads/.../.... We don't get this error on localhost.
Could some devops experts kindly point us in the right direction on what needs to be done for this to tally up on the server.
The permissions are incorrect on the wp-content/uploads directory. I had the same error and in my case the upload folder's permissions and user/group where set wrong and also some folders inside were set to root. But that's probably because I imported a backup.
To fix the upload you can add the following two commands to your deploy pipeline/script or use docker exec -it <container-name> bash to perform it manually on the container.
Set the correct user/group on the uploads folder: $ chown -R www-data:www-data uploads/*
Set the correct permissions: $ chmod 755 uploads/*

Default configuration for WordPress Docker Container

I'm currently working on a project using the WordPress API.
This is my docker-compose.yml file:
version: '3.1'
services:
wordpress:
image: wordpress
volumes:
- ./volumes/wordpress/:/var/www/html
ports:
- 8080:80
environment:
WORDPRESS_DB_PASSWORD: root
depends_on:
- mysql
mysql:
image: mysql:5.7
volumes:
- ./volumes/mysql/:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
web:
build:
context: .
dockerfile: Dockerfile
volumes:
- ./src/:/src
ports:
- 8081:8081
depends_on:
- wordpress
In order to use the WordPress API, I need to configure the WordPress container manually by going to http://localhost:8080/wp-admin and changing some settings.
Thing is, I need to make this settings changes automatic because everytime I remove the volume folder in order to reset the WordPress content, it also removes the settings.
Any idea on how I can achieve this?
I guess that all settings configured via the wp-admin section are stored in the database.
If that's the case than you can do this:
Setup a first WordPress instance by running your docker-compose and completing the setup steps.
Stop the compose. At this point in the mysql volume folder you have a database structure with a configured wordpress in it.
Store the contents of the folder somewhere.
Now, if you want to create another WordPress instance, you can edit the docker-compose.yml file in order to adjust volume binding and make sure that the initial content of the mysql volume contains the data you got from step 3 above.
When you start the new docker-compose stack it'll start from a populated database and you should have a preconfigured WordPress instance.
You need to locate the file/folder that containes the settings that you are changing.
Start the container, do the changes and backup the settings file into your host machine using:
docker cp <container-name>:<path-to-settings> .
You then can create a custom image that replaces the default settings with the backuped settings you copied to the host.
FROM wordpress
COPY <settings-from-host> <settings-path-in-container>

Why does closing tutum/wordpress automatically delete all the app and data?

I am new to docker, and trying to run a Wordpress application using this tutum/wordpress image: https://hub.docker.com/r/tutum/wordpress/
I simply follow this step: docker run -d -p 80:80 tutum/wordpress
But when I turn off the computer, and run it again, all the database + application gone. And I need to restart from scratch.
How do I persist the database and application?
That image is deprecated. So you should be using the official wordpress image
version: '3.1'
services:
wordpress:
image: wordpress
ports:
- 8080:80
environment:
WORDPRESS_DB_PASSWORD: example
mysql:
image: mysql:5.7
volumes:
- ./data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: example
Then use docker-compose up to get the wordpress up. The wordpress image has code located at /usr/src/wordpress. So if you need to persist the plugins directory then you need to use volumes to map it like I did for mysql

docker-compose wordpress mysql connection refused

I've created a small docker-compose.yml which used to work like a charm to deploy small WordPress instances. It looks like this:
wordpress:
image: wordpress:latest
links:
- mysql
ports:
- "1234:80"
environment:
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DB_PASSWORD: "password"
WORDPRESS_DB_HOST: mariadb
MYSQL_PORT_3306_TCP: 3306
volumes:
- /srv/wordpress/:/var/www/html/
mysql:
image: mariadb:latest
mem_limit: 256m
container_name: mariadb
environment:
MYSQL_ROOT_PASSWORD: "password"
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: "password"
volumes:
- /srv/mariadb:/var/lib/mysql
But when I start it now (maybe since docker update to Docker version 1.9.1, build a34a1d5), it fails
wordpress_1 | Warning: mysqli::mysqli(): (HY000/2002): Connection refused in - on line 10
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) Connection refused
When I cat /etc/hosts of the wordpress_1 there are entries for MySQL:
172.17.0.10 mysql 12a564fdbc56 mariadb
and I am able to ping the MariaDB server.
When I docker-compose up, WordPress gets installed and after several restarts the MariaDB container prints:
Version: '10.0.22-MariaDB-1~jessie' socket: '/var/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distribution
Which schould indicate it to be running, isn't it?
How do I get the WordPress to be able to connect to the MariaDB container?
To fix this issue the first thing to do is:
Add the following code to wordpress & database containers (in the docker-compose file):
restart: unless-stopped
This will make sure you Database is started and intialized before wordpress container trying to connect to it. Then restart docker engine
sudo restart docker
or (for ubuntu 15+)
sudo service docker restart
Here the full configuration that worked for me, to setup wordpress with MariaDB:
version: '2'
services:
wordpress:
image: wordpress:latest
links:
- database:mariadb
environment:
- WORDPRESS_DB_USER=wordpress
- WORDPRESS_DB_NAME=mydbname
- WORDPRESS_TABLE_PREFIX=ab_
- WORDPRESS_DB_PASSWORD=password
- WORDPRESS_DB_HOST=mariadb
- MYSQL_PORT_3306_TCP=3306
restart: unless-stopped
ports:
- "test.dev:80:80"
working_dir: /var/www/html
volumes:
- ./wordpress/:/var/www/html/
database:
image: mariadb:latest
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=mydbname
- MYSQL_USER=wordpress
- MYSQL_PASSWORD=password
restart: unless-stopped
ports:
- "3306:3306"
The reason for this behaviour probably was related to a recent kernel and docker update. I recognized several other connection issues in other docker-compose setups. Therefore I restarted the server (not just the docker service) and didn't have had any issues like this ever since.
I had almost same problem, but just restarting the Wordpress container saved me:
$ docker restart wordpress
I hope this help many people.
I too had troubles here. I was using docker-compose to set up multiple wordpress websites on a single (micro) Virtual Private Server, including phpmyadmin and jwilder/nginx-proxy as a controller.
$ docker logs XXXX will help indicate areas of concern. In my case, the MariaDB databases would keep restarting all the time.
It turns out that all that stuff just wouldn't fit on a micro 512M Single CPU service. I never received error messages that told me directly that size was an issue, but after adding things up, I realized that when all the databases were starting up, I was running out of memory. An upgrade to 1Gb, 1 CPU service worked just fine.
I was using your docker-compose.yml, had the same problem. Just restarting didn't fix. After nearly an hour of researching the logs, I found the problem was: wordpress service started connecting mysql service before it had fully started. Simply adding depends_on won't help.Docker Compose wait for container X before starting Y
the work around could be start the db server before Up. When it has fully started, run docker-compose up. Or just use external service.
This simply means you are trying to connect to the wrong host. In order to use this in localhost just use the name of your service as the database host example in your case, it would be mysql you can fix this by specifying the name of the localhost with a default variable like this MYSQL_ROOT_HOST: localhost
In my case, I'm using Mysql (not MariaDb) but I had the same problem.
After upgrading the MySQL version, it's works fine.
You can see my open source docker-compose configuration: https://github.com/rimiti/wordpress-dockerized-environment

Resources