Categories
Tutorials

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.

http://IP_SERVER

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

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 'https://mariadb.org/mariadb_release_signing_key.asc'

Once the key is imported add the apt repository URL

sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://mirror.nodesdirect.com/mariadb/repo/10.4/ubuntu bionic main'

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

apt install mariadb-server -y
systemctl status mariadb
mysql_secure_installation

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 https://files.phpmyadmin.net/phpMyAdmin/5.0.2/phpMyAdmin-5.0.2-english.tar.gz
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
Configure NGINX

Open the NGINX configuration file by entering the following command.

nano /etc/nginx/sites-available/default

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

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.

http://IP_SERVER/phpmyadmin

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.โ€

config.inc.php

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

mv /usr/share/phpmyadmin/config.sample.inc.php /usr/share/phpmyadmin/config.inc.php

Open the PHP Config file by entering the following command

sudo nano /usr/share/phpmyadmin/config.inc.php

Enter blowfish secret code with 32 characters random phrase.

$cfg['blowfish_secret'] = '32_char_random_phrase_here';
// KLS$vbc91Lkja$vc@opGbxA278EWopdc
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.

Latest Posts

1 reply on “Installing Nginx, PHP, MySQL and PHPMyAdmin on Ubuntu 18.04”

Leave a Reply

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