Contents
Introduction
WordPress is the world’s most popular content management system (CMS), powering over 40% of all websites
source. Pairing it with the performance-focused
Nginx web server and PHP-FPM on Ubuntu 22.04 ensures a fast, scalable, and secure environment.
This guide will walk you through every step, from server preparation to final WordPress configuration.
Prerequisites
- Ubuntu 22.04 LTS server (bare-metal or VPS) with sudo privileges.
- A registered domain name (e.g., example.com) pointed via an A record to your server’s public IP.
- Basic command-line familiarity and understanding of Linux directory structure.
- Firewall (ufw) access to open ports 80 and 443.
Overview of Components
Component | Version on Ubuntu 22.04 | Purpose |
---|---|---|
Nginx | 1.18.x | High-performance HTTP server/reverse proxy. |
PHP-FPM | 8.1 | Process manager for PHP enabling better concurrency. |
MariaDB | 10.6 | Relational database for storing WordPress data. |
WordPress | 6.x | Open-source CMS. |
1. System Update Base Packages
Always begin by synchronizing your package index and upgrading existing packages:
sudo apt -y upgrade
Then install essential tools:
2. Installing Nginx
Ubuntu’s repositories include a stable Nginx build. Install and enable it:
sudo systemctl enable –now nginx
Verify by pointing your browser to http://your_server_ip/. You should see the default Nginx welcome page.
3. Secure MariaDB (or MySQL)
Install MariaDB and run the built-in security script:
sudo mysql_secure_installation
- Set a strong root password.
- Remove anonymous users.
- Disallow remote root login.
- Remove test database.
- Reload privilege tables.
More details: MariaDB Secure Installation
4. Creating WordPress Database User
Inside the MariaDB shell, run:
CREATE USER wpuser@localhost IDENTIFIED BY strong_password
GRANT ALL PRIVILEGES ON wordpress. TO wpuser@localhost
FLUSH PRIVILEGES
EXIT
5. Installing PHP PHP-FPM
Add the Ondřej Surý PPA for up-to-date PHP if needed, or install directly:
Confirm PHP-FPM is running:
PHP-FPM listens on /run/php/php8.1-fpm.sock by default and integrates seamlessly with Nginx.
6. Configuring Nginx Server Block
Create a new server block file:
Populate with:
listen 80
listen [::]:80
server_name example.com www.example.com
root /var/www/wordpress
index index.php index.html index.htm
access_log /var/log/nginx/wordpress.access.log
error_log /var/log/nginx/wordpress.error.log
location / {
try_files uri uri/ /index.phpargs
}
location ~ .php {
include snippets/fastcgi-php.conf
fastcgi_pass unix:/run/php/php8.1-fpm.sock
}
location ~ /.ht {
deny all
}
}
Enable and test:
sudo nginx -t
sudo systemctl reload nginx
7. Downloading Configuring WordPress
Fetch the latest WordPress package:
curl -O https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
Move files, set permissions, and create the configuration:
sudo cp -a /tmp/wordpress/. /var/www/wordpress
sudo chown -R www-data:www-data /var/www/wordpress
sudo find /var/www/wordpress/ -type d -exec chmod 750 {}
sudo find /var/www/wordpress/ -type f -exec chmod 640 {}
Configure wp-config.php:
sudo cp wp-config-sample.php wp-config.php
sudo nano wp-config.php
- Set
DB_NAME
,DB_USER
,DB_PASSWORD
. - Generate unique Authentication Keys and Salts from
WordPress.org.
8. Finalizing Installation via Web Interface
- Open your browser at http://example.com.
- Select language, click “Continue.”
- Enter Site Title, Admin Username, Password, Email.
- Complete installation log in to /wp-admin.
9. Enabling HTTPS (Optional but Recommended)
Secure your site with a free TLS certificate from Let’s Encrypt:
sudo certbot –nginx -d example.com -d www.example.com
Certbot will automatically configure HTTPS and set up renewal.
Learn more: Let’s Encrypt Docs
10. Performance Security Recommendations
- Enable caching with plugins like WP Super Cache or W3 Total Cache.
- Use Nginx caching (fastcgi_cache) and Gzip compression in your server block.
- Keep all software updated:
sudo apt update sudo apt upgrade
. - Limit PHP memory and execution time in
/etc/php/8.1/fpm/php.ini
. - Install a Web Application Firewall (WAF) such as ModSecurity.
Conclusion
You now have a robust, high-performance WordPress setup running on Nginx and PHP-FPM under Ubuntu 22.04.
This environment is scalable, secure, and optimized for modern web traffic. For further tuning or troubleshooting, consult:
|
Acepto donaciones de BAT's mediante el navegador Brave 🙂 |