Closed konkova closed 2 years ago
Hello @konkova
Where are you seeing this error and after what process? Please include more information if possible, thanks!
Sure, thanks. I could be using wp-cli wrong, so, sorry if that's the case. SlickStack Build: MAY2022H rfroseth@SSOG-ubuntu-s-1vcpu-1gb-sfo3-01:/var/www/html$ wp plugin update --all PHP Warning: file_get_contents(/var/www/html/wp-config.php): failed to open stream: Permission denied in phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php on line 654 Error: Strange wp-config.php file: wp-settings.php is not loaded directly.
Okay I see that now:
PHP Warning: file_get_contents(/var/www/html/wp-config.php): Failed to open stream: Permission denied in phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php on line 654
Error: Strange wp-config.php file: wp-settings.php is not loaded directly.
I think this is because of file permissions in SlickStack, we set wp-config.php
as read-only and owned by www-data
which conflicts with how WL-CLI runs by default.
Ref: https://wordpress.org/support/topic/wp-cli-issues/ Ref: https://www.alexgeorgiou.gr/wp-cli-www-data-user-permissions-linux/ Ref: https://github.com/wp-cli/wp-cli/issues/4797 Ref: https://www.codedodle.com/fix-wpcli-wp-settings-error.html Ref: https://stackoverflow.com/questions/41669225/php-warning-require-once-var-www-html-wp-config-php-failed-to-open-stream-p
Gotta love it when you're researching a topic and find a conversation you had years earlier on the subject! Apparently I discussed this in the comments section of Alex's blog linked above back in 2018...
After reviewing in detail, it seems Hang Guan Cheah has found a simpler solution on his blog linked above (Code Dodle) where he simply adds the sudo
user to server group e.g. www-data
and then no fancy hackery needed.
I tested this with SlickStack and it seems to work (see our settings below).
Keep in mind (for anyone reading this) you may need to reinstall WP-CLI, users, bash aliases, and/or reboot in order to get this working properly... for older SlickStack installs, running ss-install
again and then rebooting seems to work.
Ref: https://github.com/littlebizzy/slickstack/blob/master/bash/ss-install-ubuntu-users.txt
groupadd -f slickstack
## add sftp user to groups ##
usermod -a -G slickstack "${SFTP_USER}"
usermod -a -G www-data "${SFTP_USER}"
## add sudo user to groups ##
usermod -a -G slickstack "${SUDO_USER}"
usermod -a -G www-data "${SUDO_USER}"
## add www-data user to groups ##
usermod -a -G slickstack www-data
...this is how ss-install-ubuntu-users
looks now. Also note we changed the default group to slickstack
instead of wordpress
going forward to keep the naming more generic in our stack.
We have also had this in our sudoers
for a while already, which avoids password prompts:
@SUDO_USER ALL = (root) NOPASSWD:ALL
Ref: https://github.com/littlebizzy/slickstack/blob/master/modules/ubuntu/sudoers.txt
A final update after testing this a few more times:
WP-CLI seems to be working fine on SlickStack now, even with chmod 0440
on wp-config.php
and MU plugins, since we don't want those files being changed by WordPress and such. Thanks!
Thanks for all your investigation on this, Jesse. Who knew that it was so involved?
On Mon, Aug 8, 2022 at 11:00 AM Jesse Nickles @.***> wrote:
A final update after testing this a few more times:
WP-CLI seems to be working fine on SlickStack now, even with chmod 0440 on wp-config.php and MU plugins, since we don't want those files being changed by WordPress and such. Thanks!
— Reply to this email directly, view it on GitHub https://github.com/littlebizzy/slickstack/issues/164#issuecomment-1208311882, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEATUSF455DHGTZHJVAR3GLVYEVINANCNFSM5VMVOVQQ . You are receiving this because you were mentioned.Message ID: @.***>
Error: Strange wp-config.php file: wp-settings.php is not loaded directly.