How To Install Nginx Maridb 10 On Ubuntu 16.04 Lts


How To Install Nginx Maridb 10 On Ubuntu 16.04 Lts

Step 1 — Installing Nginx

The first step in installing Nginx and MariaDB 10 on Ubuntu 16.04 is installing Nginx. Nginx is a web server and a proxy server for protocols such as HTTP and SMTP. Ubuntu 16.04 comes with Nginx installed by default, but if you want to upgrade to the latest version then you can use the command below to install it.

Run the following command in your terminal to start the installation of Nginx:

sudo apt install nginx

Nginx is now installed and up and running on your system. You can verify it by checking the version with the command:

nginx -v

The output should look something like this:

nginx version: nginx/1.11.10

Step 2 — Installing MariaDB 10

The next step is to install MariaDB 10. MariaDB 10 is a popular drop-in replacement for MySQL. It is a powerful database system that is used by many high traffic websites. To install MariaDB 10 on Ubuntu 16.04, simply run the following command in your terminal:

sudo apt install mariadb-server

Once the installation is complete, you can run the MySQL secure installation command to set up the root password and secure the database:

sudo mysql_secure_installation

You will be asked a few questions such as setting the root password, removing anonymous users, etc. Answer these questions as appropriate for your environment. Once you have set everything up, you can verify that MariaDB is running by typing the following command:

mysql -u root -p

Enter the root password to access the MariaDB console. To view all available databases, type:

show databases;

This should output a list of databases such as:

+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+

Step 3 — Installing phpMyAdmin

phpMyAdmin is a web-based graphical interface for managing MySQL and MariaDB databases. Installing phpMyAdmin on Ubuntu 16.04 is fairly simple. First, you need to install wget if it is not installed on your system by using the command below:

sudo apt install wget

Next, you need to download the latest version of phpMyAdmin from the official website:

wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.tar.gz

Extract the downloaded file with the following command:

tar -xvzf phpMyAdmin-latest-all-languages.tar.gz

This will create a new directory containing phpMyAdmin. Now, you need to move the phpMyAdmin files to the webroot directory as follows:

sudo mv phpMyAdmin-4.7.4-all-languages /var/www/html/phpMyAdmin

You can now access phpMyAdmin from your browser by navigating to http://your-server-ip/phpMyAdmin. You should see the phpMyAdmin login page.

Step 4 — Configuring Nginx

Now we need to configure Nginx to serve the phpMyAdmin files. To do this, first create a new Nginx virtual host configuration file as follows:

sudo nano /etc/nginx/sites-available/phpmyadmin.conf

Paste the following lines into the file. Make sure you replace the server_name with your domain name or the public IP address of the server:

server {
listen 80;
server_name www.example.com;
root /var/www/html/phpmyadmin;

location / {
index index.php index.html index.htm;
}

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

Save and close the file when you are finished. Now, you need to enable the newly created virtual host file by creating a symbolic link from the sites-available directory to the sites-enabled:

sudo ln -s /etc/nginx/sites-available/phpmyadmin.conf /etc/nginx/sites-enabled/phpmyadmin.conf

Now, you need to restart Nginx for the changes to take effect:

sudo systemctl restart nginx

Step 5 — Securing phpMyAdmin

By default, phpMyAdmin is accessible to any user on the internet. This is a major security risk, so you should always secure your phpMyAdmin installation. The easiest way to do this is by creating an .htaccess file in the phpMyAdmin directory. To do this, run the following command:

sudo nano /var/www/html/phpmyadmin/.htaccess

Then, paste the following lines in the file:

AuthType Basic
AuthName "Restricted Files"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user

Save and close the file. Now, you need to create a .htpasswd file which will store the username and password of the user who will be allowed to access phpMyAdmin. To do this, run the following command:

sudo htpasswd -c /etc/phpmyadmin/.htpasswd username

Replace “username” with the username you want to use. Next, you will be prompted to enter and re-enter a password for the user. After this, you should be able to access phpMyAdmin remotely but only after entering the correct username and password.

Conclusion

In this tutorial, we have seen how to install Nginx and MariaDB 10 on Ubuntu 16.04. We have also seen how to install and configure phpMyAdmin and how to secure it with an .htaccess file.

Thank you for reading this article. Please read other articles.