Skip to content
Follow
CMS Ubuntu Linux

How to Setup WordPress Nginx Cloudflare Ubuntu Fast

Richard
Written by
Richard
Apr 22, 2019 Updated Sep 15, 2026 5 min read
How to Change Default Apps in Ubuntu
How to Change Default Apps in Ubuntu

Running WordPress on Ubuntu 22.04 LTS with Nginx (a fast web server) and Cloudflare builds a website that loads in under one second and blocks common hackers. Nginx serves your page files quickly, while Cloudflare provides a free content delivery network to speed up access for visitors around the world.

Advertisement

You connect these three tools step by step to secure your site and cut down page load times.

⚡ Quick Answer

Set up WordPress with Nginx and Cloudflare on Ubuntu by installing Nginx, MariaDB, and PHP. Configure Cloudflare by adding your domain, setting SSL to Full (strict), and enabling Always Use HTTPS. Then, create Nginx server blocks for your WordPress site and adjust PHP settings.

Advertisement

Why set this up?

You want this setup to protect your site from hackers and to ensure your pages load quickly for visitors. It adds a professional layer of security and performance optimization to your blog or business site.

What happens when done?

Once finished, your website will be fully encrypted with an SSL certificate, hosted on a fast Nginx server, and protected by Cloudflare’s global network.

How to set up Cloudflare

Setting up Cloudflare protects your WordPress site and speeds it up by routing traffic through its global network. Go to the Cloudflare website, create an account, and add your domain name so Cloudflare can scan your existing DNS records and take over managing your traffic.

Advertisement

Enter your email and create an account.

Cloudflare WordPress setup
cloudflare wordpress setup

After logging in, click the button to add a site.

Cloudflare WordPress setup
cloudflare wordpress setup 1

Type in your domain name. registered

Cloudflare WordPress setup
cloudflare wordpress setup 2

Cloudflare will look for your current domain settings. If found, it will import them automatically.

Advertisement
Cloudflare WordPress setup
cloudflare wordpress setup 3

Choose the free plan for this setup.

Cloudflare WordPress setup
cloudflare wordpress setup 4
⚠️WarningCloudflare will give you two nameservers.

You must log in to your domain provider's website and replace your old nameservers with these new ones.

This image has an empty alt attribute; its file name is cloudflare-setup-name-servers.png
cloudflare setup name servers

For example, if you use a service like Google Domains, find the custom nameserver section and paste the Cloudflare addresses there.

Cloudflare WordPress Setup
cloudflare wordpress setup 16

After saving, return to Cloudflare and wait for the status to show as Active. This can take up to an hour.

Advertisement
This image has an empty alt attribute; its file name is cloudflare-overview-active.png
cloudflare overview active

Once active, you will see your DNS records.

Cloudflare WordPress Setup
cloudflare wordpress setup 6

Click the Crypto tab and set your SSL to Full (strict).

Cloudflare WordPress Setup
cloudflare wordpress setup 17

Scroll down to Origin Certificates and click to create one. These help encrypt the connection between Cloudflare and your server.

This image has an empty alt attribute; its file name is cloudflare_wordpress_setup_8.png
cloudflare wordpress setup 8

Let Cloudflare generate the key and click Next.

Advertisement
WordPress Cloudflare
cloudflare wordpress setup 9
📝NoteYou will need admin privileges (sudo) to create these files on your server.
🐧Bash / Shell
sudo nano /etc/ssl/private/cloudflare_key_example.com.pem
🐧Bash / Shell
sudo nano /etc/ssl/certs/cloudflare_example.com.pem

Download the Cloudflare Origin Pull certificate here: Set up authenticated Origin pulls · Cloudflare SSL docs

🐧Bash / Shell
sudo nano /etc/ssl/certs/origin-pull-ca.pem

You should now have three files on your server. Keep these safe.

This image has an empty alt attribute; its file name is cloudflare_wordpress_setup_10.png
cloudflare wordpress setup 10

In the Cloudflare Crypto settings, turn on "Always use HTTPS."

Advertisement
This image has an empty alt attribute; its file name is cloudflare_wordpress_setup_11.png
cloudflare wordpress setup 11

Enable "Authenticated Origin Pulls" and "Opportunistic Encryption."

This image has an empty alt attribute; its file name is cloudflare_wordpress_setup_12.png
cloudflare wordpress setup 12

Enable "Automatic HTTPS Rewrites."

This image has an empty alt attribute; its file name is cloudflare_wordpress_setup_13.png
cloudflare wordpress setup 13

Go to Page Rules and create a rule to always use HTTPS for your domain.

This image has an empty alt attribute; its file name is cloudflare_wordpress_setup_15.png
cloudflare wordpress setup 15

How to install and configure WordPress

1Install Nginx

Requires admin privileges.

Advertisement
🐧Bash / Shell
sudo apt update
sudo apt install nginx

Use these commands to manage the service:

🐧Bash / Shell
sudo systemctl stop nginx.service
sudo systemctl start nginx.service
sudo systemctl enable nginx.service

Test if it works by visiting your server's address in a browser.

nginx default home page test
nginx default page

2Install MariaDB

Installing MariaDB on Ubuntu provides the database your WordPress site needs to store posts, pages, and user data. Run the sudo apt-get install mariadb-server mariadb-client command in your terminal, then start the service so it runs automatically every time your server boots up.

🐧Bash / Shell
sudo apt-get install mariadb-server mariadb-client

Manage the service:

🐧Bash / Shell
sudo systemctl stop mysql.service
sudo systemctl start mysql.service
sudo systemctl enable mysql.service
🐧Bash / Shell
sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

Secure your database:

🐧Bash / Shell
sudo mysql_secure_installation

Test the installation:

🐧Bash / Shell
sudo mysql -u root -p
mariadb welcome
mariadb ubuntu 1604

3Install PHP

Installing PHP on Ubuntu allows your server to process the code that WordPress uses to build pages. Add a software repository to get the latest PHP versions, update your package list, and install the necessary packages along with PHP-FPM to help Nginx handle requests.

🐧Bash / Shell
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
🐧Bash / Shell
sudo apt update
🐧Bash / Shell
sudo apt install php7.2-fpm php7.2-common php7.2-mysql php7.2-gmp php7.2-curl php7.2-intl php7.2-mbstring php7.2-xmlrpc php7.2-gd php7.2-xml php7.2-cli php7.2-zip

Update the configuration file:

🐧Bash / Shell
sudo nano /etc/php/7.2/fpm/php.ini
💻Code
file_uploads = On
allow_url_fopen = On
short_open_tag = On
memory_limit = 256M
cgi.fix_pathinfo = 0
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = America/Chicago

Restart Nginx:

🐧Bash / Shell
sudo systemctl restart nginx.service

Create a test file to verify PHP:

🐧Bash / Shell
sudo nano /var/www/html/phpinfo.php
💻Code

Visit the file in your browser to see the info page.

PHP Test Page
php test page

4Create the Database

Requires admin privileges.

🐧Bash / Shell
sudo mysql -u root -p
💻Code
CREATE DATABASE wpdatabase;
💻Code
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'new_password_here';
💻Code
GRANT ALL ON wpdatabase.* TO 'wpuser'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION;
💻Code
FLUSH PRIVILEGES;
EXIT;

5Download WordPress

⬛Command Prompt
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xvzf latest.tar.gz
sudo mv wordpress /var/www/html/example.com
🐧Bash / Shell
sudo chown -R www-data:www-data /var/www/html/example.com/
sudo chmod -R 755 /var/www/html/example.com/

6Configure Nginx for WordPress

Configuring Nginx tells your web server how to handle visitor requests for your WordPress site and process PHP files correctly. Open your site configuration file using sudo nano /etc/nginx/sites-available/your_domain to set your server name and point Nginx to your website files.

🐧Bash / Shell
sudo nano /etc/nginx/sites-available/example.com
🐘PHP
server {
listen 80;
listen [::]:80;
listen 443 ssl http2;
listen [::]:443 ssl http2;

server_name example.com www.example.com;
root /var/www/html/example.com;
index index.php;

ssl_certificate /etc/ssl/certs/cloudflare_example.com.pem;
ssl_certificate_key /etc/ssl/private/cloudflare_key_example.com.pem;
ssl_client_certificate /etc/ssl/certs/origin-pull-ca.pem;
ssl_verify_client on;

client_max_body_size 100M;

autoindex off;

location / {
try_files $uri $uri/ /index.php?$args;
}

location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

7Enable the site

Enabling your WordPress site makes the Nginx configuration active so visitors can finally load your pages. Create a symbolic link using sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/ to activate the site, restart Nginx, and run the WordPress setup wizard in your browser.

🐧Bash / Shell
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo systemctl restart nginx.service

Visit your domain in a browser to finish the WordPress setup wizard.

WordPress Ubuntu Installation
wordpress 50 ubuntu install

Enter the database details you created earlier.

WordPress Ubuntu Installation
wordpress 50 ubuntu install 1
WordPress Ubuntu Installation
wordpress 50 ubuntu install 2
WordPress Ubuntu Installation
wordpress 50 ubuntu install 3

Create your admin account.

WordPress installation on Ubuntu
wordpress 50 ubuntu install 4
WordPress Ubuntu install
wordpress 50 ubuntu install 5

Finally, install the official Cloudflare plugin on your WordPress dashboard to finish the integration.

Summary

By following these steps, you have successfully secured your website with Cloudflare SSL, set up a high-performance Nginx web server, and installed WordPress with a dedicated MariaDB database on your Ubuntu Linux system.

[Y/n]

[Y/n]

[Y/n]

[Y/n]

[Y/n]









Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.

Advertisement

📚 Related Tutorials

How to Setup Joomla on Ubuntu with Nginx & Cloudflare
CMS How to Setup Joomla on Ubuntu with Nginx & Cloudflare
How to Install Drupal with Nginx and Cloudflare on Ubuntu
CMS How to Install Drupal with Nginx and Cloudflare on Ubuntu
How to Install FossBilling with Nginx on Ubuntu Linux
CMS How to Install FossBilling with Nginx on Ubuntu Linux
How to Install FreeScout with Nginx on Ubuntu Linux
CMS How to Install FreeScout with Nginx on Ubuntu Linux

No comments yet — be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *