Introduction
While many users need the functionality of a database management system like MySQL, they may not feel comfortable interacting with the system solely from the MySQL prompt.
phpMyAdmin was created so that users can interact with MySQL through a web interface. In this guide, we’ll discuss how to install and secure phpMyAdmin so that you can safely use it to manage your databases from an Ubuntu 16.04 system.
Prerequisites
It is assumed that you have already installed LEMP stack on Ubuntu 16.04. If not, please check out the following tutorial. How to Install a LEMP (Linux, Nginx, MySQL, PHP) Stack on Ubuntu 16.04
Once you are finished with these steps, you’re ready to get started with this guide.
Step One — Install phpMyAdmin/4.5.4
To get started, we can simply install phpMyAdmin from the default Ubuntu repositories.
We can do this by updating our local package index and then using the apt
packaging system to pull down the files and install them on our system:
1 |
sudo apt-get install phpmyadmin php7.0-zip php7.0-bz2 |
Once done, a new database named phpmyadmin is created and the database user phpmyadmin has necessary privileges to manage this database.
Step Two — Configure Nginx
To be able to access the phpMyAdmin web interface, we need to configure Nginx. We will configure Nginx so that phpMyAdmin is a sub-directory of the existing website. Open the default Nginx server block configuration file.
1 |
sudo nano /etc/nginx/sites-available/default |
Add the following lines in the server
section.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
location /phpmyadmin { root /usr/share/; index index.php index.html index.htm; location ~ ^/phpmyadmin/(.+\.php)$ { try_files $uri =404; fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ { root /usr/share/; } } |
Your phpMyAdmin files are in /usr/share/phpmyadmin/
directory. The above configuration tells Nginx that if visitors enter your-domain.com/phpmyadmin in browser address bar, then find index.php file in /usr/share/phpmyadmin/
directory and display the web page.
Save and close the file. Then test configuration and reload.
1 2 |
sudo nginx -t sudo systemctl reload nginx |
Now you should be able to access phpMyAdmin web interface via
1 |
your-domain.com/phpmyadmin/ |
Using PhpMyAdmin as your development interface and keep getting logout after +-24 minutes? That is PhpMyAdmin default security policy, if you are not getting active or browsing on the browser for more than 1440 seconds, you will be logged out with the message “No activity within 1440 seconds; please log in again.”
Here is how to extend the session timeout to longer period;
- Settings > Features > Change the value of Login cookie validity > Save
- Open the default Nginx server block configuration file.
1sudo nano /etc/nginx/sites-available/default
Add the following lines in the
location /phpmyadmin
section.1fastcgi_param PHP_VALUE "session.gc_maxlifetime = 43200";the Nginx default server block file looks like this:
123456789101112131415location /phpmyadmin {root /usr/share/;index index.php index.html index.htm;location ~ ^/phpmyadmin/(.+\.php)$ {try_files $uri =404;fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;include fastcgi_params;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;fastcgi_param PHP_VALUE "session.gc_maxlifetime = 43200";}location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {root /usr/share/;}}Save and close the file. Then test configuration and reload.
12sudo nginx -tsudo systemctl reload nginx - Open PhpMyAdmin.
That’s it!
I hope this article helped you to install phpMyAdmin with Nginx on Ubuntu 16.04.
How to Install a LEMP (Linux, Nginx, MySQL, PHP) Stack on Ubuntu 16.04
Source: