This guide walks you through installing WordPress on Ubuntu 20.04 LTS with Nginx as the web server. You’ll end up with a fully functional WordPress site served over HTTP, ready for HTTPS setup. Before starting, ensure you have a Ubuntu 20.04 server with a non-root sudo user, a domain name pointing to your server’s IP, and basic familiarity with the command line.
What You’ll Need
- Ubuntu 20.04 LTS server with sudo access
- Domain name (e.g., example.com) with DNS A record pointing to your server
- Access to a terminal (SSH)
- Internet connection to download packages
Step-by-Step
-
Update system packages
Log into your server and run:
sudo apt update && sudo apt upgrade -yThis ensures all existing software is up to date.
-
Install Nginx
sudo apt install nginx -yAfter installation, start and enable Nginx:
sudo systemctl start nginx sudo systemctl enable nginxVerify it’s running with
sudo systemctl status nginx. You should see “active (running)”. -
Install MariaDB (MySQL-compatible database)
sudo apt install mariadb-server mariadb-client -ySecure the installation:
sudo mysql_secure_installationFollow the prompts: set a root password (or use unix_socket), remove anonymous users, disallow root login remotely, remove test database, and reload privileges. For a local setup, answering ‘Y’ to most is fine.
-
Create WordPress database and user
Log into MariaDB as root:
sudo mysql -u root -pEnter the root password you set. Then create a database and user (replace
wpuserandstrongpasswordwith your own):CREATE DATABASE wpdatabase; CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'strongpassword'; GRANT ALL PRIVILEGES ON wpdatabase.* TO 'wpuser'@'localhost'; FLUSH PRIVILEGES; EXIT; -
Install PHP and required extensions
sudo apt install php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip -yCheck the PHP-FPM service name (usually
php7.4-fpmon Ubuntu 20.04):sudo systemctl status php7.4-fpmEnsure it’s running and enabled.
-
Download and configure WordPress
Navigate to the web root and download WordPress:
cd /var/www/html sudo wget https://wordpress.org/latest.tar.gz sudo tar -xzf latest.tar.gz sudo mv wordpress/* . sudo rm -rf wordpress latest.tar.gzSet correct ownership and permissions:
sudo chown -R www-data:www-data /var/www/html sudo find /var/www/html -type d -exec chmod 755 {} \; sudo find /var/www/html -type f -exec chmod 644 {} \; -
Create Nginx server block
Create a new configuration file:
sudo nano /etc/nginx/sites-available/wordpressPaste the following (replace
example.comwith your domain):server { listen 80; server_name example.com www.example.com; root /var/www/html; 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:/var/run/php/php7.4-fpm.sock; } location ~ /\.ht { deny all; } }Save and exit (Ctrl+X, Y, Enter). Enable the site:
sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/ sudo rm /etc/nginx/sites-enabled/defaultTest the configuration and reload Nginx:
sudo nginx -t sudo systemctl reload nginx -
Run WordPress installation
Open your browser and go to
http://example.com. You’ll see the WordPress language selection. Choose your language, then fill in the database details:- Database Name:
wpdatabase - Username:
wpuser - Password:
strongpassword - Database Host:
localhost - Table Prefix:
wp_(default)
Click Submit, then Run the installation. Enter your site title, admin username, password, and email, then install.
- Database Name:
Common Mistakes
- Wrong PHP-FPM socket path: The
fastcgi_passline must match your PHP version. Usephp -vto check, and adjust the socket path (e.g.,php8.1-fpm.sockif you have PHP 8.1). - File permissions too loose: Setting files to 777 can cause security issues. Stick to 644 for files and 755 for directories, with owner
www-data. - Not removing default Nginx site: If you don’t remove the default site, it may conflict and serve the wrong content.
- Forgetting to enable the site: Creating a symlink in
sites-enabledis essential; otherwise Nginx won’t use your config.
Tips
- Use a strong database password: Avoid simple passwords; use a mix of letters, numbers, and symbols.
- Enable HTTPS: After installation, install Certbot and obtain a free SSL certificate with
sudo apt install certbot python3-certbot-nginxandsudo certbot --nginx. - Keep everything updated: Regularly run
sudo apt update && sudo apt upgradeto patch security issues. - Backup regularly: Use plugins or cron jobs to back up your database and files.
Troubleshooting
Nginx not starting: Check syntax with sudo nginx -t. Look at error logs: sudo tail -f /var/log/nginx/error.log. Common issues include port 80 already in use (stop Apache with sudo systemctl stop apache2) or syntax errors in your config.
WordPress shows “Error establishing a database connection”: Verify database credentials in wp-config.php. Ensure MariaDB is running (sudo systemctl status mariadb). Check that the user has correct privileges.
PHP files not executing (download instead): This usually means the PHP location block is missing or incorrect. Ensure the location ~ \.php$ block is present and the socket path is correct. Reload Nginx after changes.
403 Forbidden: Check file permissions and ownership. The web server needs read access to files and execute on directories. Run sudo chown -R www-data:www-data /var/www/html.
White screen of death: Often due to PHP errors. Enable debugging by editing wp-config.php and adding define('WP_DEBUG', true);. Check the PHP error log at /var/log/php7.4-fpm.log.
Frequently Asked Questions
Can I use Apache instead of Nginx?
Yes, but this guide is specifically for Nginx. If you prefer Apache, you’d need to install apache2 and use .htaccess rules, which differ from Nginx’s configuration.
How do I change my WordPress site URL after installation?
Go to Settings > General in the WordPress admin dashboard and update the WordPress Address and Site Address fields. Alternatively, edit wp-config.php with define('WP_HOME','http://example.com'); and define('WP_SITEURL','http://example.com');.
Why do I get a 404 on all pages except the homepage?
This is usually a permalink issue. Go to Settings > Permalinks and click “Save Changes” to flush rewrite rules. If that doesn’t work, ensure Nginx’s try_files directive is correct.
How do I enable HTTPS with a free SSL certificate?
Install Certbot and the Nginx plugin, then run sudo certbot --nginx. It will automatically modify your Nginx config and set up a cron job for renewal.
Can I install WordPress on a subdirectory like example.com/blog?
Yes, but you’d need to adjust the Nginx server block’s root and location directives accordingly. The process is similar but requires more careful path configuration.
What should I do if I forget my WordPress admin password?
Use the WordPress admin reset via email, or use phpMyAdmin to update the user_pass field with an MD5 hash of a new password. Alternatively, use WP-CLI: wp user update <user> --user_pass=newpassword.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Fix Device Manager Not Opening in Windows 11
- How to Pause Snapchat Location
- System Restore Points Missing in Windows? Fixes
- Install League of Legends on Linux: Full Guide
- Fix Error 0x80070001: Causes & Solutions
- Facebook.com: What It Is and Is It Safe?9.26 yd³