Running WP-CLI as Root to Import Posts for a cPanel User

Running WP-CLI as Root to Import Posts for a cPanel User

Overview

This guide explains how to safely run WP-CLI commands in WHM Terminal as the root user to perform WordPress imports for a specific cPanel account.

This method does not require enabling shell access for the cPanel user and ensures that no other customers or sites on the server are affected.

—————

Prerequisites

Root access to WHM Terminal.

WP-CLI installed on the server.

A WordPress XML export file (for example, export-posts.xml) located in the cPanel user’s home directory.

The path to the target WordPress installation (for example, /home/username/public_html).

—————

Step 1 – Open WHM Terminal

1. In WHM, go to Server Configuration Terminal.

2. You’ll be logged in automatically as root.

—————

Step 2 – Navigate to the User’s WordPress Directory

From the Terminal, run the following command (replace username with the actual cPanel username):

cd /home/username/public_html

Confirm you are in the correct location:

ls

You should see the folders wp-admin, wp-content, and wp-includes.

—————

Step 3 – Verify WordPress Installation

Use the following command to confirm WP-CLI can see the WordPress installation:

wp core version --path=/home/username/public_html --allow-root

You should receive the installed WordPress version number (for example, 6.6.2).
If the command fails with “wp not found”, you’ll need to install WP-CLI (see Step 7).

—————

Step 4 – Run the Import Command

To import the posts and their associated images, use this command:

wp import /home/username/export-posts.xml --authors=create --path=/home/username/public_html --allow-root

What this does:

Imports only the posts listed in the XML file.

Downloads and attaches all referenced images.

Creates any missing authors.

Does not affect pages, users, themes, or plugins.

If you already copied the /uploads/ folder manually and don’t need images re-downloaded, add the --skip=attachment flag:

wp import /home/username/export-posts.xml --authors=create --skip=attachment --path=/home/username/public_html --allow-root

—————

Step 5 – Flush Permalinks

After completing all XML imports, flush permalinks once at the very end:

wp rewrite flush --path=/home/username/public_html --allow-root

Note: Flushing permalinks regenerates WordPress rewrite rules so that URLs work correctly.
You only need to run this command once after all imports are finished, not after each individual import file.

—————

Step 6 – Optional Cleanup and URL Updates

If the domain name changed, update URLs inside post content and metadata:

wp search-replace 'https://oldsite.com' 'https://newsite.com' --skip-columns=guid --path=/home/username/public_html --allow-root

To regenerate missing thumbnails:

wp media regenerate --only-missing --path=/home/username/public_html --allow-root

—————

Step 7 – Installing WP-CLI (If Needed)

If the wp command isn’t available, install WP-CLI once globally:

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
chmod +x wp-cli.phar
mv wp-cli.phar /usr/local/bin/wp
wp --info

Confirm the installation using:

wp --info

If your server uses EasyApache PHP (for example, EA-PHP82), run WP-CLI through that PHP binary:

/opt/cpanel/ea-php82/root/usr/bin/php /usr/local/bin/wp --info

—————

Safety Notes

Always specify the --path parameter to ensure commands run only inside the intended WordPress installation.

Using --allow-root lets WP-CLI execute as root without enabling shell access for the cPanel user.

File ownership may change for newly uploaded media; if needed, reset ownership after the import:

chown -R username:username /home/username/public_html/wp-content/uploads

This method affects only the specified site and cannot impact other cPanel accounts or WordPress installations on the server.

—————

Summary

Running WP-CLI from WHM Terminal as root with the --path and --allow-root flags provides a safe and reliable way to import WordPress posts and images without enabling shell access or risking timeouts.

By targeting a specific cPanel user’s site, you ensure precise control, zero downtime, and complete safety for all other customers on the server.

    • Related Articles

    • How to Replace WordPress Cron with a Real Cron Job

      Have you ever noticed that your scheduled posts in WordPress are missing? Though WordPress has its own cron feature that dictates the scheduling of your blog’s posts and events, WP-cron is not a literal cron job. Linux cron job vs. WP-cron The user ...
    • Step-by-Step Guide: Moving a Joomla Website Between cPanel Accounts

      Preparation • Ensure you are authorized to move the site. • In the source cPanel, note the document root (usually public_html). • In Joomla admin, optionally set the site Offline to freeze content during migration. • Verify the PHP version used on ...
    • How to Install a Custom Font in WordPress

      Option 1: Using a Plugin (Easiest Method) If you want to avoid editing theme files, you can use a plugin. Steps: 1. Log in to your WordPress Admin Dashboard. 2. Go to Plugins → Add New Plugin. 3. Search for one of these plugins: – Use Any Font (very ...
    • Setting the Default Blog Archive Page in WordPress (Using Elementor Template Kits)

      If you’re using an Elementor Template Kit, your Blog Archive page (the page that lists your blog posts) may not automatically display correctly until you designate it as the default “Posts Page” in WordPress and apply the correct Elementor template. ...
    • How to Get Google Sitelinks for Your Website

      Google sometimes shows extra sub-links under your website’s main search result. These are called sitelinks, and they help users navigate directly to important pages of your site. You can’t turn them on manually, but you can improve your chances of ...
    • Popular Articles

    • How to add your Microsoft 365 Email on an iPhone using the Outlook app

      How to Set Up Microsoft 365 Email on Your iPhone Using Outlook This guide will walk you through downloading the Outlook app and adding your Microsoft 365 email account on your iPhone. ————— Step 1: Download the Outlook App 1. Open the App Store on ...
    • Outlook Error "5objp" when setting up email on Outlook App

      Follow these steps if you are having trouble signing into Outlook with your Microsoft 365 account: ————— Step 1: Start with the onmicrosoft.com Address • First, try signing in using the @myorg.onmicrosoft.com format email address. – Example: ...
    • How to update your credit card on file

      Do you need to update your credit card on file within the Twilight I.T. Customer Portal? Here is what you need to do... Step 1: Log into the portal at https://portal.twilightit.com Step 2: Click on BILLING in the top menu. Step 3: Click on PAYMENT ...
    • How to view or download invoices on your account

      Here is the process of viewing and/or downloading invoices on your account with Twilight I.T. Step 1: Log into the client portal at https://portal.twilightit.com Step 2: Click on the BILLING menu Step 3: From here you can view all your invoices. If ...
    • How to add your Microsoft 365 Email on an Android phone using the Outlook app

      How to Set Up Microsoft 365 Email on Your Android Phone Using Outlook This guide will walk you through downloading the Outlook app and adding your Microsoft 365 email account on your Android device. ————— Step 1: Download the Outlook App 1. Open the ...