CMS Ubuntu Linux

How to Setup WordPress with Nginx and Cloudflare on Ubuntu

Richard
Written by
Richard
Apr 22, 2019 Updated Apr 18, 2026 6 min read
How to Setup WordPress with Nginx and Cloudflare on Ubuntu

Setting up WordPress on Ubuntu Linux using nginx-and-cloudflare-cdn-ssl-on-ubuntu-16-04-18-04/" class="sal-link" rel="noopener" target="_blank" data-sal-id="15977">Nginx and Cloudflare is a great way to make your website faster and more secure. Cloudflare acts as a shield and a booster for your site, while Nginx handles your web traffic efficiently.

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

First, you need a Cloudflare account. This post assumes you already have registered a domain name. If not, sign up first.

https://dash.cloudflare.com/sign-up

Enter your email and create an account.

Cloudflare WordPress setup

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

Cloudflare WordPress setup

Type in your domain name. registered

Cloudflare WordPress setup

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

Cloudflare WordPress setup

Choose the free plan for this setup.

Cloudflare WordPress setup

Cloudflare 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

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

Cloudflare WordPress Setup

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

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

Once active, you will see your DNS records.

Cloudflare WordPress Setup

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

Cloudflare WordPress Setup

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

Let Cloudflare generate the key and click Next.

WordPress Cloudflare

Note: You 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

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

This image has an empty alt attribute; its file name is cloudflare_wordpress_setup_11.png

Enable “Authenticated Origin Pulls” and “Opportunistic Encryption.”

This image has an empty alt attribute; its file name is cloudflare_wordpress_setup_12.png

Enable “Automatic HTTPS Rewrites.”

This image has an empty alt attribute; its file name is cloudflare_wordpress_setup_13.png

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

How to install and configure WordPress

1. Install Nginx

Requires admin privileges.

🐧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

2. Install MariaDB

Requires admin privileges.

🐧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

3. Install PHP

Requires admin privileges.

🐧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

4. Create 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;

5. Download 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/

6. Configure Nginx for WordPress

Requires admin privileges.

🐧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;
}
}

7. Enable the site

Requires admin privileges.

🐧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

Enter the database details you created earlier.

WordPress Ubuntu Installation
WordPress Ubuntu Installation
WordPress Ubuntu Installation

Create your admin account.

WordPress installation on Ubuntu
WordPress Ubuntu install

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]

How do I install WordPress on Ubuntu with Nginx?

To install WordPress on Ubuntu with Nginx, first, ensure you have Nginx and PHP installed. Then, download WordPress, configure the Nginx server block for your domain, and set the correct permissions for the WordPress directory.


What are the benefits of using Cloudflare with WordPress?

Using Cloudflare with WordPress provides benefits such as improved website performance through its CDN, enhanced security features to protect against attacks, and free SSL certificates to secure your site.


How do I set up Cloudflare for my WordPress site?

To set up Cloudflare for your WordPress site, sign up for a Cloudflare account, add your site, update your domain's nameservers to those provided by Cloudflare, and enable SSL in the Crypto tab of your Cloudflare dashboard.


Can I use Nginx instead of Apache for WordPress?

Yes, you can use Nginx instead of Apache for WordPress. Nginx is known for its high performance and low resource consumption, making it a great choice for hosting WordPress sites.


What is the difference between Full and Full (strict) SSL in Cloudflare?

Full SSL encrypts the connection between Cloudflare and your server, while Full (strict) SSL requires a valid SSL certificate on your server. Using Full (strict) SSL is recommended for better security.

Was this guide helpful?

Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, the owner and lead writer at Geek Rewind, is a tech enthusiast passionate about simplifying complex IT topics. His years of hands-on experience in system administration and enterprise IT operations have honed his ability to provide practical insights and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

2467 articles → Twitter

📚 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

Leave a Reply

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