Install MySQL

sudo apt install mysql-server

Run security script

Accept almost everything, and add secure root password:

sudo mysql_secure_installation

Change authentication method

If you don’t change the authentication method from auth_socket to mysql_native_password then anyone with a sudo user password can log in as root.

To check the authentication method, enter MySQL:

sudo mysql

And type:

SELECT user,authentication_string,plugin,host FROM mysql.user;

To configure the root account to authenticate with a password, run the following ALTER USER command. Be sure to change password to a strong password of your choosing, and note that this command will change the root password you set in the security script:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

Then, run FLUSH PRIVILEGES which tells the server to reload the grant tables and put your new changes into effect:


Check again the authentication method, to confirm the changes:

SELECT user,authentication_string,plugin,host FROM mysql.user;

Exit the MySQL shell:


Create new user with all privileges

Enter mysql:

sudo mysql -u root -p

Create a new user and give it a strong password:

CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';

Grant your user the appropriate privileges:


Exit the MySQL shell:



Install Apache

sudo apt install apache2

Adjust the Firewall to Allow Web Traffic

After you have followed the initial server setup and enabled the UFW firewall, make sure that your firewall allows HTTP and HTTPS traffic. You can check that UFW has an application profile for Apache like so:

sudo ufw app list

Look at the full Apache Full profile, it should show that it enables traffic on port 80 and 443:

sudo ufw app info "Apache Full"

Allow incoming HTTP and HTTPS traffic for this profile:

sudo ufw allow in "Apache Full"

Verify your installation, visiting your servers IP:


You will see the default Ubuntu 18.04 Apache web page


Install PHP and helper packages

sudo apt install php libapache2-mod-php php-mysql


Install phpMyAdmin

sudo apt update
sudo apt install phpmyadmin php-mbstring php-gettext

This will ask you a few questions in order to configure your installation correctly:

  • For the server selection, choose apache2.
  • Select Yes when asked whether to use dbconfig-common to set up the database.
  • You will be asked to choose a MySQL application password for phpMyAdmin
    • It will be the password for the phpmyadmin user for MySQL.

Enable the mbstring PHP extension

sudo phpenmod mbstring

Restart Apache

sudo systemctl restart apache2

Securing Your phpMyAdmin Instance

If you want to secure more the phpMyAdmin instance, by having one extra authentication, follow the guide below for phpMyAdmin.