How to Install WordPress on Ubuntu 22.04

WordPress is a cross-platform content (audio, video, written) management system. It offers tens of plugins to automate and better format the content on your website. The WordPress-relevant files/data/configurations reside on the hosting server. Hosting Servers provide an automated way to install WordPress without dealing with dependencies (that too are integrated automatically). While dealing with servers, Linux is the best among other competitors.

We have picked Ubuntu 22.04 (a Linux distro) and will guide you on how you can install WordPress on Ubuntu 22.04.

Prerequisites: Update/Upgrade the Packages List

In this article, we have to frequently use the Ubuntu Default repositories to install packages. So, ensure that you have the updated index of the packages (an upgrade is recommended too):

sudo apt update;sudo apt upgrade

How to Install WordPress on Ubuntu 22.04

WordPress is set up using LAMP, i.e., Linux (Ubuntu 22.04), Apache, MySQL, and PHP. Apache is used to create a virtual host; MySQL database stores the data and PHP is the medium between the web server and the database. So, we will install/configure all these, in a sequential manner:

Step 1: Install/Setup Apache

First, install Apache on Ubuntu:

sudo apt install apache2

Check/Verify the status:

sudo systemctl status apache2

Allow all the incoming traffic through Port 80 and Port 443 (HTTP and HTTPS). To do so, allow the ‘Apache Full’ profile using the ufw utility:


sudo ufw allow 'Apache Full'

Reload the firewall to apply the changes:

sudo ufw reload

Step 2: Install/Setup MySQL Server

Install MySQL Server on your Ubuntu:

sudo apt install mysql-server

Check the status of the mysql service:

sudo systemctl status mysql

This is optional but recommended to secure the MySQL server installation:

sudo mysql_secure_installation

The secure installation prompts multiple times, where a user can:

  • Remove the Anonymous Users.
  • Disallow a remote root login.
  • Remove access to the databases.

Now, it’s time to create a MySQL database structure:

First, create a database:

CREATE DATABASE genie_wordpress;

Create a User and set the password, i.e., replace the Password with the one you want to set:

CREATE USER genie@localhost IDENTIFIED BY 'Password';

Grant the SQL queries access to the user:

GRANT ALL ON genie_wordpress.* TO genie@localhost;

It is recommended to use FLUSH PRIVILEGES right after the GRANT to make the new changes effective immediately:


Step 3: Install/Setup PHP

Now, get PHP using the below command:

sudo apt install php

Install the MySQL module for PHP as well:

sudo apt install php-mysql

Important: You might have to install the following PHP extensions (if not available/installed by default):

sudo apt install php-gd php-curl php-mbstring php-xmlrpc php-xml php-soap php-zip php-intl

Step 4: Download WordPress Files

Download the latest available tar.gz file of the WordPress:

curl -O

Extract the downloaded file and place it inside the /var/www/html/ directory (Apache by default uses this directory to serve the requested data/files).

sudo tar xf latest.tar.gz -C /var/www/html/

Apache executed by www-data user. So, change the ownership of all the files/directories inside /var/www/html recursively to the user “www-data”:

sudo chown -R www-data:www-data /var/www/html/

The extracted file name is “wordpress” and is now located inside the /var/www/html/ as shown below:

Step 5: Configure Apache as per the Data

Apache loads/unloads the files inside the /etc/apache2/sites-available/ directory. Create a new configuration file inside it and add the following details:

  • DocumentRoot: Where all the website files reside, and Apache serves the data from here (usually it is /var/www/html/). We have also extracted the WordPress folder here, /var/www/html/.
  • Directory Block (for .htaccess): This directory block points towards the document root directory and adds the “AllowOverride All” to enable/allow the .htaccess files. This might not be necessary for the installation but is a useful act to configure WordPress and enable support for WordPress plugins.
sudo nano /etc/apache2/sites-available/wp.conf

Use the a2ensite script to enable the wp site:

sudo a2ensite wp

Meanwhile, disable the default welcome page of the Apache using the a2dissite script:

sudo a2dissite 000-default

Reload the apache2 service to apply all the changes on Apache:

Step 6: Configure PHP | Add Database Details

The PHP configuration sample file is located inside the “/var/www/html/wordpress”. This PHP configuration file will be modified as per our context. First, create/make a backup of it:

sudo cp wp-config-sample.php wp-config.backup

Remove the sample keyword from the name and keep it “wp-config.php”:

sudo mv wp-config-sample.php wp-config.php

Here comes the integration of your database structure with the PHP. The sample file asks you to insert information about the Database, i.e., name, user, password, and host. You need to enter the MySQL data that you configured while setting up LAMP:


Use the WordPress Key Generator to generate your security keys to manage the sessions and cookies of WordPress. If not generated/added by the user, these keys are generated automatically. I just added these keys in between the quotes:

Step 7: Login and Set Up the WordPress

Here you go, if you have followed the above configurations, then use the following URL to get to your WordPress:


Add the relevant information and click on Install WordPress:

WordPress will be installed shortly. Click on Log In to proceed:

Now, use the credentials to log in to your WordPress dashboard:

The WordPress dashboard is just in front. It’s a fully loaded WordPress version so you will get all the features here:

Upon visiting, here’s the interface that appeared:

That’s how you can install WordPress on Ubuntu 22.04.

Bottom Line

Installing WordPress on a local system requires LAMP. You have to get one Linux distro (Ubuntu in this case), Apache server, MySQL Server, and PHP integration to install WordPress on your site.

First, install all these packages, then configure them one by one and lastly integrate all these to get WordPress on your locally hosted website. This post has listed the sequential process to install WordPress on Ubuntu 22.04.

Print Friendly, PDF & Email