How to Set Up WordPress in Under 2 Minutes Using cPanel Terminal
Installing WordPress through cPanel Terminal is a useful alternative to uploading WordPress files manually or using an automatic installer.
Overview
- Create subdomain
↓ - Create database
↓ - Create database user
↓ - Assign user to database with ALL PRIVILEGES
↓ - Edit 6 values at top of script
↓ - Run script
↓ - Script downloads WordPress
↓ - Script creates wp-config.php
↓ - Script generates salts
↓ - Script sets permissions
↓ - Script checks PHP syntax
↓ - Open website
↓ - Complete WordPress browser setup
This method downloads the latest Australian English version of WordPress, configures the database connection, generates security keys and sets file permissions using Bash and PHP commands.
You don’t need WP-CLI or a separate installation script file.
Before you start
You need:
- Access to cPanel and Terminal or SSH.
- A domain or subdomain pointing to the correct website directory.
- A MySQL or MariaDB database.
- A database username and password.
- A database user assigned to the database with the required privileges.
This guide is intended for a fresh WordPress installation in an empty website directory, not an existing website.
Step 1. Create a MySQL database in cPanel
- Log in to cPanel.
- Open Database Wizard (or MySQL Database Wizard, depending on your cPanel version).
- Enter a database name, for example
wordpress_dev. - Click Next Step.
cPanel may automatically add your hosting account prefix.
For example:
starconfig_wordpressdev
Copy the full database name, including the prefix.
Step 2. Create a database user and password
In the Database Wizard:
- Enter a username, for example
wpdev. - Generate a strong password using the password generator.
- Store the password securely.
- Click Create User.
Example database details:
| Setting | Example |
|---|---|
| Database name | starconfig_wordpressdev |
| Database username | |
| Database password | Your generated password |
| Database host | localhost |
The database name and username are not necessarily the same.
Step 3. Assign the user to the database
Select ALL PRIVILEGES for the new database user and save the changes.
This grants the database user the permissions needed to create and modify the WordPress tables during installation.
If you created the database and user separately rather than using the wizard, use Manage My Databases → Add User to Database to assign the user and privileges.
You now have the three main details required by the installation script: database name, database username and password.
Step 4. Open cPanel Terminal
In cPanel, navigate to:
Advanced → Terminal
Alternatively, connect to your hosting account through SSH.
First, check your current location:
pwd
Example output:
/home/starconfig
List all files and folders:
ls -lah
To see folders one level above:
ls -lah ..
To return to your home directory:
cd ~
Step 5. Navigate to your website directory
Before installing WordPress, navigate to the folder assigned to your domain or subdomain.
For example:
cd /home/starconfig/test.example.com
You can find the website’s document root in cPanel → Domains.
Once you are inside the correct directory, run:
pwd
ls -lah
You should see the path to your website and the contents of its directory.
Important: The installer below requires an empty directory. Do not run it inside an existing WordPress website or a folder containing other website files.
Step 6. Install WordPress using Bash
Copy the following commands into your terminal.
Before running them, update the database name, username, password and host in the first section.
bash <<'BASH'
set -euo pipefail
# ============================================================
# WORDPRESS INSTALLATION VIA TERMINAL
# ============================================================
# Install WordPress in the current directory.
# Stop if an existing website is detected.
# No WP-CLI or separate script file required.
# ============================================================
# ============================================================
# 1. CHANGE ONLY THESE DATABASE VALUES
# ============================================================
DB_NAME="db-name-update-this"
DB_USER="db-user-update-this"
DB_PASSWORD='Pasword-update-this'
DB_HOST="localhost"
TABLE_PREFIX="sc26_"
# ============================================================
# 2. DETECT WEBSITE LOCATION AUTOMATICALLY
# ============================================================
SITE_PATH="$(pwd)"
echo ""
echo "Website installation directory:"
echo "$SITE_PATH"
echo ""
echo "Files and folders in this directory:"
ls -lah
# ============================================================
# 3. CHECK DIRECTORY AND REQUIREMENTS
# ============================================================
# Never install in the server root or account home.
if [[ "$SITE_PATH" == "/" || "$SITE_PATH" == "$HOME" ]]; then
echo "ERROR: Navigate to your website folder first."
exit 1
fi
# Stop if database details have not been changed.
if [[ "$DB_NAME" == "database_name" ||
"$DB_USER" == "database_username" ||
"$DB_PASSWORD" == "database_password" ||
-z "$DB_NAME" ||
-z "$DB_USER" ||
-z "$DB_PASSWORD" ]]; then
echo "ERROR: Update your database details first."
exit 1
fi
# Check database table prefix.
if [[ ! "$TABLE_PREFIX" =~ ^[A-Za-z0-9_]+$ ]]; then
echo "ERROR: Invalid database table prefix."
exit 1
fi
# Check required terminal commands.
for tool in wget unzip php mktemp; do
if ! command -v "$tool" >/dev/null 2>&1; then
echo "ERROR: Missing required command: $tool"
exit 1
fi
done
# Allow only common hosting-generated files/folders.
# Stop if other website content already exists.
if find . -mindepth 1 -maxdepth 1 \
! -name '.htaccess' \
! -name '.well-known' \
! -name '.user.ini' \
! -name 'cgi-bin' | grep -q .; then
echo "ERROR: Website directory contains existing files."
echo "Installation stopped to prevent overwriting."
exit 1
fi
echo "Directory checks passed."
# ============================================================
# 4. DOWNLOAD WORDPRESS
# ============================================================
echo "Downloading WordPress..."
# Use a temporary folder to protect the website directory.
TMP_DIR="$(mktemp -d)"
trap 'rm -rf -- "$TMP_DIR"' EXIT
wget -q -O "$TMP_DIR/wordpress.zip" \
https://en-au.wordpress.org/latest-en_AU.zip
# ============================================================
# 5. EXTRACT WORDPRESS
# ============================================================
echo "Extracting WordPress..."
unzip -q "$TMP_DIR/wordpress.zip" -d "$TMP_DIR"
cd "$TMP_DIR/wordpress"
# ============================================================
# 6. CREATE WP-CONFIG.PHP
# ============================================================
echo "Creating WordPress configuration..."
cp wp-config-sample.php wp-config.php
# ============================================================
# 7. MAKE DATABASE VALUES AVAILABLE TO PHP
# ============================================================
export DB_NAME DB_USER DB_PASSWORD DB_HOST TABLE_PREFIX
# ============================================================
# 8. CONFIGURE DATABASE, TABLE PREFIX AND SECURITY KEYS
# ============================================================
php <<'PHP'
<?php
$file = 'wp-config.php';
$config = file_get_contents($file);
if ($config === false) {
fwrite(STDERR, "ERROR: Cannot read wp-config.php\n");
exit(1);
}
// Replace one setting safely, including special characters.
function replace_setting($config, $key, $value) {
$pattern = "/define\(\s*'" .
preg_quote($key, '/') .
"'\s*,\s*'[^']*'\s*\);/";
$replacement = "define( '$key', " .
var_export($value, true) . " );";
$count = 0;
$config = preg_replace_callback(
$pattern,
static function () use ($replacement) {
return $replacement;
},
$config,
1,
$count
);
if ($config === null || $count !== 1) {
fwrite(STDERR, "ERROR: Cannot update $key\n");
exit(1);
}
return $config;
}
// Database settings.
$settings = [
'DB_NAME' => getenv('DB_NAME'),
'DB_USER' => getenv('DB_USER'),
'DB_PASSWORD' => getenv('DB_PASSWORD'),
'DB_HOST' => getenv('DB_HOST'),
];
foreach ($settings as $key => $value) {
$config = replace_setting($config, $key, $value);
}
// Table prefix.
$prefix = getenv('TABLE_PREFIX');
$count = 0;
$config = preg_replace_callback(
'/\$table_prefix\s*=\s*[\'"]wp_[\'"]\s*;/',
static function () use ($prefix) {
return '$table_prefix = ' .
var_export($prefix, true) . ';';
},
$config,
1,
$count
);
if ($config === null || $count !== 1) {
fwrite(STDERR, "ERROR: Cannot update table prefix\n");
exit(1);
}
// WordPress security keys and salts.
$keys = [
'AUTH_KEY',
'SECURE_AUTH_KEY',
'LOGGED_IN_KEY',
'NONCE_KEY',
'AUTH_SALT',
'SECURE_AUTH_SALT',
'LOGGED_IN_SALT',
'NONCE_SALT',
];
foreach ($keys as $key) {
$config = replace_setting(
$config,
$key,
bin2hex(random_bytes(32))
);
}
// Save configuration.
if (file_put_contents($file, $config, LOCK_EX) === false) {
fwrite(STDERR, "ERROR: Cannot save wp-config.php\n");
exit(1);
}
echo "WordPress configuration completed.\n";
PHP
# ============================================================
# 9. TEST WP-CONFIG.PHP
# ============================================================
echo "Checking PHP syntax..."
php -l wp-config.php
# ============================================================
# 10. MOVE WORDPRESS INTO WEBSITE DIRECTORY
# ============================================================
echo "Installing WordPress files..."
cp -a ./. "$SITE_PATH/"
cd "$SITE_PATH"
# ============================================================
# 11. CREATE UPLOADS DIRECTORY
# ============================================================
mkdir -p wp-content/uploads
# ============================================================
# 12. SET WORDPRESS FILE PERMISSIONS
# ============================================================
echo "Setting WordPress permissions..."
find wp-admin wp-includes wp-content \
-type d -exec chmod 755 {} +
find wp-admin wp-includes wp-content \
-type f -exec chmod 644 {} +
find . -maxdepth 1 -type f \
-exec chmod 644 {} +
chmod 400 wp-config.php
# ============================================================
# 13. INSTALLATION COMPLETE
# ============================================================
echo ""
echo "============================================"
echo "WORDPRESS FILE INSTALLATION COMPLETE"
echo "============================================"
echo ""
echo "Location: $SITE_PATH"
echo "Database: $DB_NAME"
echo "Table prefix: $TABLE_PREFIX"
echo ""
echo "Open your website to complete WordPress setup."
echo "============================================"
BASH
The script will:
- Detect your current website directory.
- Check that the directory is empty.
- Test the database connection before downloading WordPress.
- Download and extract WordPress.
- Create and configure
wp-config.php. - Generate WordPress security keys.
- Set file and directory permissions.
- Check the PHP configuration syntax.
It does not require WP-CLI or a separate .sh file.
Password security: Use single quotes around the database password in the Bash settings. If your password contains an apostrophe, it needs proper shell escaping. Never publish real database credentials in a blog post or commit them to a public repository. Passwords pasted into terminals may also be retained in terminal or session records.
The 400 permission for wp-config.php works only when the hosting/PHP process can read the file as its owner. If your hosting configuration requires different permissions, use the most restrictive supported setting.
Step 7. Complete the WordPress installation

After the terminal confirms that the WordPress files are installed, open your domain or subdomain in a browser.
For example:
The WordPress installation screen will ask for:
- Site title.
- WordPress administrator username.
- Strong administrator password.
- Administrator email address.
- Search engine visibility preference.
For a private development website, select the option to discourage search engines from indexing the website. This is not a security measure, so development sites should also use authentication or other appropriate access restrictions.
Click Install WordPress.
When the installation is complete, log in to your new WordPress dashboard:
Common installation problems
| Problem | What to check |
|---|---|
| Database connection failed | Check the database name, username, password and host |
| Access denied to database | Check that the database user has been assigned privileges |
| Directory is not empty | Confirm you are installing into the correct new website folder |
| Permission denied | Check cPanel file ownership and permissions |
| Command not found | Check that Bash, PHP, wget and unzip are available |
| WordPress configuration error | Check the PHP version and wp-config.php syntax |
Conclusion
Installing WordPress through cPanel Terminal is a practical method for developers managing multiple websites.
Once the database and database user are created, WordPress files can be downloaded, configured and prepared using one reusable Bash command block.
The most important step is confirming the correct website directory and database credentials before running the installation.