Install wordpress with http, then update to https
How to Install WordPress on Ubuntu 22.04 LTS Server
How to Install WordPress on Ubuntu 22.04 LTS Server – Linux Shout (how2shout.com)
1. Perform Ubuntu 22.04 update
sudo apt update && sudo apt upgrade
2. Install Apache & PHP for WordPress
sudo apt install apache2
sudo systemctl enable apache2
systemctl status apache2
http://server-ip-address
http://20.58.51.219/
# Apache2 Default Page success
# Install PHP version 8
sudo apt install -y php php-{common,mysql,xml,xmlrpc,curl,gd,imagick,cli,dev,imap,mbstring,opcache,soap,zip,intl}
php -v
3. Install MariaDB or MySQL
sudo apt install mariadb-server mariadb-client
# Enable, Start and check service status:
sudo systemctl enable --now mariadb
systemctl status mariadb
sudo mysql_secure_installation
4. Create Database for WordPress
# or sudo mysql -u root -p
sudo mysql
CREATE USER 'new_user'@'%' IDENTIFIED BY 'your_password';
CREATE DATABASE db_wordpress;
GRANT ALL PRIVILEGES ON *.* TO 'new_user'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
# Check user ok
Select * from mysql.user;
show databases;
exit;
5. Install WordPress on Ubuntu 22.04
sudo apt install wget unzip
# Download wordpress
wget https://wordpress.org/latest.zip
# Extract file:
sudo unzip latest.zip
# Move it to the webfolder
sudo mv wordpress/ /var/www/html/
# Remove download to free up sapce
sudo rm latest zip
# Change file permission
sudo chown www-data:www-data -R /var/www/html/wordpress/
sudo chmod -R 755 /var/www/html/wordpress/
6. Configure Apache on Ubuntu 22.04
# Create config file for wp
sudo nano /etc/apache2/sites-available/wordpress.conf
# Copy paste
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html/wordpress
ServerName 20.58.51.219
ServerAlias www.example.com
<Directory /var/www/html/wordpress/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# Enable virtual host
sudo a2ensite wordpress.conf
# Enable rewrite module
sudo a2enmod rewrite
# Disable the default Apache test page
sudo a2dissite 000-default.conf
# Restart the Apache webserver to apply the changes:
sudo systemctl restart apache2
http://your-server-ip-address
8. Add Database information
db_wordpress
new_user
your_password
localhost was used here as db host
Finally, click on the “Run the installation” button.
9. Create Admin user and password
10. Login to the backend

Added a theme, a category and a post
How To Create a Self-Signed SSL Certificate for Apache in Ubuntu 22.04
# Check UFW
sudo ufw status
Status: inactive
# If enabled / Must have NSG HTTP and HTTPS also
sudo ufw allow "Apache Full"
# check status
sudo ufw status?
# Step 1 — Enabling mod_ssl
sudo a2enmod ssl
sudo systemctl restart apache2
# Step 2 – Creating the TLS Certificate
# Alter days
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache-selfsigned.key -out /etc/ssl/certs/apache-selfsigned.crt
[...]
Common Name (e.g. server FQDN or YOUR name) []:20.58.51.219
# Step 3 – Configuring Apache to Use TLS
# For this tutorial we will create a new minimal configuration file. (If you already have an Apache <Virtualhost> set up and just need to add TLS to it, you will likely need to copy over the configuration lines that start with SSL, and switch the VirtualHost port from 80 to 443. We will take care of port 80 in the next step.)
sudo nano /etc/apache2/sites-available/20.58.51.219.conf
<VirtualHost *:443>
ServerName 20.58.51.219
DocumentRoot /var/www/html/wordpress
SSLEngine on
SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
</VirtualHost>
# We have the document root from HTTP install
# DocumentRoot /var/www/html/wordpress
# Next, we need to enable the configuration file with the a2ensite tool:
sudo a2ensite 20.58.51.219.conf
# Next, let’s test for configuration errors:
sudo apache2ctl configtest

sudo systemctl reload apache2
# One tab, http://20.58.51.219/
# New tab
https://20.58.51.219/

HTTPS for WordPress – Documentation
The Site health tools (Tools > Site health) will inform you that your website doesn’t use HTTPS.
Since version 5.7, WordPress can also automatically switch to HTTPS if an SSL certificate is already set up on your server.

To implement HTTPS support on WordPress, you only need to set the WordPress and Site Address URL to use https://. You can install WordPress either using HTTP or HTTPS to start, both will work, and you can switch over later.
Go to Settings > General and make sure that the WordPress Address (URL) and Site Address (URL) is https. If not, add ‘S’ after http to make https and save it :

Save it, moment of truth…….
Redirected to login, https://20.58.51.219/
Saved.

CN is public ip

Press the http post URL

Error as expected

Publish a new post?

Can we add programming user?

Edit it to be worker, success

Ok, but we can not add new post, restart server, but that can not fix it, but test boot.
Boot ok, all starting.
Na, not able to make new posts, it must be some redirect.
API also has issue

You may need to redirect your HTTP traffic to your HTTPS site. For Apache, you can do so by creating two VirtualHost entries for example:
cd /etc/apache2/sites-available/
sudo cp wordpress.conf wordpress.conf_bck
cat 20.58.51.219.conf
<VirtualHost *:443>
ServerName 20.58.51.219
DocumentRoot /var/www/html/wordpress
SSLEngine on
SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
</VirtualHost>
cat wordpress.conf
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html/wordpress
ServerName example.com
ServerAlias www.example.com
<Directory /var/www/html/wordpress/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# edit wordpress.conf to
sudo nano wordpress.conf
sudo apache2ctl configtest
Syntax OK
sudo service apache2 status
Nope
Publishing failed. The response is not a valid JSON response.
# htaccess, is hidden
/var/www/html/wordpress$ cat .htaccess
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# Back up
sudo cp .htaccess .htaccess_bck
# Edit to
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule ^(.*) https://%{20.58.51.219}/$1 [R,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# Boot server

Nope same error with adding a new post.
The fix, enable apache ssl first.
The install wordpress on the SSL url.
Or test this
From http to https
How to Install WordPress with Apache and Let’s Encrypt SSL on Ubuntu 20.04 – SnapShooter Tutorials
How To Secure Apache with Let’s Encrypt on Ubuntu 20.04 | DigitalOcean
Start
For your live WordPress site, you will have to register and get a trusted certificate from a Certificate Authority or CA. Then install the certificate on your blog.
The process is the same as what we’re doing here.
How To Install WordPress With Self-Signed SSL And Apache2 On Ubuntu 14.04 | Liberian Geek
End
Extra: