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.