Dijamin berhasil Install nginx server, phpmyadmin di ubuntu 18 - Step 2

Installing phpMyAdmin for Nginx on 

Ubuntu 18.04


Sumber : https://devanswers.co/installing-phpmyadmin-nginx-ubuntu-18-04/


Last updated on 
In this guide we will install and configure phpMyAdmin to work with Nginx on Ubuntu Server 18.04 LTS (Bionic Beaver). phpMyAdmin is open source free software, designed to handle the administration and management of MySQL databases through a graphic user interface. Written in PHP, PHPMyAdmin has become one of the most popular web-based MySQL management tools.

Prerequisites

You should be using a non-root user with sudo privileges as explained in Ubuntu 18.04 Initial Server Setup.
You should also have your LEMP stack (Nginx, MySQL and PHP) already installed before continuing with this guide. If you don’t have these installed yet, please see Installing a LEMP Stack (Nginx, MySQL, PHP) on Ubuntu 18.04.

1. Install phpMyAdmin

Let’s begin by updating the package lists and installing phpMyAdmin on Ubuntu 18.04. Below we have two commands separated by &&. The first command will update the package lists to ensure you get the latest version and dependencies for phpMyAdmin . The second command will then download and install phpMyAdmin. Press y and ENTER when asked to continue.
sudo apt update && sudo apt install phpmyadmin
The order of the following screens in the phpMyAdmin Package configuration may vary depending on your setup.
If you are prompted to choose a web server like below, as there is no option for Nginx, press TAB and then ENTER to continue without selecting a web server.
Select Yes and press ENTER to install and configure the database.
The MySQL application password is only used internally by phpMyAdmin to communicate with MySQL. You can leave this blank and a password will be generated automatically. Just press ENTER to continue.
In order for Nginx to serve the phpMyAdmin files correctly, we must create a symbolic link from the phpMyAdmin directory /usr/share/phpmyadmin to the Nginx document root directory.
The default location of the Nginx document root in Ubuntu 18.04 should be /var/www/html/, though it could be different depending on your setup. If you followed a previous guide for setting up multiple domains for Nginx, your document root may be located in somewhere like /var/www/example.com/public_html.
Once you have confirmed your document root, let’s create a symbolic link from the phpMyAdmin directory to your document root. Here we will assume your document root is /var/www/html/ and we will simply add phpmyadmin to the end of it. This will allow us to access phpMyAdmin at example.com/phpmyadmin.
sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin

3. Test phpMyAdmin

You should now be able to access the phpMyAdmin web interface by visiting your server’s domain name or public IP address followed by /phpmyadmin. e.g. http://example.com/phpmyadmin or http://192.168.1.10/phpmyadmin
If you don’t have a domain name yet and don’t know your IP, you can find out with:
ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'
You will have set up the root user and password when installing MySQL for the first time. However, remote login might be disabled for root. If you get an error  “Access denied for user ‘root’@’localhost'”, you should continue to Step 4 to create a superuser just for phpMyAdmin.

4. Create MySQL User

If you weren’t able to log in as root above, you can now create a superuser account just for phpMyAdmin.
In terminal, log into MySQL as root. You may have created a root password when you installed MySQL for the first time or the password could be blank, in which case you can just press ENTER when prompted for a password.
sudo mysql -p -u root
Now add a new MySQL user with the username of your choice. In this example we are calling it pmauser (php my admin user). Make sure to replace  password_here with your own (generate a password).
The % symbol tells MySQL to allow this user to log in from anywhere remotely. If you want heightened security, you could replace this with an IP address.
CREATE USER 'pmauser'@'%' IDENTIFIED BY 'password_here';
Now we will grant superuser privileges to our new user pmauser.
GRANT ALL PRIVILEGES ON *.* TO 'pmauser'@'%' WITH GRANT OPTION;
You should now be able to access phpMyAdmin using this new user account.
If you would like to set up some additional security for phpMyAdmin, continue to the next step.

5. Obscure phpMyAdmin URL

Bots and attackers continuously scan web servers for the phpMyAdmin login page, so it is recommended that you change the URL to something else.
In this example we are going to change it from example.com/phpmyadmin to example.com/pma_hidden, though you can change it to whatever you want.
In step 2, we created a symbolic link in the document root /var/www/html/phpmyadmin
All we need to do is to rename this symbolic link, in this example, to: pma_hidden. Make sure you enter the correct document root here. The default is /var/www/html though it may be something like /var/www/example.com/public_html/ on your server.
sudo mv /var/www/html/phpmyadmin /var/www/html/pma_hidden
You should now be able to access phpMyAdmin at example.com/pma_hidden

6. Secure phpMyAdmin (Optional)

To provide an additional layer of security, we can set up authentication in Nginx.
Firstly, generate a strong password and keep it safe.
We will now install apache2-utils, which can generate the .htpasswd file that works with both Nginx and Apache.
sudo apt install apache2-utils
Once installed, we can generate the .htpasswd file. Simply change username to whatever username you want. Generate a password and keep it safe.
sudo htpasswd -c /etc/nginx/.htpasswd username
There should now be a .htpasswd file containing your username and encrypted password. You can check with:
cat /etc/nginx/.htpasswd
You should see something like username:$apr1sdfsdf4435sdtskLfWmmg1sfdsdgg4
We now need to add two directives to our Nginx configuration file. The location of the config file may vary depending on your setup, though the default is usually in /etc/nginx/sites-available/default. If you set up multiple domains in a previous guide, your config file may be located in somewhere like /etc/nginx/sites-available/example.com
This this example, we will assume the config file is in /etc/nginx/sites-available/default. Open the file to edit.
sudo nano /etc/nginx/sites-available/default
Scroll down and look for the location block and paste in a new block underneath it with the name of your obscured phpMyAdmin folder, in this example pma_hidden. (Use the right mouse button to paste if using PuTTY for Windows)
/etc/nginx/sites-available/default
location /pma_hidden {
        auth_basic "Restricted Access";
        auth_basic_user_file /etc/nginx/.htpasswd;
}
Save file and exit (press CTRL + X, press Y and then press ENTER).
Check that the Nginx config file is valid, otherwise the server could crash on restart.
sudo nginx -t
If valid, reload Nginx config.
sudo service nginx reload
Now when visiting example.com/pma_hidden, you should be presented with an authentication window.
You’re all done!

0 Response to "Dijamin berhasil Install nginx server, phpmyadmin di ubuntu 18 - Step 2"

Post a Comment