Install phpMyadmin, NGINX and PHP 7.3 on Ubuntu

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, avr: 4.50)

phpMyAdmin is one of the popular frameworks for MySQL or MariaDB database management. It’s open source and free to use, the software can interact on the web interface and easy for the user to manage, create, read, update, delete, export, import and much more. In this tutorial, will guide you easily how to Install phpMyadmin NGINX and PHP 7.3 on Ubuntu

Prerequisites

Before starting with this guide, it’s better you need to have domains or subdomain name pointing to your public server IP. on the following tutorial we will use lab.axfon.com. If you do not have public IP or domain you may also follow this tutorial using local server.


Step 1: Install NGINX as Web Server

Now we are going to install NGINX stable version by default repository Ubuntu, to do this type the command below:

sudo apt update && sudo apt install nginx

Once NGINX already installed, to check and verify Nginx service status type the command below

sudo service nginx status

If it is running and working properly you will see the output NGINX active (running) like below

● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2019-01-03 21:00:12 UTC; 5h 3min ago
     Docs: man:nginx(8)
  Process: 3083 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, stat
  Process: 3068 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exi
 Main PID: 3087 (nginx)
    Tasks: 2 (limit: 665)
   Memory: 4.4M
   CGroup: /system.slice/nginx.service
           ├─3087 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
           └─3088 nginx: worker process
Jan 03 21:00:12 axfon-lab systemd[1]: Starting A high performance web server and a reverse pr
Jan 03 21:00:12 axfon-lab systemd[1]: nginx.service: Failed to parse PID from file /run/nginx
Jan 03 21:00:12 axfon-lab systemd[1]: Started A high performance web server and a reverse pro

To exit Nginx service status just press q on the keyboard


Step 2: Configuration the Firewall with UFW

UFW (Uncomplicated Firewall) is an Iptable interface to easily configure a firewall on your system. If it does not yet enable, it’s recommended to enable and setup the rule for Nginx

For the first, we have to add rule for SSH, let’s se the command line below

sudo ufw allow OpenSSH

Add the rule receive HTTP to Nginx

sudo ufw allow 'Nginx HTTP'

Then you will see on terminal

Rule added
Rule added (v6)'

Now enable ufw for Firewall.

sudo ufw enable

If prompted just pres Y to accept and continue and to check UFW status type the command below

sudo ufw status

You will see the output UFW active (running) like below

Status: active
To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
Nginx HTTP                 ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)
Nginx HTTP (v6)            ALLOW       Anywhere (v6)

NGINX web server now is ready on Ubuntu, now you may go to your web browser and visit your domain or IP. If you have not configured domain name yet and don’t know your IP, use the following command find out

sudo ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'

If everything is OK you will be presented on your browser with the default NGINX landing page as below


Step 3: Install PHP 7.3 FPM

When this tutorial made the PHP 7.3 is not yet available in Ubuntu default repositories, for installing it we have to add manually ondrej/php PPA by running the following command

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php

After adding the PPA we need to update Ubuntu, run the following command

sudo apt-get update

Once the PPA repository has been added and updated, now we are going to install PHP 7.3

sudo apt-get install php7.3-fpm php7.3-cli php7.3-mysql php7.3-gd php7.3-imagick php7.3-recode php7.3-tidy php7.3-xmlrpc php7.3-common php7.3-curl php7.3-mbstring php7.3-xml php7.3-bcmath php7.3-bz2 php7.3-intl php7.3-json php7.3-readline php7.3-zip

To verified PHP 7.3 was installed correctly on the web server, you may check the PHP version

sudo php -v

You will be presented on the terminal screen as below

PHP 7.3.0-2+ubuntu18.10.1+deb.sury.org+1 (cli) (built: Dec 17 2018 09:23:19) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.0-dev, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.0-2+ubuntu18.10.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

The default location of the PHP socket that Nginx List the contents for the directory /var/run/php/

ls /var/run/php/

You will see the output like below, note this below we are going to use for the next server block configuration

php7.3-fpm.pid php7.3-fpm.sock

Step 4: Configuration Server Blocks

Nginx Server Blocks allows to run or host one or multi-domain on a single server. Nginx contains a default server block in /etc/nginx/sites-available/default.

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

Let’s see below configuration, on the red line you may change server_name with your IP address or your domain and add index.php after index

server {
    listen 80;
    listen [::]:80;
    root /var/www/html;
    index index.php index.html index.htm;
    server_name lab.axfon.com;

    location / {
    try_files $uri $uri/ /index.php?$args;        
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
        fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
    }

}

Press Ctrl/Cmd + X and then press Y and ENTER to save changes

Set permission ownership for current user to be able to modify any files in these directories.

sudo chown -R $(whoami):$(whoami) /var/www/html/

Grant Directory Permission

sudo chmod -R 755 /var/www

Create file  info.php into the root directory as the above configuration

sudo echo "<?php phpinfo(); ?>" > /var/www/html/info.php

Changes made in the NGINX configuration file will not be applied until the command to Restart and Before testing on the Browser we have to verify and make sure no error.

sudo service nginx restart

You can now view this page in your web browser by visiting your server’s domain name or public IP address followed by /info.php: http://YOUR_DOMAIN_or_IP/info.php


Step 5: Install MariaDB or MySQL

There two options using MariaDB or MySQL Database, please choose one that you prefer with. To install MariaDB or MySQL on Ubuntu server let’s following steps:

Installing MariaDB

MariaDB is a fork of MySQL, the database structure and indexes of MariaDB are the same as MySQL. This allows you to switch from MySQL to MariaDB without having to alter your applications since the data and data structures will not need to change.

To install MariaDB packages from the MariaDB repository use the following command

sudo apt-get install mariadb-server mariadb-client

Press Y and ENTER when prompted on installing process
MariaDB service will start automatically, the commands below can be used to stop, start and enable MariaDB service.

sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

To check and verify MariaDB is working, use the command below

sudo systemctl status mariadb

The output MariaDB active (running) like below

● mariadb.service - MariaDB database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2019-01-04 05:00:38 UTC; 14s ago
 Main PID: 18447 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 27 (limit: 665)
   Memory: 69.9M
   CGroup: /system.slice/mariadb.service
           └─18447 /usr/sbin/mysqld
Jan 04 05:00:39 axfon-lab /etc/mysql/debian-start[18486]: mysql
Jan 04 05:00:39 axfon-lab /etc/mysql/debian-start[18486]: performance_schema
Jan 04 05:00:39 axfon-lab /etc/mysql/debian-start[18486]: Phase 6/7: Checking and upgrading t
Jan 04 05:00:39 axfon-lab /etc/mysql/debian-start[18486]: Processing databases
Jan 04 05:00:39 axfon-lab /etc/mysql/debian-start[18486]: information_schema
Jan 04 05:00:39 axfon-lab /etc/mysql/debian-start[18486]: performance_schema
Jan 04 05:00:39 axfon-lab /etc/mysql/debian-start[18486]: Phase 7/7: Running 'FLUSH PRIVILEGE
Jan 04 05:00:39 axfon-lab /etc/mysql/debian-start[18486]: OK
Jan 04 05:00:39 axfon-lab /etc/mysql/debian-start[18545]: Checking for insecure root accounts
Jan 04 05:00:39 axfon-lab /etc/mysql/debian-start[18549]: Triggering myisam-recover for all M

Press q on the keyboard to exit service status

To check MariaDB server version use the command below

mysql -V

You will see the output

mysql  Ver 15.1 Distrib 10.1.29-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

If you already installed MariaDB server above, you should ignore below Installation MySQL and jump to next step


Installing MySQL

MySQL is an open-source relational database management system (RDBMS). Just like all other relational databases, MySQL uses tables, constraints, triggers, roles, stored procedures and views as the core components

To install MySQL packages from the MySQL repository use the following command

sudo apt update && sudo apt install mysql-server

Press Y and ENTER when prompted on installing process

MySQL service will start automatically, the commands below can be used to stop, and start MySQL service.

sudo service mysql stop
sudo service mysql start

To check and verify MySQL is working, use the command below

sudo service mysql status

The output MySQL active (running) like below

● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since since Wed 2018-05-09 21:10:24 UTC; 16s ago
 Main PID: 30545 (mysqld)
    Tasks: 27 (limit: 1153)
   CGroup: /system.slice/mysql.service
           └─30545 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid

Press q on the keyboard to exit service status

To check MySQL server version use the command below

mysql -V

You will see the output

mysql  Ver 15.1 Distrib 10.1.29-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Step 6: Install phpMyadmin

To install phpMyadmin we will use the default repository from Ubuntu. When installing phpMyAdmin on the server, it automatically created a database user called phpmyadmin.

sudo apt update && sudo apt install phpmyadmin

Then you will be presented on screen for configuration phpMyadmin, just pressing TAB to highlight OK then pressENTER

The phpMyadmin package must have a database installed and configured before it can be used. press TAB to highlight YES then pressENTER

Please provide a password for phpmyadmin to register with the database server. enter YOUR_PASSWORD or left it blank (will generate random password) then press TAB to highlight OK then pressENTER


Step 7: Create Symbolic Link

For NGINX serve the phpMyAdmin files correctly, we have to create a symbolic link from the phpMyAdmin directory /usr/share/phpmyadmin to the default location of the Nginx document root into directory /var/www/html/, (you may change directory depending on your setup).

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

you can change with another name of phpmyadmin in root directory


Step 8: Testing phpMyadmin on the Browser

You can now view this page in your web browser by visiting your server’s domain name or public IP address followed by /phpmyadminhttp://your_domain_or_IP/phpmyadmin


Step 9: Troubleshooting Error Login

If you could not log in as root and your_password on the above phpMyadmin, you have to create a superuser account.

sudo mysql -p -u root

Create a new user and give it a strong password (on green text change with yours)

CREATE USER 'axfonuser'@'localhost' IDENTIFIED BY 'axfonpassword';

Then grant your new user appropriate privileges, grant the user privileges to all tables within the database

GRANT ALL PRIVILEGES ON *.* TO 'axfonuser'@'localhost' WITH GRANT OPTION;

Finally exit MySQL shell

EXIT

You may now be able to access phpMyAdmin using your new user account ….Congrats..!!


If this tutorial could help you, please rate above Star button rating and share to help others find it! Feel free to leave a comment below.

Recommended For You

Axfon

About the Author: Axfon

Axfon.com is a site Online publisher for collection of guides and tutorials about Internet Technology