tiredofit / docker-wordpress

Dockerized Content Management System many with customizable options
MIT License
36 stars 7 forks source link

Add webroot path to find-replace #22

Closed radarsymphony closed 1 year ago

radarsymphony commented 1 year ago

Hi tiredofit,

I found another issue with SITE_URL_UPDATE_MODE. I discovered that I also needed to add the path to the webroot in order for the DB update to occur via the wp-cli find-replace. After I added --path="${NGINX_WEBROOT}" the command ran and the DB updated.

[tiredofit/wordpress:5.4.2 14:14:21 /] $ sudo -u "${NGINX_USER}" wp-cli search-replace "https://example.com" "https://dev.example.com" --skip-columns=guid
Error: This does not seem to be a WordPress installation.
Pass --path=`path/to/wordpress` or run `wp core download`.
[tiredofit/wordpress:5.4.2 14:14:25 /] $ which wordpress
[tiredofit/wordpress:5.4.2 14:15:05 /] $ which wp-cli
/usr/bin/wp-cli
[tiredofit/wordpress:5.4.2 14:15:15 /] $ 
tiredofit commented 1 year ago

I'm not sure this actually needs to be performed but I see no harm with this being added and is a better practice.

If working inside the container via console you can get away with just typing wp-cli as there is a bash function (cat /root/.bashrc) which automatically changes working dir to NGINX_WEBROOT. The container initialization routines also work within the NGINX_WEBROOT, so shouldn't be throwing errors when firing.

Your addition adds a safety net. Thanks.

tiredofit commented 1 year ago

Tagged as 5.4.5 and credited to @radarsymphony

radarsymphony commented 1 year ago

Thanks. I think your command runs as the nginx user on line 77, which does not use the /root/.bashrc.

I tested this by appending the following to the bottom of the /root/.bashrc:

alias test='echo "I am a test"'

I then sourced the file and ran: sudo -u ${NGINX_USER} test

Nothing.

[tiredofit/wordpress:5.4.2 16:11:33 /] $ sudo -u ${NGINX_USER} env
HOSTNAME=f5bee208836c
TERM=xterm
PS1=[tiredofit/wordpress:5.4.2 \t \w] $ 
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
MAIL=/var/mail/nginx
LOGNAME=nginx
USER=nginx
HOME=/var/cache/nginx
SHELL=/sbin/nologin
SUDO_COMMAND=/usr/bin/env
SUDO_USER=root
SUDO_UID=0
SUDO_GID=0

What I am I missing that enables the nginx user to make use of your /root/.bashrc when it runs the command on line 77?

tiredofit commented 1 year ago

It's a root shell - but wp-cli executes as NGINX_USER

https://github.com/tiredofit/docker-wordpress/blob/67b72227d92948305a3a215d26f2ac2e988fdd45/install/assets/functions/30-wordpress#L25