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 install Office Apps (365) to your Windows or Mac computer

      How to Download and Install Microsoft 365 Office Apps (Windows and Mac) This guide will walk you through downloading and installing the Microsoft 365 Office apps, including Word, Excel, PowerPoint, Outlook, and more. The steps are nearly the same for ...
    • How to Save and Share a Document in OneDrive from Word or Excel

      Follow these steps to save your document to OneDrive and share it with others directly from Word or Excel. ————— Step 1: Save to OneDrive 1. In Word or Excel, click File. 2. Select Save As. 3. Choose OneDrive – [Your Organization or Personal]. 4. ...
    • How to Collaborate on a Document in Real-Time with Others

      Microsoft 365 allows you to co-author documents with colleagues in Word, Excel, or PowerPoint. ————— Step 1: Save to OneDrive or SharePoint 1. Open your file in Word, Excel, or PowerPoint. 2. Click File > Save As and select OneDrive or SharePoint. ...
    • How to Recover Unsaved or Previous Versions of Office Files

      If you lose changes or accidentally close a document, you can often recover it using Office’s built-in recovery tools. ————— Step 1: Recover Unsaved Files 1. Open Word, Excel, or PowerPoint. 2. Go to File > Info > Manage Document (or Manage ...
    • How to Use Templates in Word, Excel, and PowerPoint

      Microsoft Office apps come with ready-to-use templates to save you time. ————— Step 1: Access Templates 1. Open Word, Excel, or PowerPoint. 2. From the start screen, you’ll see featured templates. 3. Or click File > New to browse available templates. ...