How to Install WordPress on Ubuntu 22.04 – Step-by-Step Guide

If you are looking for a reliable and secure platform to host your website, WordPress is a popular choice. WordPress is an open-source content management system (CMS) that allows users to create and manage their websites with ease.

In this article, we will provide a detailed guide on how to install WordPress on Ubuntu 22.04. We will cover all the necessary steps to install and configure WordPress on your Ubuntu server.


Before we start the installation process, make sure that you have the following prerequisites:

  • A server running Ubuntu 22.04.
  • An SSH client to connect to your server.
  • A root user or a user with sudo privileges.
  • A domain name pointing to your server’s IP address.

Installing LAMP stack on Ubuntu 22.04

The first step to installing WordPress on Ubuntu 22.04 is to install the LAMP stack. LAMP stands for Linux, Apache, MySQL, and PHP. These are the essential components required to run WordPress.

To install LAMP, open the terminal and run the following command:

sudo apt-get update sudo apt-get install apache2 mysql-server php libapache2-mod-php php-mysql

This command will install Apache web server, MySQL database server, and PHP on your server.

Creating a MySQL database for WordPress

Once you have installed the LAMP stack, the next step is to create a MySQL database for WordPress. To do this, run the following command:

Also Read:   Best WordPress Plugins to Speed Up Your Website and Improve Loading Times

sudo mysql -u root

This will open the MySQL console. Type the following command to create a new database for WordPress:

CREATE DATABASE wordpress_db;

Create a new user and grant privileges to the newly created database:

CREATE USER ‘wpuser’@’localhost’ IDENTIFIED BY ‘password’; GRANT ALL PRIVILEGES ON wordpress_db.* TO ‘wpuser’@’localhost’; FLUSH PRIVILEGES; exit

Make sure to replace ‘wpuser’ and ‘password’ with your desired username and password.

Downloading and Installing WordPress

The next step is to download and install WordPress. You can download the latest version of WordPress from the official website. Alternatively, you can use the following command to download WordPress:

cd /var/www/html/ sudo wget sudo tar -xzvf latest.tar.gz sudo chown -R www-data:www-data /var/www/html/wordpress/ sudo chmod -R 755 /var/www/html/wordpress/

Configuring WordPress

After installing WordPress, you need to configure it. To do this, navigate to the WordPress directory:

cd /var/www/html/wordpress/

Copy the sample configuration file and rename it:

cp wp-config-sample.php wp-config.php

Open the wp-config.php file using a text editor and modify the following lines:

define(‘DB_NAME’, ‘wordpress_db’); define(‘DB_USER’, ‘wpuser’); define(‘DB_PASSWORD’, ‘password’); define(‘DB_HOST’, ‘localhost’);

Save the file and exit the text editor.

Securing your WordPress installation

Now that you have installed and configured WordPress, it is essential to secure your installation. You can start by securing your MySQL database by running the following command:

sudo mysql_secure_installation

Follow the prompts to secure your MySQL installation. This will prompt you to set a password for the MySQL root user, remove anonymous users, disable remote root login, and remove the test database.

Additionally, you can install a security plugin for WordPress, such as Wordfence Security or iThemes Security. These plugins offer features such as malware scanning, firewall protection, and login protection. Make sure to keep your plugins up to date to ensure the latest security patches are applied.

Also Read:   Finally add a New Wordpress theme


Installing WordPress on Ubuntu 22.04 is a straightforward process that can be accomplished in a few simple steps. By following the steps outlined in this article, you can have your WordPress website up and running in no time. Remember to keep your installation secure by following best practices, such as using strong passwords and keeping your software up to date.


Q1. Can I install WordPress on Ubuntu 20.04?

A1. Yes, the steps to install WordPress on Ubuntu 20.04 are the same as the steps outlined in this article.

Q2. What if I already have Apache, MySQL, and PHP installed?

A2. If you already have Apache, MySQL, and PHP installed, you can skip the LAMP installation step and proceed to create a MySQL database and install WordPress.

Q3. How do I access my WordPress site after installation?

A3. You can access your WordPress site by navigating to your domain name in a web browser.

Q4. Can I install WordPress on a shared hosting account?

A4. Yes, most shared hosting providers offer an easy one-click installation of WordPress.

Q5. Is it necessary to install a security plugin for WordPress?

A5. While it is not necessary to install a security plugin, it is highly recommended to ensure the security of your installation.

About Me