Install WordPress on a fresh VM

Overview & Details
Overview & Details
Before you begin
Clean VM
Start with a fresh Ubuntu Server LTS virtual machine with root
or sudo access and a working internet connection. Do not use a VM
that already runs another web server or control panel.
Recommended resources
At least 1 vCPU, 2 GB of RAM, and 20 GB of disk space is a
comfortable starting point for a small site. Allow more for
media, plugins, and backups.
Network
Open TCP ports 80 and 443 on the VM and on any provider or
hypervisor firewall. Point your domain’s A record at the VM
if you plan to use HTTPS.
Run with care: These commands install system packages
and change web server settings with administrative privileges. Use a
VM you control, and take a snapshot first.
Connect and update
Sign in to the VM as root and update its packages. Replace the example
IP address with your own.
ssh root@YOUR_SERVER_IP
apt update && apt upgrade -y
If the update requires a reboot, reboot first, reconnect, and then continue.
Install Apache, MariaDB, and PHP
This installs the web server, the database, and the PHP modules
WordPress commonly needs.
apt install -y apache2 mariadb-server php libapache2-mod-php php-mysql php-curl php-gd php-mbstring php-xml php-zip php-intl php-imagick curl unzip
a2enmod rewrite
systemctl restart apache2
Create the database
Create a database and a dedicated user for WordPress. Replace
YOUR_DB_PASSWORD with a strong password before running,
and keep it for Step 05.
mariadb -e "CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'YOUR_DB_PASSWORD';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;"
Before running: Replace the placeholder locally, never
publish your real password, and be aware that passwords typed into
commands may remain in shell history.
Download WordPress
Download the latest release from wordpress.org, place it in the web
root, and give Apache ownership of the files.
cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
rm -f /var/www/html/index.html
cp -a wordpress/. /var/www/html/
chown -R www-data:www-data /var/www/html
find /var/www/html -type d -exec chmod 755 {} \;
find /var/www/html -type f -exec chmod 644 {} \;
Connect WordPress to the database
Copy the sample configuration, then edit it and enter your database
details. Set DB_NAME to wordpress,
DB_USER to wpuser, and DB_PASSWORD
to the password you chose.
cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php
nano /var/www/html/wp-config.php
Replace the placeholder security keys too. WordPress provides a
generator at
api.wordpress.org/secret-key/1.1/salt.
In nano, press Ctrl+O then Enter to save, and Ctrl+X to exit.
Allow permalinks
Let WordPress use pretty URLs by allowing .htaccess
overrides for the web root.
cat > /etc/apache2/conf-available/wordpress.conf <<'EOF'
<Directory /var/www/html>
AllowOverride All
</Directory>
EOF
a2enconf wordpress
systemctl reload apache2
Finish in your browser
Open this address, choose a language, and complete the famous
five-minute install by entering your site title and creating an
administrator account:
http://YOUR_SERVER_IP/
Replace YOUR_SERVER_IP with your VM’s actual IP address.
Use a strong, unique administrator password.
Turn on HTTPS
If your domain already points to this VM, install a free Let’s Encrypt
certificate. Replace example.com with your domain.
apt install -y certbot python3-certbot-apache
certbot --apache -d example.com -d www.example.com
Keep building
Keep WordPress, themes, plugins, and the operating system updated, use
unique administrator credentials, and take regular backups of both
/var/www/html and the database.
References:
WordPress installation guide
·
WordPress requirements
·
Certbot
WP Multisite
Before you begin Working WordPress This guide assumes a working WordPress install on Apache, such as the one from…
Install Nextcloud on a fresh VM
Before you begin Docker installed This guide needs Docker Engine and the Compose plugin on an Ubuntu VM. If…
Install Docker on a fresh VM
Before you begin Clean VM Start with a fresh, 64-bit Ubuntu Server LTS virtual machine. Check Docker’s supported Ubuntu…
Download Install WordPress on a fresh VM
Use the button below to open the download destination.


