Setup WordPress via the Command Line

This is, in my opinion, the easiest way to do a manual install of WordPress. This tutorial is aimed at running WordPress on a Cloud Server, VPS, or Dedicated Server. We are assuming that you are comfortable loading up an SSH client, or using a web-based console. We based this tutorial on a fresh install of Ubuntu 17.04, with a fresh install of the LAMP stack.

Note:  The following is for intermediate level users. If you don’t feel comfortable many server companies offer WordPress as a “one-click” install application. If you want to use a “one-click” method to run WordPress on its own server, check out our guide to creating a server with WordPress in under 15 minutes.

Note:  This tutorial assumes that you are running as root. If you are running as another user you may need to use the sudo command prior to the following commands.

Step 1 – Obtain the latest copy of WordPress and place it in the desired directory

The obvious first step is to download the latest version of WordPress onto your server.  This can be accomplished with the following steps:

  1. Change directory to your public html directory, on Ubuntu 17.04 it is /var/www/html

$ cd /var/www/html

  1. Download the latest copy of WordPress with wget

$ wget

  1. If necessary install the Unzip utility. Unzip WordPress zip file.

$ apt-get install unzip

$ unzip ./

  1. Rename the “wordpress” folder to the name you desire. This will be how you access your WordPress site. (In this example it would be

$ mv ./wordpress ./blog

Note:  If you would like to run WordPress as the default on your site you can execute the following commands, this will rename the default apache page so it won’t be served, and it will move all files in your wordpress directory to the main public html directory.

$ cd /var/www/html 

$ mv ./index.html  ./index.html.old

$  cd ./wordpress

$ mv ./*.* ../

 Step 2 – Set WordPress permissions

To allow the required permissions for WordPress to function we will change the owner of your public html directory to www-data. This is the account Apache usually runs under.

$ chown –R www-data:www-data /var/www

Note: If you are not running as root, you will need to add your user to the www-data group with the following command:

$ sudo usermod –aG www-data yourusername

Step 3 – Create the WordPress Database

Now we will create the database that WordPress will use to store most of its data.

  1. Login to the MySQL Console, in this case, we are using the root user, your user may vary.

$ mysql -u root –p

  1. MySQL will now ask you for the root database users password, type it in, and press enter
  2. Create a database user specifically for WordPress. In this example, wordpress represents the database username, and ‘AscfSE@b134D!’ represents the password. You can change these to whatever you desire, but keep the single quotes ( ‘ ‘) around it.

mysql> create user 'wordpress'@'localhost' identified by 'AscfSE@b134D!';

  1. Create the database for wordpress.

mysql> create database wordpress;

  1. Grant the wordpress user privileges. Use the “usage” level to prevent this user from doing anything but accessing MySQL

mysql> grant usage on *.* to wordpress@localhost;

  1. Grant your wordpress user all privileges to only the wordpress database

mysql> grant all privileges on wordpress.* to wordpress@localhost;

Step 4 – Launch WordPress installer

So you should be all set from the command line. Open a browser and visit . Follow the following steps and you will be good to go.

  1. Enter your database information. This will be the information you entered for the database name, username, and password above.

WordPress Database Screen


2. Set your Site info & admin username and password


3. Login to WordPress with the credentials you just provided and write a test post


4. Visit your site to see if it works (you can see our result from the steps above here)

6. Enjoy your new installation!

Leave a Reply


%d bloggers like this: