How to Install Nginx with Google PageSpeed, MariaDB, PHP And PhpMyAdmin on Ubuntu 20.04

Nginx installed MySQL/MariaDB and PHP/Python bundles on the Cloud computing system. For example, it compatible with Windows, Linux, MAC, and many more. And it configured to run as a process for hosting sites, apps and more.

And PageSpeed boosts site performance by variation the web resources, reduce web latency, etc… Whereas, PhpMyAdmin is open-source, famous, free, plus supports a vast range of operations.

We prefer Nginx 20+ because it uses load balancing, HTTP caching and can be a reverse proxy. Sad but true, it doesn’t support HTTP3 protocol. So we come out to take you in the right directions.

This guide will help you learn to install Nginx 20+. And how to configure MariaDB, PHP with PhpMyAdmin on Ubuntu 20 module with Nginx. And more importantly, we provide an entire video about it at the bottom of this article.

So, first thing first, let’s install the Nginx 20+. And then configure MariaDB, PHP with PhpMyAdmin on Ubuntu 20.

1. Install Nginx 20+ on Ubuntu 20+:

First, begin with updating your software packages and then install Nginx.

sudo apt update && sudo apt upgrade
sudo apt install nginx

After installing, you may verify the status.

sudo service nginx status
 nginx.service - The NGINX HTTP and reverse proxy server
    Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
    Active: active (running) since Fri 2019-07-26 09:22:51 UTC; 1h 24min ago
   Process: 14404 ExecStop=/bin/kill -s QUIT $MAINPID (code=exited, status=0/SUCCESS)
   Process: 14419 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
   Process: 14407 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Main PID: 14423 (nginx)
     Tasks: 10 (limit: 2361)
    CGroup: /system.slice/nginx.service
            ├─14423 nginx: master process /usr/sbin/nginx
            ├─14426 nginx: worker process
            └─14427 nginx: cache manager process 

2. Install PageSpeed and Modules:

Install ngx_pagespeed with the command below:

sudo apt install libssl-dev
bash <(curl -f -L -sS \
--nginx-version latest

At installation, you’ll see

Extracting nginx…About to build nginx. Do you have any additional ./configure arguments you would like to set? For example, if you would like to make nginx with https support, give –with-http_ssl_module. If you don't have any, press enter.

Now to add the modules, type or copy the text below:

--prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/ --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module

After that, continue the installation by entering Y

3. Configure System for Nginx:

With a system service, you may control NginX (start, stop, restart) process. So, re-edit the default system configuration and restore it with the following code.

sudo nano /lib/systemd/system/nginx.service

Restore it with the following code:

Description=The NGINX HTTP and reverse proxy server

ExecStartPre=/usr/sbin/nginx -t
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID


Now, save the file and leave.

Reload the daemon system to enable the changes.

sudo systemctl daemon-reload

4. Cache Directory Setup Formula:

Make a new user name nginx except for a home directory.

sudo useradd --no-create-home nginx
sudo mkdir -p /var/cache/nginx/client_temp
sudo mkdir /var/cache/ngx_pagespeed

5. Correct Permissions Setup:

sudo chown nginx:nginx /var/cache/ngx_pagespeed
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html

6. PageSpeed enable:

You have to edit the Nginx virtual host configuration, plus sum up the PageSpeed configurations.

sudo nano /etc/nginx/sites-available/default

With the following, restore the contents of the file:

server {
     listen 80 default_server;
     listen [::]:80 default_server;


     root /var/www/html;
     index index.php index.html index.htm;

     access_log   logs/yourdomainname_access.log;
     error_log    logs/yourdomainname_error.log;

     location / {
         try_files $uri $uri/ =404;

     pagespeed on;
     pagespeed FileCachePath "/var/cache/ngx_pagespeed/";
     pagespeed RewriteLevel OptimizeForBandwidth;

     location ~ ".pagespeed.([a-z].)?[a-z]{2}.[^.]{10}.[^.]+" {
         add_header "" "";

     location ~ "^/pagespeed_static/" { }
     location ~ "^/ngx_pagespeed_beacon$" { }

Now, save the file and leave. If you get any error like with restarting nginx , please turn off the moudle ( include /etc/nginx/modules-enabled/*.conf; ), let’s navigate to sudo nano /etc/nginx/nginx.conf.So the configuration will look like below.

user www-data;
worker_processes auto;
pid /run/;
#include /etc/nginx/modules-enabled/*.conf;

Test your configuration:

Make a new index.html file in the root directory.

sudo nano /var/www/html/index.html

Create your content, then save the file and restart Nginx.

Test your PageSpeed:

Ask for your domain name using the curl command to test.

curl -I -X GET

You’ll get similar results to the following.

HTTP/2 200
server: nginx/1.17.2
content-type: text/html
vary: Accept-Encoding
date: Fri, 26 Jul 2019 12:00:42 GMT
cache-control: max-age=0, no-cache

It means PageSpeed is activated and optimizing.

7. Install MariaDB on Ubuntu 20:


It’s another best open-source relational database that fit today’s modern world. It built by the MySQL key developers and ensured to remain open source. MariaDB also has enterprise features, such as real ACID compliance and full SQL.

Now, install the database management system of MariaDB.

$ sudo apt install mariadb-server mariadb-client

You can start and verify its service by using the command right after installation.

$ sudo systemctl status mysql

Now, you’ve to secure your installation through security scripts.

$ sudo mysql_secure_installation

Right after, type or enter the below security question:

    1. Set root password? [Y/n]: y
    2. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
    3. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
    4. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
    5. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

security question

8. Install PHP on Ubuntu 20

It’s a top-class scripting language best suited for web developments. PHP is a fast, pragmatic, and flexible server-side language. Plus, it empowers everything from blog to famous websites. By using the below command, you may able to install PHP, PHP-FPM and other modules.

$ sudo apt install php php-fpm php-common php-mysql php-gd php-cli

You can start and verify its service by using the command right after installation.

$ sudo systemctl status php7.2-fpm

After that, configure PHP-FPM to present PHP based web apps or sites.

$ sudo vim /etc/php/7.2/fpm/php.ini

Please search for the; cgi.fix_pathinfo=1 and modify it with the below command.


Next, configure PHP-FPM to the default Nginx server block configuration file to process PHP scripts.

$ sudo vim /etc/nginx/sites-available/default

Uncomment the configuration following section to get PHP scripts to the FastCGI server.

location ~ \.php$ {
            include snippets/fastcgi-php.conf;
        	fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;

nginx server block

After having changed, reboot the php-fpm and nginx services to embed the current changes.

$ sudo systemctl restart php7.2-fpm
$ sudo systemctl restart nginx

You can test your PHP setup in a web server document with a below single command by creating a simple info.php page.

$ echo "" | sudo tee /var/www/html/info.php

Now, run a web browser and type your URL to see the php info page.


php info

9. Install PhpMyAdmin on Ubuntu 20

Now, to administrating the MariaDB database on Ubuntu 20 with ease, install the PhpMyAdmin.

$ sudo apt install phpmyadmin

At the package installation time, it’ll ask to choose a web server that automated configured to run phpMyAdmin. And Nginx is not on the list, so hit the TAB key then press Enter.

Web Server

PhpMyAdmin Configuration

Then, type the password for MySQL to make a database for phpmyadmin.

set password

So it is time to finish the phpmyadmin installation process here. And you may able to access the interface by making the below symlink.

$ sudo ln -s  /usr/share/phpmyadmin /var/www/html/phpmyadmin

The PhpMyAdmin index file is index.php. And make sure that you’ve added it to the index files list. In your default server block config file /etc/nginx/sites-available/default displayed in the below screenshot.

index index.php index.html index.htm index.nginx-debian.html;

index file

After that, place the proper permissions to inhibit entrance denied errors on the phpmyadmin root directory.

$ sudo chmod 775 -R /usr/share/phpmyadmin/
$ sudo chown root:nginx -R /usr/share/phpmyadmin/

Next, enter the below URL to access PhpMyAdmin, from a web browser.


At last, confirm the phpMyAdmin using your MariaDB root username and password.


Okay, that’s it! This article describes how to set up and configure the trendy MariaDB, PHP with PhpMyAdmin in Ubuntu 20. If you have any queries, let us know via the comments section.

In conclusion, I hope this post will benefit you. And don’t forget to send your review, as those are very important to us. And stay safe and secure for the furthermore engaging, attractive, and informative articles.

Inspire us with your love!

Facebook Twitter Pinterest Reddit

Zakariar Habib is a freelance writer with more than 2 years. He is trying to learn about new technology that will keep him updated with the modern tech world. You can find him at the

You can check also

Leave a Reply

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