Recently I shared a practical guide to configuring Nginx with WordPress on Debian. This time I needed a new test environment and decided to try Alpine Linux, one of the lightest and fastest distributions available for a VPS.
That lightness comes at a price: almost nothing comes pre-configured out of the box. And WordPress isn’t particularly forgiving of half-baked setups. This guide shows you step-by-step how to set up a complete Nginx + PHP-FPM + MariaDB + WordPress stack, with the real-world optimizations I usually use in production environments.
1. Initial System Preparation
First things first, update the system as always:
apk update && apk upgrade
Then install the basic tools we’ll need:
apk add nano curl wget unzip
2. Installing the Stack
Installing Nginx, PHP-FPM, and MariaDB
With a single command, we install the entire core stack:
apk add nginx mariadb mariadb-client \
php83 php83-fpm php83-mysqli php83-json php83-openssl \
php83-curl php83-zlib php83-xml php83-phar php83-intl \
php83-dom php83-xmlreader php83-xmlwriter php83-ctype \
php83-session php83-mbstring php83-gd
Important: Alpine does not install PHP extensions automatically. If any are missing, WordPress might fail silently or show confusing errors. Install all the ones listed above.
Critical Step: Remove Nginx’s Default Configuration
Alpine includes a default configuration file that breaks WordPress. If you don’t remove it, you will run into 404 or 500 errors that are very tricky to diagnose.
rm /etc/nginx/http.d/default.conf
Do not skip this step. It will save you a lot of headaches.
3. Configuring MariaDB
Initialize the database and start the service:
mysql_install_db --user=mysql --datadir=/var/lib/mysql
rc-service mariadb start
rc-update add mariadb
Now run the security installation script to remove insecure defaults:
mysql_secure_installation
Once inside MySQL, create the database and user for WordPress:
CREATE DATABASE wordpress;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'password_seguro';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
4. Configuring PHP-FPM
Edit the PHP-FPM pool configuration file:
nano /etc/php83/php-fpm.d/www.conf
Find and modify these lines:
user = nginx
group = nginx
listen = 127.0.0.1:9000
If you leave the user as
nobody(the default value), you’ll run into permission issues when WordPress tries to write files.
Start the service and enable it at boot:
rc-service php-fpm83 start
rc-update add php-fpm83
5. Configuring Nginx for WordPress
Create the site configuration file:
nano /etc/nginx/http.d/wordpress.conf
And use this base configuration:
server {
listen 80;
server_name tu-dominio.com;
root /var/www/wordpress;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires max;
log_not_found off;
}
}
Important note: On Alpine, it is recommended to use
fastcgi.confinstead offastcgi_params. This avoids the classic “File not found” error when processing PHP files.
6. Downloading and Installing WordPress
Create the directory and download the latest version:
mkdir -p /var/www/wordpress
cd /var/www
wget https://wordpress.org/latest.zip
unzip latest.zip
7. Permissions (A Critical Step in Alpine)
Assign the correct permissions so Nginx can read and write without issues:
chown -R nginx:nginx /var/www/wordpress
chmod -R 755 /var/www
Remember that all parent folders in the path need execute permission (
+x). If missing on any directory, WordPress won’t be able to access its own files.
8. Starting Nginx and Finishing Installation
Start Nginx and add it to system startup:
rc-service nginx start
rc-update add nginx
Now you can open your browser and go to:
http://TU_IP
You should see the WordPress installation wizard.
9. Production Optimizations
FastCGI Cache
FastCGI caching is one of the most effective improvements for reducing server load. First, add this outside the server block (in nginx.conf or in your site configuration file):
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=WORDPRESS:100m inactive=60m;
Then, inside the server block, add the logic to bypass caching for requests that shouldn’t be cached:
set $no_cache 0;
if ($request_method = POST) {
set $no_cache 1;
}
if ($http_cookie ~* "wordpress_logged_in") {
set $no_cache 1;
}
location ~ \.php$ {
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_cache WORDPRESS;
fastcgi_cache_bypass $no_cache;
fastcgi_no_cache $no_cache;
}
Gzip
Enable compression to reduce response sizes by up to 80%:
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
gzip_min_length 256;
10. Cloudflare Fix for Flexible SSL
If you’re using Cloudflare in Flexible SSL mode, add this code at the very beginning of wp-config.php to avoid redirect loops:
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])
&& $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$_SERVER['HTTPS'] = 'on';
}
Common Issues and Solutions
403 Forbidden Error
Almost always caused by permissions. Quick fix:
chown -R nginx:nginx /var/www/wordpress
“File not found” Error
Means FastCGI is misconfigured. Ensure you’re using include fastcgi.conf; inside the PHP block.
WordPress Won’t Upload Images
Verify that php83-gd and php83-mbstring are installed.
Database Connection Error
Confirm that php83-mysqli is installed and the credentials in wp-config.php match exactly what you created in MariaDB.
Pre-Launch Checklist
- You removed
/etc/nginx/http.d/default.conf - You installed all required PHP extensions
- You changed the PHP-FPM user to
nginx - Permissions on
/var/www/wordpressare correct - Nginx points to
/var/www/wordpress - You used
fastcgi.confin the PHP configuration - FastCGI cache is enabled (recommended)
- Gzip is enabled
Ready to Go
Alpine Linux isn’t “plug and play.” It’s more like building a server from scratch, piece by piece. If something is misconfigured, it usually fails without giving you many clues.
But when done right, the result is well worth it: an extremely lightweight, fast, and stable stack that uses very few resources on your VPS.
In the end, you get a WordPress instance that responds swiftly without wasting RAM. Exactly what you want when aiming for an efficient environment.
Do you use Alpine for WordPress? What extra tricks or optimizations have you discovered? Let me know in the comments.