
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Install phpMyAdmin with Nginx on Ubuntu
When you try to build a website for production or just start learning web development, you need a server to make your web application accessible from the browser to other users, either to use it or test its functionality.
The web server is an interesting part of any web application that involves backend tasks.
Nginx is a better choice for a server to serve websites. It is known for its efficiency and capacity to handle large traffic. Perhaps as a server, Nginx can also work as a reverse proxy and load balancer. The pronunciation of the word "Nginx" is like this:engine-x.
To manage an SQL database, you need to be familiar with the SQL language to manage a database. Using an application that helps manage a database can boost productivity and make database usage simple, even for someone who doesn't know SQL queries.
phpMyAdmin is just a web interface to manage MySQL and MariaDB databases. It allows us to create databases, tables, and users. Do not confuse it with the actual database server, which could be MySQL or MariaDB, and needs to be installed before the web interface.
In this tutorial, we will go through the process and steps required to get phpMyAdmin and Nginx installed and running on Ubuntu.
Install Nginx
Nginx can be installed on Ubuntu easily. However, if you have Apache already installed on your machine and you want them both to act as servers, this requires some changes in the configuration to avoid conflicts.
To install Nginx, first, update the system ?
sudo apt update
Next, get the Nginx server using the command ?
sudo apt install nginx
After the installation is done, we can check the version installed using the command ?
nginx -v
To check the status of the server, whether it's running or not, use the command ?
sudo systemctl status nginx
Now, because I use Apache alongside Nginx, I get this message ?
This problem occurs because the two servers use the same port to serve web requests. To fix this, we need to make changes for one of them to use a different port.
Let's change the port for the Apache server. Instead of 80, let's use 8080. To do this, we need to edit the following file ?
sudo nano /etc/apache2/ports.conf
Change the port from 80 to 8080.
Next, we need to make changes in the virtual host configuration and update the port as well.
Edit this file ?
sudo nano /etc/apache2/sites-available/000-default.conf
Change the port from 80 to 8080. It will look like this ?
<VirtualHost *:8080>
Finally reloads both servers using these commands ?
sudo systemctl restart apache2 sudo systemctl restart nginx
Now, both servers are running in different ports and we can access them like this ?
- localhost:8080 is for the Apache server
- localhost is for the nginx server
We can verify this by navigating to these endpoints in a browser or using curl in the command line ?
Note: You only need to do this if you want to work with both servers on the same machine, and both of them act as web servers.
Install phpMyAdmin
Before installing phpMyAdmin, you need to install a database server. It could be MariaDB or MySQL.
To install MariaDB, use the command ?
sudo apt install mariadb-server mariadb-client
This will install MariaDB; after the installation, we can verify the installed version using the command ?
mariadb --version
To install phpMyAdmin, simply run the following command:
sudo apt install phpmyadmin
This command will download and install phpMyAdmin with its dependencies. During the installation, it will prompt you to follow some steps to set up the web interface.
The first step will ask you to choose the server. Since we are using Nginx and it's not on the list, just hit [Yes] to skip this.
Next, it will ask to use dbconfig-common to set up the database. Hit [Yes].
The previous command will create a database, and next, it will ask for a password for it. Enter a password of your choice.
Finally, it will ask to confirm the password.
After that, the database setup is complete.
Install PHP
phpMyAdmin is a web application that uses PHP in the backend, so we need to install PHP in order for it to work. If you don't already have PHP installed, use this command
sudo apt install php-fpm php-mysql php-json php-curl php-mbstring php-xml php-zip -y
This will install PHP along with some required dependencies.
Configure Nginx for phpMyAdmin
The last step is to configure Nginx to use phpMyAdmin. First, add a phpMyAdmin block to Nginx by editing the file ?
sudo nano /etc/nginx/sites-available/default
Fill it with the following content ?
server { ... location /phpmyadmin { root /usr/share/; index index.php; location ~ ^/phpmyadmin/(.+\.php)$ { try_files $uri =404; root /usr/share/; fastcgi_pass unix:/run/php/php7.4-fpm.sock; # Replace with your PHP version fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|svg|ttf|woff|woff2|eot))$ { root /usr/share/; } } }
The final step is to reload the configuration ?
sudo systemctl reload nginx
Finally, you just need to navigate to localhost/phpmyadmin to get access to the web interface.
Conclusion
Nginx is a powerful and fast server to learn and practice on. In this article, we set up Nginx with the web interface phpMyAdmin. We did some extra configuration because we installed and used the Apache server alongside Nginx.