How to install WordPress on Ubuntu Linux

Andrei Maksimov

Andrei Maksimov

0
(0)

WordPress is a multi-platform content management system (CMS) for managing and creating websites, internet-shops and blogs. WordPress is used by small businesses, individual bloggers, educational institutions, nonprofit organizations, and even giant organizations, implying that it is suitable for everyone, regardless of who you are or what you want to achieve with your website. According to w3techs.com WordPress consumes more than 63% of the CMS market, and that percentage is constantly rising. In this article we’ll show you how you can install WordPress on your Ubuntu server.

Prerequisites

Installing WordPress

As soon as you’ve installed the LAMP stack, we can move forward to the WordPress installation itself.

Creating database

In this section we’ll do the following:

  • Create WordPress database
  • Create WordPress role – defines permissions to access the database
  • Create WordPress user
  • Attach WordPress role to WordPress user
  • Test user connection to the database

Let’s open MySQL console client:

sudo mysql
1. How to install WordPress on Ubuntu Linux - sudo mysql

Now, you can create a WordPress database:

CREATE DATABASE wordpress_db;
3. How to install WordPress on Ubuntu Linux - MySQL - create database

As the next step, we need to create a database role for WordPress user:

CREATE ROLE wordpress_role;
3. How to install WordPress on Ubuntu Linux - MySQL - create role

And grant WordPress role access to WordPress database:

GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_role';
4. How to install WordPress on Ubuntu Linux - MySQL - grant privileges to role

Now, we can create a database user for WordPress:

CREATE USER wordpres@localhost IDENTIFIED BY RANDOM PASSWORD;
5. How to install WordPress on Ubuntu Linux - MySQL - create user

Note: save generated password somewhere, you’ll need it soon.

Finally, we need to grant wordpress_role role to the wordpress user and set it as default role:

GRANT 'wordpress_role' TO 'wordpress_user'@'%';
SET DEFAULT ROLE 'wordpress_role' to 'wordpress_user'@'%';
6. How to install WordPress on Ubuntu Linux - MySQL - grant user role

Now, exit from the MySQL client by pressing Ctrl+d and test that the WordPress user can connect to the database:

mysql -u wordpress_user -p
7. How to install WordPress on Ubuntu Linux - MySQL - wordpress user connection test

We have finished a database creation part successfully.

Downloading WordPress

At this stage we need to download WordPress and make required changes with its source code.

First of all, let’s download the WordPress distribution:

wget https://wordpress.org/latest.tar.gz
8. How to install WordPress on Ubuntu Linux - Distribution download

Now, let’s extract the downloaded archive (for more information on using tar, read How to extract .gz and .tar.gz files in Linux):

tar xzvf latest.tar.gz
9. How to install WordPress on Ubuntu Linux - Untar distribution

We will copy these files into our Apache document root folder as soon as we finish required configuration steps.

WordPress initial configuration

Let’s start from creating a .htaccess file first:

touch wordpress/.htaccess
10. How to install WordPress on Ubuntu Linux - .htaccess file

Now, create a WordPress configuration file by copying the wp-config-sample.php file to the wp-config.php:

cp wordpress/wp-config-sample.php wordpress/wp-config.php
11. How to install WordPress on Ubuntu Linux - Creating wp-config.php file

Next, create an upgrade directory:

mkdir wordpress/wp-content/upgrade
12. How to install WordPress on Ubuntu Linux - Creating upgrade folder

Use the curl command to get random keys required for WordPress to function (save them somewhere, we’ll use them in a second):

curl -s https://api.wordpress.org/secret-key/1.1/salt/
13. How to install WordPress on Ubuntu Linux - Getting random keys

Now, let’s edit wp-config.php file:

nano wordpress/wp-config.php

Make required changes to specify WordPress database connection:

14. How to install WordPress on Ubuntu Linux - wp-config.php - DB connection

Scroll down the file and edit random WordPress keys:

15. How to install WordPress on Ubuntu Linux - wp-config.php - random keys and salts

Once the database credentials and WordPress random secure keys and salts are added, save your file by pressing CTRL+x, y, and Enter.

Important: I’m assuming, that you’re installing WordPress on a brand new server, so, I’ll clean up Apache server document root folder (/var/www/html) and copy wordpress folder content there.

rm -Rf /var/www/html/*
sudo cp -R wordpress/* /var/www/html/
16. How to install WordPress on Ubuntu Linux - Deploying WordPress to Apache

Now, we’re ready to finalize WordPress deployment in Web UI.

WordPress installation (web interface)

Launch your browser and enter the server IP address or DNS hostname in a search bar.

Now, set all credentials to manage the content and press “Install WordPress“.

17. How to install WordPress on Ubuntu Linux - Web UI - Step 1

After a couple of seconds, you’ll see a screen telling that WordPress has been successfully installed.

18. How to install WordPress on Ubuntu Linux - Web UI - Step 2

To move to your site’s Admin Dashboard, click “Log in” and login with the username and password you specified at the previous step.

19. How to install WordPress on Ubuntu Linux - Web UI - Dashboard

Congratulations!

The WordPress has been successfully installed!

Summary

WordPress is a free and open-source content management system that can be used to build everything from simple websites to blogs, large portals, and enterprise websites. In this article, we have described how to install WordPress on Ubuntu Linux server.

How useful was this post?

Click on a star to rate it!

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Top rated Udemy Courses to improve you career

Subscribe to our updates

Like this article?

Share on facebook
Share on Facebook
Share on twitter
Share on Twitter
Share on linkedin
Share on Linkdin
Share on pinterest
Share on Pinterest

Want to be an author of another post?

We’re looking for skilled technical authors for our blog!

Leave a comment

If you’d like to ask a question about the code or piece of configuration, feel free to use https://codeshare.io/ or a similar tool as Facebook comments are breaking code formatting.