❓ What Is This
Things like backing up your database or converting JPEGs to WebP
can go a lot more smoothly if you use WP-CLI.
This post is for anyone using shared hosting like Lolipop, Sakura Internet, or Xserver.
It walks through how to connect over SSH
and get WP-CLI working.
Confirmed working as of August 22, 2024.
🪴 Environment
Server side
- PHP 8.2
- WP-CLI 2.11.0
Machine used
- Apple Silicon M1
- Sonoma 14.5
🖐️ Steps
1. Connect to your shared hosting via SSH
First, open a terminal and connect to the server over SSH.
If you're on Lolipop, follow the support page below to connect via SSH.
https://lolipop.jp/manual/user/ssh-m-terminal
2. Configuring PHP
Once you're connected over SSH, check your PHP version.
php -vThis command, though, gives you "command not found."
/usr/local/php/8.2/bin/php -vThis works, but it's way too inconvenient to type every time.
I set things up based on the article below.
https://qiita.com/yuuki_okubo/items/54f62f7acb94e273bd96
vi ~/.bash_profileChange the contents of .bash_profile to the following.
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
export PATH="~/bin:$PATH"source .bash_profleSet the path with the following command.
echo 'export PATH=/usr/local/php/8.2/bin:$PATH' >> ~/.bashrcsource ~/.bashrcNow you'll be able to run php -v directly.
3. Setting up wp-cli
Let's follow the official docs for this.
https://wp-cli.org/ja
Create a bin directory at the same level as web,
then move into the bin directory.
mkdir bin
chmod 705 bin/
cd binInstall wp-cli using curl.
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.pharChange the permissions on the file you just added, and rename wp-cli.phar to wp.
chmod 705 wp-cli.phar
mv wp-cli.phar wpYou can check whether the install worked with the following command.
wp --infoAnd that's it.