Install WordPress in Ubuntu 22.04

WordPress is a content management system (CMS). It was first released on May 27, 2003. Initially, it was mainly used to publishing blogs. But, with time it began to utilised for various other web content types. In this article, we would focus on how to install WordPress in Ubuntu 22.04.

At the time of writing, version 5.9.0 is its latest stable release.

There are two methods to install WordPress in Ubuntu 22.04. Either it can be installed through standard Ubuntu repository or we can do it through the .tar.gz package file available on its official website. This article focuses on the installation done through .tar.gz package file available on its official website. We will cover the standard repository installation in some other article.

Note: Following operations may require you to have superuser privileges. In case you don’t have one, we advise you to contact your System Administrator.

Install WordPress in Ubuntu 22.04

First, visit the official website of WordPress. A simple google search – “WordPress Download” would get you the desired result. On the Downloads web page, Just below Download WordPress x.x button, we would see the link to download .tar.gz file. So, click on that link Download .tar.gz

The downloaded file is – wordpress-x.x.tar.gz

where, x.x is the latest stable version of WordPress available.

Now, extract the package file using tar command-line utility.

tar -xvf wordpress-x.x.tar.gz

It would create wordpress/ in current directory.

Next, we need to get the setup and configure necessary files through –

Installing lamp-server,
Create database user and grant necessary privileges,
Edit configuration files, and
Install and setup WordPress.

We would get the above steps done in order – starting with installing lamp-server.

Install LAMP Server in Ubuntu 22.04

LAMP is basically – Linux, Apache, MySQL and PHP. Relevant packages can be installed through standard Ubuntu repository. Therefore, issue the following in terminal –

sudo apt install apache2
sudo apt install php8.1
sudo apt install php8.1-mysql
sudo apt install mysql-server

Also, we advise you to install following packages as well. They would be useful later.

sudo apt install php8.1-curl php8.1-mbstring php8.1-xml
Create database user and grant necessary privileges

To setup MySQL for WordPress

sudo mysql_secure_installation

it asks whether we want to setup Password Validation Component? Press y confirm

Thereafter, it asks for Password Validation Policy – we chose Strong.

Next, enter the password twice and Press y to continue with the password. We chose y for all other prompts. You may chose the option y|N as per your requirements.

Create a database for WordPress

sudo mysql -u root -p

Enter the password used earlier. Following commands would create a database – wp_database, user – wp_user, and password – Pqwertyd6*. We have also granted all privileges to the user on WordPress database.

CREATE DATABASE wp_database;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'Pqwertyd6*';
GRANT ALL PRIVILEGES ON wp_database.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
quit
Edit configuration files

Our purpose is to help you setup the most basic configuration (i.e. hosting just one website on the server). Therefore, edit the config file – 000-default.conf

sudo nano /etc/apache2/sites-available/000-default.conf

and append the file with following entries –

<Directory /var/www/html/>
AllowOverride All
</Directory>

Next, enable rewrite module.

sudo a2enmod rewrite

To check if we have an issue –

sudo apache2ctl configtest

It should return with Syntax OK.

Then, restart apache2.service –

sudo systemctl restart apache2.service
Install and setup WordPress

Next, head to the directory where we have wordpress/

cd /path/to/wordpress-directory/

Copy wp-config-sample.php as wp-config.php

cp wordpress/wp-config-sample.php wordpress/wp-config.php

Now, copy the entire wordpress/ directory to /var/www/html/

sudo cp -a wordpress/. /var/www/html/

Also, change the ownership of /var/www/html/ to www-data using chown command-line utility.

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

Finally, edit the wp-config.php file –

sudo nano /var/www/html/wp-config.php

and, edit the following entries – Create database user and grant necessary privileges

define( 'DB_NAME', 'wp_database' );
define( 'DB_USER', 'wp_user' );
define( 'DB_PASSWORD', 'Pqwertyd6*' );

If index.html exists in /var/www/html/ then, remove it.

sudo rm /var/www/html/index.html

Restart Apache2

sudo systemctl restart apache2.service

Lastly, open a web browser and type localhost in address bar.

This should present you a web page wherein you are asked to provide Site title, Username, Password, E-mail & Search engine visibility. After providing the details, click on button Install WordPress. This is it.

In conclusion, we have discuss how to install WordPress in Ubuntu 22.04 release.

Additional Info –

Issue 1. We have already discussed it above and if you have been following us all through. You have it installed already.

We got an error – Your PHP installation appears to be missing the MySQL extension which is required by WordPress. This happened when we tried to open localhost for the first time. In our case we forgot to install the package – php8.1-mysql

sudo apt install php8.1-mysql

Issue 2. We also got an error – An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration… This happened while adding new themes then you need to append /var/www/html/wp-config.php file with the following –

define( ‘FS_Method’, ‘direct’ );