Want to subscribe to topics you're interested in?
Become a Member

Security Sysadmin WP-CLI not pleased with moving wp-config.php to other location

Discussion in 'System Administration' started by EckyBrazzz, Jun 10, 2019.

  1. EckyBrazzz

    EckyBrazzz Active Member

    867
    182
    43
    Mar 28, 2018
    >>>>Click here<<<< i'm nearby......
    Ratings:
    +333
    Local Time:
    2:23 AM
    Latest
    Latest
    To improve security even a step futher I wanted to change the location of the wp-config.php out of the public folder.

    My wp-config.php is this:
    Code (Text):
    <?php
    
    /** Absolute path to the WordPress directory. */
    if ( !defined('ABSPATH') )
        define('ABSPATH', dirname(__FILE__) . '/');
    
    /** Location of your WordPress configuration. */
    require_once(ABSPATH . '../private/some-config.php');
    

    But running the wp_updater gives me an error on PHP
    Code (Text):
    [11:38][root@server8]# sh ./wp_updater_domain.com.sh
    /home/nginx/domains/domain.com/public
    update wp-cli
    2019-06-10 11:38:16 URL:https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar [5506663/5506663] -> "/usr/bin/wp" [1]
    OS:     Linux 3.10.0-957.12.2.el7.x86_64 #1 SMP Tue May 14 21:24:32 UTC 2019 x86_64
    Shell:  /bin/bash
    PHP binary:     /usr/local/bin/php
    PHP version:    7.2.6
    php.ini used:   /usr/local/lib/php.ini
    WP-CLI root dir:        phar://wp-cli.phar/vendor/wp-cli/wp-cli
    WP-CLI vendor dir:      phar://wp-cli.phar/vendor
    WP_CLI phar path:       /home/nginx/domains/domain.com/public
    WP-CLI packages dir:    /root/.wp-cli/packages/
    WP-CLI global config:
    WP-CLI project config:
    WP-CLI version: 2.2.0
    Error: Strange wp-config.php file: wp-settings.php is not loaded directly.
    Error: Strange wp-config.php file: wp-settings.php is not loaded directly.
    Reloading nginx configuration (via systemctl):  [  OK  ]
    

    I was reading the same issue here but that did not give a clue to resolve it.
    How to use wp-cli with a non-standard wp-config.php location
     
  2. eva2000

    eva2000 Administrator Staff Member

    44,426
    10,144
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,696
    Local Time:
    3:23 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
  3. EckyBrazzz

    EckyBrazzz Active Member

    867
    182
    43
    Mar 28, 2018
    >>>>Click here<<<< i'm nearby......
    Ratings:
    +333
    Local Time:
    2:23 AM
    Latest
    Latest
    So adding the below to the some-config gave me another error.
    Code (Text):
    <?php
    
    /** Absolute path to the WordPress directory. */
    if ( !defined('ABSPATH') )
        define('ABSPATH', dirname(__FILE__) . '/');
    
    /** Location of your WordPress configuration. */
    require_once(ABSPATH . '../private/some-config.php');
    
    /** Sets up WordPress vars and included files. */
    require_once(ABSPATH . 'wp-config.php');
    

    Guess I'm not the same PHP consumer/eater as you, simply don't get what's wrong.
    Code (Text):
    PHP Fatal error:  Cannot redeclare wp_get_server_protocol() (previously declared in /home/nginx/domains/domain.com/public/wp-includes/load.php:16) in /home/nginx/domains/domain.com/public/wp-includes/load.php on line 21
    Error: De site ondervindt technische problemen.
    PHP Fatal error:  Cannot redeclare wp_get_server_protocol() (previously declared in /home/nginx/domains/domain.com/public/wp-includes/load.php:16) in /home/nginx/domains/domain.com/public/wp-includes/load.php on line 21
    Error: De site ondervindt technische problemen.
    Reloading nginx configuration (via systemctl):  [  OK  ]
    

    I looked here and my setup is this
    Code (Text):
    ├── private
    │   └── some-conf.php   <----|
    ├── public                       |
    │   ├── index.php                |
    │   └──  wp-config.php      -----|  (required file)
    
     
  4. eva2000

    eva2000 Administrator Staff Member

    44,426
    10,144
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,696
    Local Time:
    3:23 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    tried asking wordpress and wp-cli folks too Command line interface for WordPress | WP-CLI ?
     
  5. eva2000

    eva2000 Administrator Staff Member

    44,426
    10,144
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,696
    Local Time:
    3:23 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x