coiai Logo

This article is an English translation of the original Japanese post. Read the Japanese original →

Connecting to Lolipop via SSH to Use WP-CLI

August 22, 2024

Categories: Linux, WordPress · Tags: lolipop, WordPress, wp-cli, サーバー

❓ 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 -v

This command, though, gives you "command not found."

/usr/local/php/8.2/bin/php -v

This 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_profile

Change the contents of .bash_profile to the following.

if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi

export PATH="~/bin:$PATH"
source .bash_profle

Set the path with the following command.

echo 'export PATH=/usr/local/php/8.2/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

Now 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 bin

Install wp-cli using curl.

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

Change the permissions on the file you just added, and rename wp-cli.phar to wp.

chmod 705 wp-cli.phar
mv wp-cli.phar wp

You can check whether the install worked with the following command.

wp --info

And that's it.