CMS Ubuntu Linux

How to Install Drupal with Nginx and Cloudflare on Ubuntu

Richard
Written by
Richard
Apr 23, 2019 Updated Apr 18, 2026 6 min read

This guide explains how to set up Drupal on an Ubuntu server using the Nginx web server and Cloudflare. Drupal is a powerful tool for building websites. Adding Cloudflare helps your site load faster, keeps it secure, and provides a free security certificate.

Why do this? Using these tools together makes your website faster for visitors and protects it from bad traffic. What happens when done? You will have a professional, secure, and high-performance Drupal website ready for content.

Setting up Cloudflare

First, you need a Cloudflare account. If you do not have one, visit the registered a domain name website to sign up.

If you already have an account, log in. Click the button to add a new site. https://dash.cloudflare.com/sign-up

Type in your domain name.

Cloudflare will look for your domain settings.

Cloudflare WordPress setup

Select the free plan option.

Cloudflare WordPress setup

Cloudflare will give you two “nameservers.” You must go to the website where you bought your domain name (like Google Domains) and replace their current nameservers with the ones Cloudflare provided.

Cloudflare WordPress setup

Wait for the changes to take effect. This can take up to an hour.

Cloudflare WordPress setup

Once your status says “Active,” go to the “Crypto” tab. Turn on “Full (strict) SSL” to keep your connection secure.

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

Scroll down to “Origin Certificates” and create a certificate.

Cloudflare WordPress Setup

Follow the steps to generate a private key and certificate.

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

Note: You will need admin privileges to create these files on your server. Run these commands on your Ubuntu server to create the files:

🐧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 from this link: Set up authenticated Origin pulls · Cloudflare SSL docs

Run these commands to create the final security file:

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

You should now have three files on your server. Make sure “Always Use HTTPS” is turned on in your Cloudflare settings.

Cloudflare WordPress Setup
Cloudflare WordPress Setup
This image has an empty alt attribute; its file name is cloudflare_wordpress_setup_8.png
WordPress Cloudflare
This image has an empty alt attribute; its file name is cloudflare_wordpress_setup_10.png

Installing Drupal and Nginx

Now, let’s set up your server. You will need admin privileges for these steps.

First, install the Nginx web server:

🐧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 web browser.

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

Installing the Database

Drupal needs a database to store information. We will use MariaDB:

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

Enable 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 the database with a password:

🐧Bash / Shell
sudo mysql_secure_installation

Follow the prompts to set a password and remove test settings. Test the connection:

🐧Bash / Shell
sudo mysql -u root -p
This image has an empty alt attribute; its file name is cloudflare_wordpress_setup_12.png

Installing PHP

Drupal uses PHP. Install it with these commands:

🐧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-gmp php7.2-curl php7.2-intl php7.2-mbstring php7.2-xmlrpc php7.2-mysql php7.2-gd php7.2-xml php7.2-cli php7.2-zip

Open the configuration file to make sure it works well with Drupal:

🐧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 to apply changes:

🐧Bash / Shell
sudo systemctl restart nginx.service

Create a test file to verify PHP is working:

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

Visit your site in a browser to see the test page.

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

Creating the Drupal Database

Log into your database and create a space for Drupal:

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

Downloading Drupal

Install the necessary tools to download Drupal:

🐧Bash / Shell
sudo apt install curl git
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

Download the latest version and set file permissions:

Command Prompt
cd /var/www/html
sudo git clone --branch 8.6.0 https://git.drupal.org/project/drupal.git example.com
cd /var/www/html/example.com
sudo composer install
🐧Bash / Shell
sudo chown -R www-data:www-data /var/www/html/example.com/
sudo chmod -R 755 /var/www/html/example.com/

Configuring Nginx and Finishing Up

Create the configuration file for your site:

🐧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 /index.php?$query_string;
}

location @rewrite {
rewrite ^/(.*)$ /index.php?q=$1;
}

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

location ~ ^/sites/.*/files/styles/ {
try_files $uri @rewrite;
}

location ~ ^(/+)?/system/files/ {
try_files $uri /index.php?$query_string;
}
}

Enable the site and restart Nginx:

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

Visit your domain in your browser to start the Drupal setup wizard. Follow the on-screen instructions to finish.

This image has an empty alt attribute; its file name is cloudflare_wordpress_setup_15.png
nginx default home page test
mariadb welcome
PHP Test Page
Drupal install composer

Don’t forget to install the Cloudflare module: https://www.drupal.org/project/cloudflare

To upgrade in the future, use this command:

🐧Bash / Shell
sudo composer update /var/www/html/example.com/core --with-dependencies
cd /var/www/html/example.com
sudo composer require drush/example.com
cd /var/www/html/example.com/vendor/drush/drush
./drush updatedb
./drush cr

Summary

By following this guide, you have secured your server with Cloudflare, installed the Nginx web server, set up a MariaDB database, and configured PHP. Your Drupal site is now running on a fast, secure foundation. You can now log in to your Drupal dashboard and begin creating your website content.

[Y/n]

[Y/n]

[Y/n]

[Y/n]

[Y/n]

[a-z-]

What are the steps to install Drupal on Ubuntu with Nginx?

To install Drupal on Ubuntu with Nginx, first, ensure you have Nginx and PHP installed. Then, download Drupal, configure Nginx to serve the Drupal files, and set up the database. Finally, complete the installation through the web interface.


How does Cloudflare improve my Drupal website's performance?

Cloudflare acts as a content delivery network (CDN) that caches your website content, reducing load times for users by serving data from the nearest location. It also optimizes images and provides minification for CSS and JavaScript, further enhancing performance.


Do I need a domain name to use Cloudflare?

Yes, you need a registered domain name to use Cloudflare. Cloudflare requires you to add your site by entering your domain name, which allows it to manage your DNS settings and provide its services.


What is the purpose of using Nginx with Drupal?

Nginx is a high-performance web server that can handle many simultaneous connections, making it ideal for high-traffic Drupal sites. It serves static files quickly and can be configured to work efficiently with PHP, improving overall site performance.


How do I configure Cloudflare SSL for my Drupal site?

To configure Cloudflare SSL for your Drupal site, log into your Cloudflare account and navigate to the SSL/TLS settings. Choose the appropriate SSL option, such as 'Full' or 'Flexible', and ensure your Drupal site is set up to handle HTTPS requests properly.

Was this guide helpful?

Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips 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.

Leave a Reply

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

Exit mobile version