Introduction
WordPress powers over 40% of websites worldwide, making it the most popular content management system (CMS). Deploying WordPress on an Ubuntu VPS using NGINX, PHP-FPM, and MariaDB ensures optimal performance, scalability, and security. This guide walks you through the entire process, from server preparation to WordPress installation, providing a robust stack for high-traffic websites.
Prerequisites
Before you begin, ensure you have:
- An Ubuntu 22.04 VPS
- Root or sudo privileges
- A registered domain name pointing to your VPS IP
Step 1: Update Your System
Start by updating your system packages to ensure the latest security patches are installed:
sudo apt update && sudo apt upgrade -y
Step 2: Install NGINX
Install NGINX as the web server to handle HTTP requests efficiently:
sudo apt install nginx -y
Start and enable NGINX to run at boot:
sudo systemctl start nginx
sudo systemctl enable nginx
Verify NGINX status:
sudo systemctl status nginx
Step 3: Install MariaDB
MariaDB will serve as the database for your WordPress site:
sudo apt install mariadb-server mariadb-client -y
Secure the MariaDB installation:
sudo mysql_secure_installation
Follow the prompts to set a root password, remove anonymous users, and secure your database.
Step 4: Create a Database for WordPress
Log in to the MariaDB shell:
sudo mysql -u root -p
Create a database and user for WordPress:
CREATE DATABASE wordpress;
CREATE USER ‘wpuser’@’localhost’ IDENTIFIED BY ‘strong_password’;
GRANT ALL PRIVILEGES ON wordpress.* TO ‘wpuser’@’localhost’;
FLUSH PRIVILEGES;
EXIT;
Step 5: Install PHP and PHP-FPM
Install PHP-FPM and necessary PHP modules for WordPress:
sudo apt install php-fpm php-mysql php-cli php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip -y
Verify PHP installation:
php -v
Step 6: Configure NGINX for WordPress
Create a new server block configuration:
sudo nano /etc/nginx/sites-available/wordpress
Add the following configuration:
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/wordpress;
index index.php index.html index.htm;location / {
try_files $uri $uri/ /index.php?$args;
}location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}location ~ /\.ht {
deny all;
}
}
Enable the configuration:
sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
Test NGINX configuration for syntax errors:
sudo nginx -t
Reload NGINX to apply changes:
sudo systemctl reload nginx
Step 7: Download and Install WordPress
Navigate to the web root directory:
cd /var/www/
Download WordPress:
sudo wget https://wordpress.org/latest.tar.gz
Extract the archive:
sudo tar -xvzf latest.tar.gz
Set proper permissions:
sudo chown -R www-data:www-data /var/www/wordpress
sudo chmod -R 755 /var/www/wordpress
Step 8: Configure WordPress
Copy the sample configuration file:
sudo cp /var/www/wordpress/wp-config-sample.php /var/www/wordpress/wp-config.php
Edit the configuration file:
sudo nano /var/www/wordpress/wp-config.php
Update the database settings:
define(‘DB_NAME’, ‘wordpress’);
define(‘DB_USER’, ‘wpuser’);
define(‘DB_PASSWORD’, ‘strong_password’);
define(‘DB_HOST’, ‘localhost’);
Step 9: Secure Your WordPress Site with SSL (Optional)
Install Certbot for SSL:
sudo apt install certbot python3-certbot-nginx -y
Obtain and configure SSL:
sudo certbot –nginx -d yourdomain.com -d www.yourdomain.com
Step 10: Finalize WordPress Installation
Open your browser and navigate to:
http://yourdomain.com
Complete the installation process by following the on-screen instructions:
- Set the site title
- Create an admin username and password
- Choose your preferred language
Conclusion
Congratulations! You’ve successfully deployed a WordPress site on your Ubuntu VPS using NGINX, PHP-FPM, and MariaDB. This stack provides excellent performance, scalability, and security for your website. Don’t forget to keep your server and WordPress installation updated regularly to maintain security and performance.