How to create a build for quickly deploying a server with WP?

For something like this I would use bash scripting, it works great and will do anything for you.

If we assume that the server environment (Nginx, MySQL, PHP) is already set up and configured, the bash script will focus solely on downloading, installing, and configuring WordPress.

Here’s a simplified script for that purpose:

WordPress Installation Bash Script

#!/bin/bash

# Variables
DBNAME='wordpress_db'           # Database name
DBUSER='wordpress_user'         # Database user
DBPASS='your_password'          # Database password
WP_DIR='/var/www/wordpress'     # Directory to install WordPress
URL='http://example.com'        # URL of your WordPress site

# Ensure script is run as root
if [ "$(id -u)" != "0" ]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi

# Download and Extract WordPress
wget https://wordpress.org/latest.tar.gz -O /tmp/latest.tar.gz
tar -xzf /tmp/latest.tar.gz -C /tmp
mv /tmp/wordpress/* $WP_DIR/
rm /tmp/latest.tar.gz
rm -rf /tmp/wordpress

# Set Permissions
chown -R www-data:www-data $WP_DIR
find $WP_DIR -type d -exec chmod 750 {} \;
find $WP_DIR -type f -exec chmod 640 {} \;

# Create WordPress Config
cp $WP_DIR/wp-config-sample.php $WP_DIR/wp-config.php
sed -i "s/database_name_here/$DBNAME/g" $WP_DIR/wp-config.php
sed -i "s/username_here/$DBUSER/g" $WP_DIR/wp-config.php
sed -i "s/password_here/$DBPASS/g" $WP_DIR/wp-config.php

# Set WordPress Salts
SALTS=$(curl -s https://api.wordpress.org/secret-key/1.1/salt/)
printf '%s\n' "g/$put_your_unique_phrase_here/d" a "$SALTS" . w | ed -s $WP_DIR/wp-config.php

# Complete the Installation
echo "WordPress installed successfully. Please complete the installation through the web interface."

# Open the web interface to complete the installation
xdg-open $URL/wp-admin/install.php

Notes:

Modify Variables: Change DBNAME, DBUSER, DBPASS, WP_DIR, and URL according to your setup.

Running the Script: Run this script as root or with sudo privileges.
Directory Permissions: The script sets permissions for security. Adjust them if needed.

Completion: The installation is completed through the WordPress web interface.

Execution:
Save the script as install_wordpress.sh.

Make it executable: chmod +x install_wordpress.sh.

Run the script: sudo ./install_wordpress.sh.

Always test the script in a non-production environment first to ensure it works as expected with your configuration. This script is a basic guideline and might need adjustments based on your specific server setup.

tech