How to install WordPress with (almost) just the command line

This guide intends to walk you through every step of a WordPress install, and to avoid the use of a GUI whenever possible. It was designed with NearlyFreeSpeech.NET hosting in mind, but may be helpful on other hosts as well.

First, we’ll set up the database that WordPress needs to run.

  1. Log into phpMyAdmin (or equivalent UI for your server’s MySQL Database).
  2. Click on “Databases”.
  3. Create a new database by providing a database name like “sitenamewp”, then clicking “Create”. WordPress recommends using “utf8mb4_general_ci” collation when creating a database. Write the database name down–it will be required later.
  4. Return to the main page by clicking the home icon in the top left.
  5. Click “User Accounts”
  6. Click “Add user account”
  7. Give the user a name like “wpuser_sitename” Write the user name down–it will be required later.
  8. Generate a password for the user by clicking the “Generate” button. Write the password down–it will be required later.
  9. Click “Go” to create the user.
  10. Go back to “User accounts”, then click “Edit privileges” for the recently created user.
  11. Click “Database”.
  12. Select the database that you created for this WordPress site, then click “Go”.
  13. Click “Check all”, then click “Go” to give this user all permissions on the selected database.
  14. Look at the top of the page and write down the host name for your MySQL server. It will look something like “hostname.db” and be found after the text “Server:”.
  15. Next, we’ll install WordPress on the web server. Use PuTTY to SSH into the server where you wish to install WordPress.
  16. Run
    wp core download

    To get the latest for WordPress. It may take a few moments. Wait for it to complete.

  17. Replace the bracketed text with the database info that you wrote down in steps 3, 7, 8, and 14, then run
    wp core config --dbhost=[step14] --dbname=[step3] --dbuser=[step7] --dbpass=[step8]

    The actual command should look something like this below (but won’t be exactly the same)

    wp core config --dbhost=hostname.db --dbname=sitenamewp --dbuser=wpuser_sitename --dbpass=R@ndomP@$w0rd
  18. Run
    chmod 644 wp-config.php

    To change the permissions of the wp-config.php file.

  19. Replace the bracketed text with your actual site URL, site name, admin user, admin user password, and admin user email, then run
    wp core install --url=[url] --title="[title]" --admin_user=[user] --admin_password=[pass] --admin_email=[email]

    The actual command should look something like this below (but won’t be exactly the same)

    wp core install --url=sitename.nfshost.com --title="Site Name" --admin_user=AdminUsername --admin_password=AdminP@$w0rd --admin_email=example@example.com
  20. In PuTTY, run the following commands one after another:
    cd wp-content
    mkdir -p uploads
    chgrp -R web uploads
    chmod -R 775 uploads
    cd ..

    This should ensure that you can upload files to your site (based on the recommendation here.)

  21. In PuTTY, run the following command:
    touch .htaccess

    This creates an empty .htaccess file, which can be used for setting up permalinks.

  22. In PuTTY, run the following commands one after another:
    chgrp -R web ../public
    find ../public -type f -exec chmod 664 {} \;
    find ../public -type d -exec chmod 775 {} \;
    chgrp -R web *
    find . -type d -exec chmod 775 {} \;
    find . -type f -exec chmod 664 {} \;

    This will allow the web server to create and modify files. It also sets proper permissions for directories and files. It’s riskier than using the WordPress CLI from a security standpoint, but more convenient for WordPress users.

  23. Optionally, add the line, define('FS_METHOD','direct'); to the wp-config.php file, immediately before the /* That's all, stop editing! Happy publishing. */ line. This can make WordPress, Theme, and Plugin upgrades easier, but be sure you are aware of the security concerns before doing this. To edit the wp-config.php file…
    Run pico wp-config.php
    Add define('FS_METHOD','direct');in the location described above
    Press CTRL + X to exit pico
    Then press Y to Save modified buffer, then press Enter to confirm the save.
  24. Since we wrote passwords on the command line, you may wish to clear the history with
    history -c
  25. Exit PuTTY with the exit command

And that’s it! WordPress should be set up and ready to go! You can visit and log in to your site using the admin credentials and the URL you specified in step 19.

Do these steps not work for you? You can run wp --info to see if your server has the wp cli already. Servers not running the wp cli may need a more manual install of WordPress, such as the steps listed here.

Leave a Comment

Your email address will not be published. Required fields are marked *