Installing Nginx, PHP, MySQL and PHPMyAdmin on Ubuntu 18.04

This tutorial is created to set up Nginx and PHPMyAdmin along with PHP 7.4 on ubuntu 18.04 with simple and easy steps.

Update via the command line

Before beginning the whole set up process make sure you’re at the command line and type the following commands.

sudo apt update
 Install NGINX

Now let’s install NGINX and check whether it’s running or not.

sudo apt install nginx -y
systemctl status nginx

The β€œ-y” in the end automatically enters β€œyes” when the command β€œsudo apt install nginx -y” ask for your confirmation before installing. After the installation. Check your Server by navigating into your IP ADDRESS as shown below.

Code language: JavaScript (javascript)
Installing PHP and MariaDB

Install PHP 7.4 and all the important plugins and check the server status.

sudo apt install software-properties-common -y
sudo add-apt-repository ppa:ondrej/php
sudo apt install php7.4-fpm php7.4-common php7.4-dom php7.4-intl php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring php7.4-soap php7.4-zip php7.4-bcmath -y

Run the following command to check the status of php 7.4

systemctl status php7.4-fpm
Code language: CSS (css)

Import MariaDB gpg key by running the command below to add it to your system.

Visit MariaDB website to obtain the gpg key

sudo apt-key adv --fetch-keys ''
Code language: JavaScript (javascript)

Once the key is imported add the apt repository URL

sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] bionic main'
Code language: JavaScript (javascript)

After that Install the MariaDB Server on ubuntu by following commands.

apt install mariadb-server -y
systemctl status mariadb
Install PHPMyAdmin

Install PHPMyAdmin 5.0.2 as shown below by extracting it to the /usr/share/phpmyadmin directory.

To install the latest version of phpMyAdmin visit the phpMyAdmin page

wget -c
tar xzvf phpMyAdmin-5.0.2-english.tar.gz
sudo mv phpMyAdmin-5.0.2-english /usr/share/phpmyadmin
ln -s /usr/share/phpmyadmin /var/www/html
Code language: JavaScript (javascript)
Configure NGINX

Open the NGINX configuration file by entering the following command.

nano /etc/nginx/sites-available/default
Code language: JavaScript (javascript)

Add the following lines of code to the server block

index index.php index.html index.htm;

location ~ \.php$ {
  try_files $fastcgi_script_name =404;
  include fastcgi_params;
  fastcgi_pass  unix:/run/php/php7.4-fpm.sock;
  fastcgi_index index.php;
  fastcgi_param DOCUMENT_ROOT  $realpath_root;
  fastcgi_param SCRIPT_FILENAME   $realpath_root$fastcgi_script_name; 

Code language: PHP (php)

Test the configuration and restart the server.

nginx -t
systemctl restart nginx
systemctl status nginx

Hoorey! Now it’s time to test PHPMyAdmin by typing following URL.

Code language: JavaScript (javascript)

If you encounter an error The $cfg'TempDir' is not accessible... on PHPMyAdmin.

Create a tmp Directory in PHPMyAdmin

mkdir /usr/share/phpmyadmin/tmp

And then add permission to that created directory

chmod 755 -R /usr/share/phpmyadmin/tmp

If you are see an error β€œThe secret passphrase in configuration (blowfish_secret) is too short.”

If your PHPMyAdmin directory doesn’t contain any file then copy and create as shown below.

mv /usr/share/phpmyadmin/ /usr/share/phpmyadmin/

Open the PHP Config file by entering the following command

sudo nano /usr/share/phpmyadmin/

Enter blowfish secret code with 32 characters random phrase.

$cfg['blowfish_secret'] = '32_char_random_phrase_here';
// KLS$vbc91Lkja$vc@opGbxA278EWopdc
Code language: PHP (php)
Watch the whole tutorial from the video below,

If you like the article please share with others and drop your ideas and suggestions at the comment section.