1. Initial Server Hardening
Before installing the stack, secure the OS.
- Update the System:
sudo apt update && sudo apt upgrade -y - Create a Sudo User: Stop using
root. Create a new user and add them to the sudo group. - SSH Security: Disable password authentication in
/etc/ssh/sshd_configand use SSH keys. Change the default port from 22 to a custom high-range port. - Firewall (UFW): “`bash sudo ufw allow ‘Nginx Full’ sudo ufw allow [Your Custom SSH Port] sudo ufw enable
2. Installing NGINX and MySQL
- NGINX:
sudo apt install nginx. Once installed, NGINX will serve as your high-speed reverse proxy. - MySQL:
sudo apt install mysql-server. Immediately runsudo mysql_secure_installationto remove anonymous users and test databases. - Database Creation: Log in to MySQL and create a dedicated database and user for WordPress using
utf8mb4for full emoji and multilingual support.
3. The PHP-FPM Engine
WordPress is PHP-heavy. For a modern Ubuntu setup, install PHP 8.3 along with the necessary extensions.
- Extensions: You need
php-fpm,php-mysql,php-gd,php-mbstring,php-xml,php-curl, andphp-zip. - Configuration: Edit your
php.inito increaseupload_max_filesizeandmemory_limit(256M minimum recommended).
4. NGINX Virtual Host Configuration
Don’t use the default config. Create a specific server block for your domain in /etc/nginx/sites-available/.
- FastCGI Pass: Ensure your
location ~ \.php$block correctly points to the PHP-FPM socket (e.g.,unix:/var/run/php/php8.3-fpm.sock). - Try_Files: Set
try_files $uri $uri/ /index.php?$args;to ensure WordPress permalinks function without 404 errors.
5. SSL and Directory Permissions
- Certbot: Use Let’s Encrypt for free SSL. Run
sudo apt install python3-certbot-nginxfollowed bysudo certbot --nginx. This automatically handles the SSL handshake and redirects HTTP to HTTPS. - Ownership: Grant the
www-datauser ownership of the WordPress directory:sudo chown -R www-data:www-data /var/www/your-site - Permissions: Set directories to
755and files to644to maintain security while allowing the server to write to the/uploads/folder.