ISPConfig 3 & WP-CLI

Discussion in 'Installation/Configuration' started by agentmoller001, Aug 7, 2016.

  1. Here's how I installed WP-CLI with ISPCongfig 3, and it's available globally for clients with jailkit installed. First I followed this guide to allow PHP in SSH for jailed users - http://www.faqforge.com/linux/add-php-in-ssh-jail-ispconfig-3/
    The I ran these commands:
    Code:
    wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar --no-check-certificate
    php5 wp-cli.phar --info
    chmod +x wp-cli.phar
    mv wp-cli.phar /usr/bin/wp
    Code:
    nano /etc/jailkit/jk_init.ini
    Add to the end of file
    Code:
    [wp]
    comment = WordPress Command Line
    executables = /usr/bin/wp
    includesections = php
    Run the command:
    Code:
    jk_init -c /etc/jailkit/jk_init.ini -f -k -j /var/www/clients/client1/web1 wp
    Next, login to ISPConfig 3 and navigate to -
    ISPConfig 3 > System (Tab) > System > Server Config > (select server) > Jailkit
    Add the word "wp" separated by a white space at the end of the "Jailkit chroot app sections" field.

    SSH to the jailed shell and test.
    Code:
    [email protected]:/usr/bin$ php5 wp --info
    PHP binary:     /usr/bin/php5
    PHP version:    5.6.24-0+deb8u1
    php.ini used:   /etc/php5/cli/php.ini
    WP-CLI root dir:        phar://wp-cli.phar
    WP-CLI packages dir:
    WP-CLI global config:
    WP-CLI project config:
    WP-CLI version: 0.24.0
    Hope this helps someone. If anyone sees any security issues, please let me know.
     
    Last edited: Aug 9, 2016
    Jesse Norell likes this.
  2. Issues now.
    Code:
    [email protected]:/web$ wp --info
    /usr/bin/env: php: No such file or directory
    
    [email protected]:/web$ ls -la /usr/bin/e*
    -rwxr-xr-x 2 root root 31240 Mar 14  2015 /usr/bin/env
    Any ideas?

    Do I need to run the command:
    Code:
    jk_cp -k -j /var/www/clients/client1/web1 /usr/bin/wp
     
    Last edited: Aug 7, 2016
  3. Ovidiu

    Ovidiu Active Member

    can't help much but in your first working example you use php5 and in the second non-working scenario it seems wp is looking for php not php5. So if php isn't in your path, how about you symlink the php5 variable to php?
     
    agentmoller001 and Jesse Norell like this.
  4. Adding the path /usr/bin/php to the PHP > executables section of the jk_init.ini file fixed the issue.
    Code:
    [php]
    comment = the php interpreter and libraries
    executables = /usr/bin/php5, /usr/bin/php
    directories = /usr/lib/php5, /usr/share/php, /usr/share/php5, /etc/php5, /usr/share/php-geshi, [B]/usr/share/zoneinfo[/B]
    includesections = env
    But, there is a new issue (ofcoarse).
    Code:
    [email protected]:/web$ wp plugin update --all
    PHP Notice:  date_default_timezone_set(): Timezone ID 'UTC' is invalid in phar:///usr/bin/wp/php/wp-settings-cli.php on line 48
    Error: Error establishing a database connection
     
  5. Ovidiu

    Ovidiu Active Member

    I googled that, can you check your php.ini date.timezone directive?
    http://php.net/manual/en/function.date-default-timezone-set.php
     
  6. Jesse Norell

    Jesse Norell Well-Known Member Staff Member Howtoforge Staff

    Make sure you are connecting to 127.0.0.1 from cli, there is no socket file to talk to the mysql server in your jailkit environment.
     
    agentmoller001 likes this.
  7. Jesse Norell

    Jesse Norell Well-Known Member Staff Member Howtoforge Staff

    yes, adding the socket into your jailkit environment would solve the same problem. I think unix sockets perform better than tcp (127.0.0.1), but for just the wp cli command it likely makes very little difference which route you go.
     
  8. Agreed - Thanks Jessie!

    I believe that to be the warning issue as well. Thanks Ovidiu!

    I will confirm.
     
  9. I added mysql to the jailkit jk_init.ini file.
    Code:
    [mysql]
    comment = mysql client
    executables = /usr/bin/mysql
    Updated the jail.
    Code:
    jk_init -c /etc/jailkit/jk_init.ini -f -k -j /var/www/clients/client1/web1 mysql
    And added mysql to the Jailkit section of ISPConfig 3.

    For testing only, I changed the wp-config.php file DB_HOST and it believe Jessie is correct.
    Code:
    /** MySQL hostname */
    define( 'DB_HOST', '127.0.0.1:3306' );
    I don't know how to get WP-CLI use TCP connection without changing the wp-config.php file. If anyone can advise please.

    I also had to use the UTC +/- timezone in WordPress only. Not America_Los_Angeles (in my case).

    Now there is another error.
    Code:
    [email protected]:/web$ wp plugin update --all
    PHP Notice:  date_default_timezone_set(): Timezone ID 'UTC' is invalid in phar:///usr/bin/wp/php/wp-settings-cli.php on line 48
    Enabling Maintenance mode...
    Downloading update from https://downloads.wordpress.org/plugin/wordpress-seo.3.4.2.zip...
    Using cached file '/home/keuqbtwsp1121/.wp-cli/cache/plugin/wordpress-seo-3.4.2.zip'...
    Unpacking the update...
    PHP Fatal error:  date(): Timezone database is corrupt - this should *never* happen! in /web/wp-admin/includes/class-wp-filesystem-direct.php on line 500
    Fatal error: date(): Timezone database is corrupt - this should *never* happen! in /web/wp-admin/includes/class-wp-filesystem-direct.php on line 500
    Does this look like the fix? - http://ivanbayan.com/index.php/2013...database-is-corrupt-this-should-never-happen/
    I have never used pecl. That's why I am asking prior to trying.
     
    Last edited: Aug 9, 2016
  10. Success!
    I had the [ B ] tags in the jk_init.ini file wrapped around the /usr/share/zoneinfo
    Once I removed them and updated the jail, it worked. Now the focus is on getting a mysql TCP connection.
     
  11. Jesse Norell

    Jesse Norell Well-Known Member Staff Member Howtoforge Staff

    for the production website you might want to continue using a unix socket .. can you specify the database host on the command-line? or even specify an alternative wp-config.php (one for web, one for cli)?
     
  12. I was able to make it work now by modifying the wp-config.php file under "DB_HOST" with an "if" and "else" statement.

    Code:
    /** Tell WP-CLI to use TCP instead of socket connection */
    if ( defined( 'WP_CLI' ) && WP_CLI ) {
    
    /** MySQL hostname for WP-CLI */
    define('DB_HOST', '127.0.0.1:3306');
    
    } else {
    
    /** MySQL hostname */
    define('DB_HOST', 'localhost:3306'); }
    It feels good to finally get it working. Thanks again for all the help!

    Reference: https://github.com/wp-cli/wp-cli/issues/2402#issuecomment-174083900
     
    Last edited: Aug 10, 2016

Share This Page