Home Top Ad

How To Install phpMyAdmin on Ubuntu 18.04 (LEMP)

Share:





Prerequisites





Before you get started with this guide, you need to have some basic steps completed.





First, we’ll assume that your server has a non-root user with sudo privileges, as well as a firewall configured with ufw, as described in the initial server setup guide for Ubuntu 18.04.





We’re also going to assume that you’ve completed a LEMP (Linux, NGINX, MySQL, and PHP) installation on your Ubuntu 18.04 server. If this is not completed yet, you can follow this guide on installing a LAMP stack on Ubuntu 18.04.





Finally, there are important security considerations when using software like phpMyAdmin, since it:





  • Communicates directly with your MySQL installation
  • Handles authentication using MySQL credentials
  • Executes and returns results for arbitrary SQL queries




For these reasons, and because it is a widely-deployed PHP application which is frequently targeted for attack, you should never run phpMyAdmin on remote systems over a plain HTTP connection. If you do not have an existing domain configured with an SSL/TLS certificate





Once you are finished with these steps, you’re ready to get started with this guide.





Step 1 — Installing phpMyAdmin





sudo apt install phpmyadmin -y





In order to run phpmyadmin under the Nginx web server, we need
to add the configuration to the virtual host configuration file.





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





Paste the following Nginx configuration for phpmyadmin
inside the 'server {…}' bracket.





location /phpmyadmin {
root /usr/share/;
index index.php;
try_files $uri $uri/ =404;





location ~ ^/phpmyadmin/(doc|sql|setup)/ {
deny all;
}





location ~ /phpmyadmin/(.+.php)$ {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include snippets/fastcgi-php.conf;
}
}





nginx -t
systemctl reload nginx