WP-CLI for Jailed users in ISPConfig 3 on Debian Jessie

WP-CLI for Jailed users in ISPConfig 3 on Debian Jessie

In this article I will show you how to preinstall WP-CLI for jailed users in ISPConfig 3 on Debian Jessie. It is assumed that you already have a working ISPConfig 3 environment setup and running.

https://www.howtoforge.com/tutorial/perfect-server-debian-8-jessie-apache-bind-dovecot-ispconfig-3/

Download and Configure WP-CLI

The next thing is to download wp-cli.

wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar --no-check-certificate

Now make the file executable.

chmod +x wp-cli.phar

Move the file to the /usr/bin folder and change the name to wp.

mv wp-cli.phar /usr/bin/wp

Make WP-CLI Available for New Jailed Users

Go back into the jk_init.ini file.

nano /etc/jailkit/jk_init.ini

Now add the configuration for wp-cli to the bottom of the file.

[wp]
comment = WordPress Command Line
executables = /usr/bin/wp
includesections = php

Make PHP Available for New Jailed Users

The first step is to make PHP available in the jail from the command line. Open the jk_init.ini file using a text editor of your choice.

nano /etc/jailkit/jk_init.ini

Add the following to the bottom of the jk_init.ini file.

[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, /usr/share/zoneinfo
includesections = env

[env]
comment = Environment Variables
executables = /usr/bin/env

Make MySQL Available for New Jailed Users

Now we need to make MySQL available for the jail. Open the jk_init.ini file using a text editor.

nano /etc/jailkit/jk_init.ini

Add the following to the bottom of the jk_init.ini file.

[mysql]
comment = MySQL Client
executables = /usr/bin/mysql

Enable PHP, MySQL & WP-CLI for Existing Jailed Users

To make WP-CLI available to existing jailed users, you will need to run the following command for each jail. (Use the appropriate path for each jail.)
Example One:

jk_init -c /etc/jailkit/jk_init.ini -f -k -j /var/www/clients/client1/web1 php mysql wp

Example Two:

jk_init -c /etc/jailkit/jk_init.ini -f -k -j /var/www/clients/client3/web13 php mysql wp

Note: Jailkit will try to link all the necessary dependencies/libraries when creating/modifying the jail. But, you may need to add any that are listed in error messages. Below is an example how to add the library /lib/x86_64-linux-gnu/libgcc_s.so.1 for MySQL in the /etc/jailkit/jk_init.iniconfiguration file.

[mysql]
comment = MySQL Client
executables = /usr/bin/mysql
libraries = /lib/x86_64-linux-gnu/libgcc_s.so.1

Enable PHP, MySQL & WP-CLI for New Jails in ISPConfig 3

Login to your ISPConfig 3 hosting control panel and select the System tab. Under the System Menu, select Server Config. Next, choose the appropriate server and navigate to the Jailkit tab. Then add the values php mysql wp to the section Jailkit chroot app sections. Make sure there is only a space, and not a comma between each value.
ISPConfig 3 Jailkit Settings Image

Allow MySQL a TCP or Socket Connection

There are additional steps to allow MySQL a TCP, or Socket connection for WP-CLI that are not yet complete. For now, a workaround has been established by adding if and else statements to the define('DB_HOST', ''); section in the WordPress wp-config.php file.

For existing WordPress websites, open the wp-config.php file. (Use the appropriate path.)

nano /var/www/clients/client1/web1/web/wp-config.php

Delete this section.

/** MySQL hostname */
define('DB_HOST', 'localhost:3306');

Now replace it with this section and save the file.

/** 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'); }

Testing WP-CLI

Login to a new or existing SSH jail and navigate to the websites root directory.

cd /web

Check to make sure WP-CLI functions.

wp --info

You should receive an output similar to the following.

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

WP-CLI Documentation & Resources

Share on FacebookTweet about this on TwitterPin on PinterestShare on Google+Share on LinkedInEmail this to someonePrint this page

Leave a Reply