How to install wordpress via command line

May 14, 2018/0/0
wordpress installation

This article is intended to walk a user through installing a new copy of WordPress via BASH command line.

Sidenote: If you are copying and pasting these commands into your terminal, do not copy the #. It is there to notate a block of code.

Getting Started

First, navigate to the directory which you would like to install the new copy of WordPress to. The default location in ubuntu would be: /var/www/html

# cd /var/www/html


Once you are in the correct directory, run this string of commands to download and extract a new copy of WordPress to the current working directory in Linux command line:

# wget http://wordpress.org/latest.zip; unzip latest.zip; cd wordpress; mv * ..; cd ..; rm -rf wordpress

As an example, presume you ran this command in the document root folder of example.com. Upon navigating to http://example.com/ you should find a WordPress install page.

This means that WordPress was downloaded and extracted to the correct directory. If you do not see this screen, clear your browser cache and cookies and refresh. If you still don’t see this you probably downloaded and extracted WordPress to the wrong directory — meaning you need to locate your website’s document root directory and then run the first string of commands in the correct folder.

Next, I would suggest ensuring that you have the proper ownership set up on the files and folders. Navigate back to the root folder using the cd command, then set the ownership using the following command:

# cd
# sudo chown -R www-data /var/www/html

Setting up the database

We now have to create a database that the new WordPress installation will use. To run these commands successfully you will need to know your main MySQL username and password. In this example we will pretend that my main MySQL username is “user” and my password is “password”.

In your command prompt run:

# mysql -u user -p

Then type in your password to log in to the MySQL command prompt. If it fails you are most likely using the wrong password or username.

Once logged in to mysql command prompt type in this command to create a database. This example will create a database named “wordpress”.

# CREATE DATABASE wordpress;

Now that we have a database created we need to assign a user to it. If you would like to create a new user to it run this command to create the new user and set the user’s password:

# CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';

Once the user is created, or if you have already created the user, run this command to assign “user” to the database named “wordpress” by granting user with all the permissions for wordpress.

# GRANT ALL ON wordpress.* TO 'user'@'localhost';

Finish the installation

Now you are ready to fill out the information needed to finish the WordPress information, as shown in the next image. Go back to example.com and press “Let’s Go!”. Again, the example image will show the MySQL database user is “user”, with “password” as the password, and “wordpress” as the database name.

Assuming all your file permissions are correct in the document root directory of your website you should be given a prompt to “Run the Install”.

Common errors

Sometimes you will get an error that says “Sorry, but i can’t write the wp-config.php file. You can create the wp-config.php file manually and paste the following text into it.” ex:

To fix this, you will need to edit your document root directory permissions to be 755 and ensure that your web server user is the owner of the folder. Alternatively, you may need to create a file named wp-config.php with the specified code in it in the root WordPress folder. I would recommend fixing the permissions rather than just adding the file because WordPress will need the correct file permissions

If the install worked properly, when you visit the new site for the first time, you will be asked to setup your admin username and password. Congrats! You just installed WordPress via the command line!

wordpress setup

Credits: Spencer Heywood
Visit his personal blog here: https://www.the-empire.systems

Navigation

Add comment