Getting Started with WordPress WP-CLI and Nginx on Ubuntu 22.04
Getting Started with WordPress WP-CLI and Nginx on Ubuntu 22.04
Author: Łukasz Bodziony
Email: lukasz@bodziony.net.pl
DevOps Services: bodziony.net.pl
Published: June 2025
Introduction
WP-CLI is a powerful command-line tool that lets you manage your WordPress installation without opening a browser. In this tutorial, Łukasz Bodziony will show you how to quickly install Nginx, PHP, and WP-CLI, then deploy a WordPress site on Ubuntu 22.04—all via the terminal.
Prerequisites
- Ubuntu 22.04 LTS server with sudo/root access
- Basic familiarity with the Linux command line
- A domain name pointing to your server’s IP
Step 1: Update Your System
sudo apt update && sudo apt upgrade -y
Step 2: Install Nginx, PHP & Extensions
sudo apt install -y nginx php-fpm php-mysql php-xml php-curl php-gd php-mbstring
sudo systemctl enable --now nginx php7.4-fpm
Step 3: Install WP-CLI
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp --info
Step 4: Create Your WordPress Site
Create a directory for your site and download WordPress:
sudo mkdir -p /var/www/example.com
cd /var/www/example.com
sudo wp core download
Create wp-config.php
and set database credentials:
sudo wp config create \
--dbname=wordpress \
--dbuser=wpuser \
--dbpass='StrongDBPass123' \
--dbhost=localhost \
--dbprefix=wp_
Install WordPress:
sudo wp core install \
--url="https://example.com" \
--title="My WP Site" \
--admin_user="admin" \
--admin_password="StrongAdminPass!" \
--admin_email="admin@example.com"
Ensure proper permissions:
sudo chown -R www-data:www-data /var/www/example.com
sudo find /var/www/example.com -type d -exec chmod 755 {} \;
sudo find /var/www/example.com -type f -exec chmod 644 {} \;
Step 5: Configure Nginx Server Block
sudo tee /etc/nginx/sites-available/example.com << 'EOF'
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example.com;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
EOF
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
Step 6: (Optional) Enable HTTPS with Let’s Encrypt
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com
Conclusion
Congratulations! You’ve just bootstrapped a fully functional WordPress site using WP-CLI on Nginx under Ubuntu 22.04. Managing updates, plugins, and themes can now all be done from your terminal.
🚀 Host your next WordPress project on a rock-solid Linux VPS: netcloud24.com/servers/vps-linux/
Comments
Post a Comment