Uk2 Logo

Knowledgebase

Search Articles

Categories

  • Back to How To's

    How to Install WordPress Using WP-CLI


    WP-CLI is a command-line tool for managing WordPress installations. It allows you to download, configure, and install WordPress without using a browser or control panel.

    This method requires SSH access to the server.


    Prerequisites

    • SSH access to the server
    • A MySQL database and database user already created for the site
    • The document root of the domain must be empty or not yet containing a WordPress installation

    Steps

    1. Navigate to the Document Root

    Change to the directory where WordPress should be installed - typically public_html or a subdirectory:

    cd ~/public_html

    2. Download WordPress Core Files

    wp core download

    This downloads the latest version of WordPress into the current directory.

    3. Create the wp-config.php File

    wp config create --dbname=your_database --dbuser=your_db_user --dbpass='your_db_password' --dbhost=localhost

    Replace your_database, your_db_user, and your_db_password with the actual database credentials. The password must be wrapped in single quotes - database passwords often contain special characters such as !, =, or $ that the shell will misinterpret if the value is unquoted or double-quoted.

    4. Install WordPress

    wp core install --url="https://example.com" --title="Site Title" --admin_user="admin" --admin_password="securepassword" --admin_email="[email protected]"

    Replace the values with the appropriate site URL, title, and admin credentials.

    5. Verify the Installation

    wp core version

    This should return the installed WordPress version, confirming the installation was successful.


    Useful Additional Commands

    CommandDescription
    wp plugin listList all installed plugins
    wp plugin install <plugin>Install a plugin by slug
    wp theme listList all installed themes
    wp user listList all WordPress users
    wp cache flushFlush the WordPress object cache
    wp core updateUpdate WordPress to the latest version

    Troubleshooting

    PHP memory exhausted error

    If you see an error like:

    PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 36864 bytes) in phar:///usr/local/bin/wp/...

    This means PHP's memory limit (128MB by default) is too low for WP-CLI to complete the operation. Prefix your command with php -d memory_limit=512M to override the limit for that run:

    php -d memory_limit=512M /usr/local/bin/wp core download
    php -d memory_limit=512M /usr/local/bin/wp core install --url="https://example.com" ...

    This only applies to the single command - it does not change the server's PHP configuration permanently.


    Notes

    • If WP-CLI is not available, contact 20i Support team to confirm whether it is installed.
    • Always use a strong admin password - avoid using default or obvious values.
    • The --allow-root flag may be required if running commands as the root user, though this is not recommended.

    Related Articles

    How to Install Wordpress
    How to Access and Edit a WordPress Site
    Permalinks

    Can’t Find what you need?

    No worries, Our experts are here to help.