WordPress 6.0 on Ubuntu 22.04 Server with LAMP
How to install and configure WordPress on Ubuntu 22.04 LTS (your own private server) using Apache2, MariaDB (MySQL) and PHP8.1 setup.
Wordpress Logo

This article will help you install / setup WordPress on Ubuntu 22.04 (your own private server) with Apache2, PHP and MariaDB/MySQL database.

The benefit on hosting your website on your own private server is reduced cost of hosting on hosting providers, more space for your website and good control over optimizing and tuning setup as per your own needs.


WordPress is a piece of software which has become the most widely used content management system and is used for setting up websites and blogs. It is open source, licensed under the GPL, and written in PHP.

WordPress allows users to create and edit websites through a central administrative dashboard, which includes a text editor for modifying content, menus and various design elements.

WordPress provides plugins which provide additional functionality through WordPress Plugin Directory. There are over 54,000+ Plugins available in WordPress repository, which can be installed through upload or by one-click installation through the WordPress Plugin Library.

Users can write posts and readers can write comments about it, also the software had been downloaded more than 36+ million times, from the date of release.


The Four Layers of a LAMP Stack

Linux based web servers consist of four software components, they are arranged in layers which interacts with each other, make up the software stack.

Websites and Web Applications run on top of this underlying stack. The common software components that make up a traditional LAMP stack are:

  1. Linux: The operating system (OS) makes up our first layer. Linux sets the foundation for the stack model. All other layers run on top of this layer. we plan to use Ubuntu 22.04 version on Linux operating system.
  2. Apache: The second layer consists of web server software, typically Apache Web Server. This layer resides on top of the Linux layer. Web servers are responsible for translating from web browsers to their correct website.
  3. MySQL: Our third layer is where databases live. MySQL stores details that can be queried by scripting to construct a website, It usually sits on top of the Linux layer alongside Apache/layer 2. In high end configurations, MySQL can be off loaded to a separate host server.
  4. PHP: Sitting on top of them all is our fourth and final layer. The scripting layer consists of PHP and/or other similar web programming languages. Websites and Web Applications run within this layer.
Wordpress on Ubuntu 20.04 (Own Private Server) - explanation of LAMP stack setup


Linux, Apache2, PHP8.1, MariaDB Server and Client installed on Ubuntu 22.04 and working. if you dont know how to do it, follow the article

Picture showing four layers of LAMP stack.
  • SSL Certificate procured with a domain name.


To setup wordpress on Ubuntu (your own private server), follow the procedure mentioned below

Download wordpress

Download wordpress database from the link mentioned below in /tmp folder and unzip it

cd /tmp
wget https://wordpress.org/latest.zip
unzip latest.zip

Copy the directory wordpress to /var/www/html folder

sudo cp -rf wordpress /var/www/html/

Delete index.html from /var/www/html/wordpress

cd /var/www/html/wordpress
sudo \rm -rf index.html

Install PHP packages

sudo apt install php-mysql php-cgi php-cli php-gd

Restart Apache2 service

sudo service apache2 restart

Change the permissions of the wordpress folder

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

Create MariaDB username and password

Now lets create a mariadb database user and password on ubuntu server

sudo mysql -u root -p

Enter the root password at the mariadb prompt to create a database

MariaDB [(none)]> create database wordpress;
MariaDB [(none)]> show databases;
MariaDB [(none)]> create user "wordpress"@"localhost" identified by 'password';
MariaDB [(none)]> grant all privileges on wordpress.* to "wordpress"@"localhost";
MariaDB [(none)]> flush privileges; 
MariaDB [(none)]> exit;

Go to the web browser, type PublicIP/wordpress, you should be able to see wordpress welcome and select language page, click continue
it will asks for database name, username, password and database host

Database name : wordpress
Username : wordpress
Password : password
Database host : localhost (Keep as is)
Table Prefix : wp_ (Keep as is)

You will be able to get into your wordpress installation by logging in with

Site Title
username: admin

That's it, wordpress on Ubuntu is up and running.

login into admin panel by entering the following URL in a browser window


also to access live website, type the following URL in a browser window


Access your site directly from the main domain

In order to allow your site to be accessed directly from the main domain (https://mydomain.com) instead of https://mydomain.com/wordpress, follow the approaches mentioned below.

First open your Ubuntu browser, Log into WordPress admin dashboard > Settings > General > Site Address (URL) and change this to main domain name https://mydomain.com.

The problem with this approach is that you will not be able to change your permalinks to use post-names, it will not work and site-health area in dashboard shows up an error REST API error.

Another approach is to copy the file /var/www/html/wordpress/index.php file to /var/www/html folder and modify the following lines

sudo cp -rp /var/www/html/wordpress/index.php /var/www/html/
vi /var/www/html/index.php

and replace the following line

require __DIR__ . '/wp-blog-header.php';


require __DIR__ . '/wordpress/wp-blog-header.php';

save and close. now everytime when you type mydomain.com, you will be redirected to mydomain.com/wordpress, also you will be able to use permalinks with post-name as the slug.

Configure Apache Web Server

Create a new wordpress configuration file under /etc/apache2/sites-available

sudo vi /etc/apache2/sites-available/wordpress.conf

and then paste these lines

Alias /wordpress"/var/www/html/wordpress/"
<Directory /var/www/html/wordpress/>
Options +FollowSymlinks
AllowOverride All
<IfModule mod_dav.c>
Dav off
SetEnv HOME /var/www/html/wordpress
SetEnv HTTP_HOME /var/www/html/wordpress

Create Symbolic link

sudo ln -s /etc/apache2/sites-available/wordpress.conf /etc/apache2/sites-enabled/wordpress.conf

Forward All HTTP requests to HTTPS

To configure all http requests to be forwarded to https (which is more secure) open the following file

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

and add the lines mentioned below before </VirtualHost>

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Now enable apache2 rewrite module by entering the following command

sudo a2enmod rewrite

and restart the apache2 server

sudo systemctl reload apache2

WordPress on Ubuntu 22.04 (your own private server) fully up and running.

Similar Posts

  • All
  • fail2ban
  • nextcloud
  • raspberrypi
  • ubuntu
  • nas
  • synology
  • wordpress
  • ftp
  • sftp
  • ssh

Mobeen Syed on February 17, 2021

This article describes how to enable /etc/rc.local (startup) with systemd on Ubuntu 20.04 (focal fossa) linux distribution.
Picture showing four layers of LAMP stack.

Mobeen Syed on October 3, 2022

Setup Four layers of LAMP Stack Apache2, PHP8.1, MariaDB SQL database on Linux Ubuntu 22.04 distribution for hosting your own website/cloud.
Nextcloud Logo

Mobeen Syed on October 3, 2022

Setup Nextcloud on Ubuntu 20.04 using Apache2, PHP LAMP stack, SSL secure with letsencrypt and fail2ban brute force protection using fail2ban.

2 Replies to “WordPress 6.0 on Ubuntu 22.04 Server with LAMP”

Hello! I realize this is kind of off-topic however I needed to ask.
Does managing a well-established website like yours take
a massive amount work? I’m brand new to running a
blog however I do write in my diary every day.
I’d like to start a blog so I can easily share my own experience and views online.
Please let me know if you have any kind of ideas or tips for brand new aspiring bloggers.

Appreciate it!

my homepage: قیمت تور ترکیه

May I simply just say what a comfort to uncover somebody who actually understands what they are discussing on the
internet. You certainly realize how to bring a problem to light and make it important.
More people have to check this out and understand this side of your story.
I was surprised you are not more popular given that you most
certainly possess the gift.

my blog post :: buy instagram followers

Leave a Reply

Your email address will not be published. Required fields are marked *