Install WordPress via Command Line

This is how to install WordPress via the command line or terminal. This gets the latest version of WordPress and installs it on your server. This is a lot faster than downloading WordPress and uploading it to your server via FTP.

To run these commands, you must have an SSH client installed. (On Windows, you can use PuTTY, which you can download for free.) You must also make sure that your host grants you SSH access to your server.

  1. Make an SSH connection to your server via your SSH client (via PuTTY on Windows). In a Linux/Ubuntu terminal, you can simply do:
    ssh YOUR_FTP_USERNAME@domain.com 

    replacing “YOUR_FTP_USERNAME” and “domain.com” with your own details.

  2. Go to the directory for the website in which you want to install WordPress.
    cd html/sitedir/
    
  3. Get the latest WordPress package and extract it.
    wget https://wordpress.org/latest.tar.gz
    tar xfz latest.tar.gz
    
  4. Move the files out of the wordpress folder and into your site’s root.
    mv wordpress/* ./
    
  5. Delete the .tar.gz file and empty wordpress directory, which we no longer need.
    rmdir ./wordpress/
    rm -f latest.tar.gz
    
  6. Create the wp-config.php file with the command:
    cp wp-config-sample.php wp-config.php
    
  7. Open wp-config.php in the VI editor:
    vi wp-config.php
    
  8. Add your database details to wp-config.php in the VI editor. For this, you should have already created a new database on your server for WordPress to use. You’ll need to gather this information about the database:
    • Database Name
    • Database Username
    • Database Password
    • Database Host

    Those 4 bits of information go into the first 4 lines, respectively, of wp-config.php (ignoring comments). On the command line, you’ll type “i” to insert. Then use your arrow keys to move the cursor to where you want to type the new information.

    For example, the first line of code (ignoring comments) looks like this:

    define( 'DB_NAME', 'database_name_here' );

    So, change ‘database_name_here‘ into your own database name. Make the 4 changes with the 4 bits of information that I listed above. You can either type your text into the VI editor, or you can also paste text into the VI editor (Ctrl + Shift + V in Ubuntu).

  9. Add your security keys to wp-config.php in the VI editor. First, as recommended by WordPress, go here to generate your own keys: https://api.wordpress.org/secret-key/1.1/salt/. Copy all of the text on that web page. Now, in the VI editor, move your cursor to the part of wp-config.php where you see this:
    define('AUTH_KEY',         'put your unique phrase here');
    define('SECURE_AUTH_KEY',  'put your unique phrase here');
    define('LOGGED_IN_KEY',    'put your unique phrase here');
    define('NONCE_KEY',        'put your unique phrase here');
    define('AUTH_SALT',        'put your unique phrase here');
    define('SECURE_AUTH_SALT', 'put your unique phrase here');
    define('LOGGED_IN_SALT',   'put your unique phrase here');
    define('NONCE_SALT',       'put your unique phrase here');
    

    Delete those lines and replace them with the security keys that you copied. To paste your copied keys into the VI editor, simply use the arrows to move the cursor to the positions where you want to paste your text. Then press the RIGHT mouse button; your text will be pasted.

  10. Save your changes to wp-config.php in the VI editor.
    • Press the escape key on your keyboard (“Esc“).
    • On the command line, type:
      :wq
  11. Exit:
    exit
  12. Go to your site in your browser. You will be redirected to yoursite.com/wp-admin/install.php. Fill in the requested information and click “Install WordPress“.

Also see my favorite settings for an optimized wp-config.php file.

See more:

We've 2 Responses

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]