# Step 0 have a vm with a public ip or private, be on vpn or not, you need an ip you can access.
20.117.154.123 (demo ip), replace all instances with the ip you are using.
This VM was made with Ansible.
# Step 1
sudo apt update -y
sudo apt upgrade -y
# Allow 80,443 NSG and check ufw
sudo ufw status
sudo apt install apache2 -y
sudo a2enmod ssl
sudo systemctl restart apache2
sudo service apache2 status
# visit
http://20.117.154.123/ = Apache2 Default Page
# Step 2 Creating a Self-Signed SSL Certificate
sudo openssl req -x509 -nodes -days 3650 -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.117.154.123
sudo nano /etc/apache2/sites-available/20.117.154.123.conf
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/test
ServerName 20.117.154.123
ServerAlias www.example.com
<Directory /var/www/test/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:443>
ServerName 20.117.154.123
DocumentRoot /var/www/test
SSLEngine on
SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
</VirtualHost>
sudo mkdir /var/www/test
sudo nano /var/www/test/index.html
<h1>HTTPS it worked!</h1>
sudo a2ensite 20.117.154.123.conf
sudo apache2ctl configtest
# Syntax OK
sudo systemctl reload apache2
sudo service apache2 status
# This is what we have now
# /etc/apache2/sites-enabled$ ls
000-default.conf 20.117.154.123.conf
# visit, should result in same
http://20.117.154.123/ = HTTPS it worked!
https://20.117.154.123/ = HTTPS it worked!
# View cert
# Common Name 20.117.154.123
# Validity, Not After, Fri, 07 Oct 2033 17:52:30 GMT
# Step 3 install php and mariadb
sudo apt install -y php php-{common,mysql,xml,xmlrpc,curl,gd,imagick,cli,dev,imap,mbstring,opcache,soap,zip,intl}
php -v
sudo apt install mariadb-server mariadb-client -y
sudo systemctl enable --now mariadb
sudo mysql_secure_installation
enter, n, n, y, y, y, y
sudo mysql
CREATE USER 'username'@'%' IDENTIFIED BY 'password';
CREATE DATABASE db_wordpress;
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Select * from mysql.user;
show databases;
exit;
# Step 4 install wordpress
sudo apt install wget unzip -y
wget https://wordpress.org/latest.zip
sudo unzip latest.zip
sudo mv wordpress/ /var/www/html/
sudo chown www-data:www-data -R /var/www/html/wordpress/
sudo chmod -R 755 /var/www/html/wordpress/
# backup 20.117.154.123.conf
cd /etc/apache2/sites-available/
sudo cp 20.117.154.123.conf 20.117.154.123.conf_bck
# Now wordpress, add ip and wordpress folder
sudo nano /etc/apache2/sites-available/wordpress.conf
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html/wordpress
ServerName 20.117.154.123
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>
<VirtualHost *:443>
ServerName 20.117.154.123
DocumentRoot /var/www/html/wordpress
<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
SSLEngine on
SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
</VirtualHost>
sudo a2ensite wordpress.conf
sudo a2dissite 20.117.154.123.conf
sudo a2enmod rewrite
sudo apache2ctl configtest
# Syntax OK
sudo systemctl restart apache2
sudo systemctl enable apache2
sudo service apache2 status
# visit, should result in same
http://20.117.154.123/ = http://20.117.154.123/wp-admin/setup-config.php
https://20.117.154.123/ = https://20.117.154.123/wp-admin/setup-config.php
# Setup
english
db_wordpress
username
password
Run the installation
Welcome
test123 (site name)
user-for-wp
password-for-user
some@gmail.com
Login and view default settings
Check site health
The disk space should go away soon.
Could not determine available disk space for updates. | WordPress.org
Create some posts and view API
Enable this first permalinks->Post name and save it
Posts
Browse, https://20.117.154.123/wp-json/wp/v2/posts
Check site health again
Install theme twenty 16, activate it.
Make two pages Page1 and Post, sett it to home, Settings->Reading
Install and active IknowledgeBase theme, activate and publish it.
Go to pages and create home page with Home page template.
Update settings to Home
Update wp theme to Home in customize. Homepage Settings or verify it
Apache log
# pwd
/var/log/apache2
Test Python auto job.
Add a new user pythonworker as admin (maybe editor is enough) with a password
Now generate token
Now generate a post
import requests
import base64
import json
import logging
import requests
import json
def make_post_and_send():
data = {
"title": "Title for Post 2",
"content": "This is the content of my new post",
"status": "publish" # Use "draft" to save the post as a draft
}
try:
# Send the HTTP request
response = requests.post("https://20.117.154.123/wp-json/wp/v2/posts", auth=("pythonworker", "v8## #### #### #### #### ###"), json=data, verify=False)
# Check the response
if response.status_code == 201:
print("Post created successfully")
else:
print("Failed to create post: " + response.text)
except Exception as ex:
logging.error(ex)
make_post_and_send()
Now verify the new posts(we ran i 2 times)
Reboot server
Check that all is in the same state, publish a new post with Python.
View site health again
Then delete test server.
Links used
How to Install WordPress on Ubuntu 22.04 LTS Server – Linux Shout (how2shout.com)
How To Install WordPress With Self-Signed SSL And Apache2 On Ubuntu 14.04 | Liberian Geek
When you get a domain or alias-> Or decide what domain to use:
Solution to WordPress Showing IP Address Instead of Domain
Solution to WordPress Showing IP Address Instead of Domain – ServerPilot
How to generate CSR using OpenSSL with SAN