Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to 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.
Nginx is a better choice for a server to serve websites. It is known for its efficiency and capacity to handle large traffic. Nginx can also work as a reverse proxy and load balancer. The pronunciation of the word "Nginx" is like this: engine-x.
phpMyAdmin is 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.
Prerequisites: Ubuntu server with sudo privileges and internet connection.
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
Resolving Port Conflicts with Apache
If you're running Apache alongside Nginx, both servers use port 80 by default, causing conflicts. To fix this, we need to change Apache to use a different port.
Let's change the port for the Apache server from 80 to 8080. Edit the ports configuration file
sudo nano /etc/apache2/ports.conf
Change the port from 80 to 8080.
Next, edit the virtual host configuration
sudo nano /etc/apache2/sites-available/000-default.conf
Change the VirtualHost directive to
<VirtualHost *:8080>
Finally, restart both servers
sudo systemctl restart apache2 sudo systemctl restart nginx
Now you can access:
- localhost:8080 for Apache server
- localhost for Nginx server
Install Database Server
Before installing phpMyAdmin, you need to install a database server. We'll use MariaDB
sudo apt install mariadb-server mariadb-client
Verify the installation
mariadb --version
Install PHP
phpMyAdmin requires PHP to function. Install PHP and required extensions
sudo apt install php-fpm php-mysql php-json php-curl php-mbstring php-xml php-zip -y
Install phpMyAdmin
Install phpMyAdmin using the package manager
sudo apt install phpmyadmin
During installation, you'll encounter configuration prompts:
- When asked to choose a web server, select [Yes] to skip (Nginx isn't listed)
- When asked to use dbconfig-common, select [Yes]
- Enter a password for the phpMyAdmin database
- Confirm the password
Configure Nginx for phpMyAdmin
Configure Nginx to serve phpMyAdmin by editing the default site configuration
sudo nano /etc/nginx/sites-available/default
Add the following location block inside the server block
location /phpmyadmin {
root /usr/share/;
index index.php;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
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/;
}
}
Note: Replace php8.1-fpm.sock with your PHP version. Check available versions with ls /run/php/.
Test the Nginx configuration
sudo nginx -t
If the test is successful, reload Nginx
sudo systemctl reload nginx
Access phpMyAdmin
Navigate to http://localhost/phpmyadmin in your browser to access the phpMyAdmin interface. Use your MariaDB credentials to log in.
Conclusion
You have successfully installed and configured phpMyAdmin with Nginx on Ubuntu. This setup provides a web-based interface for managing MySQL/MariaDB databases efficiently. Remember to secure your installation by configuring proper authentication and access controls for production environments.
