How to install WordPress on Ubuntu OS Server

This article is explaining how to install WordPress on Ubuntu OS without visual help from Cpanel or similar tools allowing one-click installs. With Ubuntu server access only via terminal, we need to use few Linux commands to make this happen.


WordPress Version: 5.4.2
OS Version: Ubuntu Os 18.04.3 (LTS) x64
MariaDB Version: 10.1.44

We’ll touch base with every step and every command so you can always get back to anything causing you trouble in the process. For the very start, let’s list out the bare minimum of access we should have in order to access the Linux server:

  1. An IP address (or hostname/domain)
  2. Username
  3. Password or ssh key

To make this easier we’ll breakdown the process into following subheadings: login to the server, prepare pre-installation requirements, download and install WordPress, and configure WordPress. Here we go!

Login to the server

With the above login details, we can access the Ubuntu server with the following command if we have a username (or domain), IP address, and password:

ssh username@ip-address(or domain)



If, however, instead of the password we have ssh key the login should look like this:

ssh username@ip-address(or domain)


ssh [email protected] -i /path/to/the/ssh-key


ssh [email protected] -i /path/to/the/ssh-key

Pre-installation requirement

When logged in to the server, we need to make sure that the operating system is up to date, PHP is installed, the database server is installed and all required services up and running.

Update operating system:

bluegrid-edu:~# apt-get update

Install Apache Webserver

bluegrid-edu:~# apt-get install apache2

Enable .htaccess override:

Open /etc/apache2/apache2.conf and change AllowOverride None to AllowOverride All:

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted

Create .htaccess file in the document root directory (/var/www/html/) and add the following line in it:

DirectoryIndex index.php

Install “upzip” using the following command:

bluegrid-edu:~# apt-get install unzip

Install PHP and apache PHP library:

Execute the following command to install PHP and necessary PHP library for apache:

bluegrid-edu:~# apt install php libapache2-mod-php

Install MySQL extension for PHP:

bluegrid-edu:~# apt-get install php-mysql

Restart apache2:

bluegrid-edu:~# systemctl restart apache2

Install Mariadb database Server:

bluegrid-edu:~# apt-get install mariadb-server

Create a database and database user:

  • Login to MariaDB database server:
bluegrid-edu:~# mysql
  • Create a database:
MariaDB [(none)]> create database wpdatabase;
  • Create a database user:
MariaDB [(none)]> create user [email protected] identified by 'wppassword';
  • Grant privileges to this user on the newly created database:
MariaDB [(none)]> grant all on wpdatabase.* to [email protected];
  • Reload privileges:
MariaDB [(none)]> grant all on wpdatabase.* to [email protected];

Download the latest WordPress installation:

Use the URL in the curl command to download the latest WordPress installation:

bluegrid-edu:~# curl -o /var/www/html/
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 12.6M  100 12.6M    0     0  9369k      0  0:00:01  0:00:01 --:--:-- 9369k

Change location to /var/www/html/ using the following command:

bluegrid-edu:~# cd /var/www/html/

Unpack the file using the following command:

bluegrid-edu:/var/www/html# unzip

Now the WordPress files are placed in the /var/www/html/wordpress/ directory and we need them moved out of the wordpress directory using the following command:

bluegrid-edu:/var/www/html# mv -f wordpress/* ./

Configure WordPress

Now we should be able to open the domain or the IP address of the server in the browser and the following screen should appear. In our case, we used the following domain and below is the screen from it:

WordPress on Ubuntu | start screen
WordPress installation start screen

This looks good! Let’s continue. Hitting the “Let’s go!” button we open next form where the WordPress database details are asked:

WordPress on Ubuntu | Database details
WordPress installation database details

Note: If you happen to get an exception like this:

WordPress on Ubuntu | wp-config.php exception
WordPress installation | wp-config.php write permissions exception

There are two ways to fix this:

  • You can manually create the wp-config.php file using the following command and paste copied content WordPress offered in above screen:
bluegrid-edu:/var/www/html# nano wp-config.php

When the wp-config.php is saved we can proceed with installation by hitting the “Run the installation” button.

Or you can change the ownership on the document root directory in two steps:

Step #1: Find out apache user it runs as:

bluegrid-edu:/var/www/html# ps aux | egrep '(apache|httpd)'

Step #2: Apply new changes on the document root directory:

bluegrid-edu:/var/www/html# chown -R www-data:www-data /var/www/html/

When permissions are changed we can reload the current page and the following will appear:

WordPress on Ubuntu | Run the installation
WordPress installation | Run the installation

We can proceed now by hitting the “Run the installation”.

The installation will stop on the following screen – Website details:

WordPress on Ubuntu | Website details
WordPress on Ubuntu | Website details

When “Install WordPress” is pressed WordPress will install and login form will pop up:

WordPress on Ubuntu | Website installed
WordPress on Ubuntu | Website installed
WordPress on Ubuntu | Website Login
WordPress on Ubuntu | Website Login

We are in! WordPress is installed and we are in the admin area. We can begin administering WordPress from this point.

WordPress on Ubuntu | WordPress Dashboard
WordPress on Ubuntu | WordPress Dashboard
Share this post

Share this link via

Or copy link