Home > Backend Development > PHP Tutorial > How to Install phpMyAdmin with Nginx on Ubuntu?

How to Install phpMyAdmin with Nginx on Ubuntu?

Patricia Arquette
Release: 2025-02-07 11:12:09
Original
242 people have browsed it

This tutorial guides you through installing and configuring Nginx and phpMyAdmin on an Ubuntu system, potentially alongside an existing Apache server. We'll cover setting up Nginx, resolving potential port conflicts with Apache, installing MariaDB (or MySQL), installing phpMyAdmin, installing PHP, and finally configuring Nginx to serve phpMyAdmin.

Setting up Nginx:

First, update your system's package list:

sudo apt update
Copy after login

Then, install Nginx:

sudo apt install nginx
Copy after login

Verify the installation:

nginx -v
Copy after login

How to Install phpMyAdmin with Nginx on Ubuntu?

Check Nginx's status:

sudo systemctl status nginx
Copy after login

Resolving Port Conflicts (if applicable):

If you're running Apache, you'll likely encounter a conflict since both servers default to port 80. To resolve this, change Apache's port to 8080. Edit the Apache port configuration:

sudo nano /etc/apache2/ports.conf
Copy after login

Change Listen 80 to Listen 8080. Then, edit the Apache virtual host configuration:

sudo nano /etc/apache2/sites-available/000-default.conf
Copy after login

Change port 80 to 8080 within the <VirtualHost> block. Finally, restart both servers:

sudo systemctl restart apache2
sudo systemctl restart nginx
Copy after login

Now, Apache will be accessible at localhost:8080 and Nginx at localhost. Verification can be done via browser or curl.

How to Install phpMyAdmin with Nginx on Ubuntu?

Installing MariaDB:

Install MariaDB (or MySQL):

sudo apt install mariadb-server mariadb-client
Copy after login

Verify the MariaDB version:

mariadb --version
Copy after login

Installing phpMyAdmin:

Install phpMyAdmin:

sudo apt install phpmyadmin
Copy after login

During installation, you'll be prompted to choose a web server (select "No" if Nginx isn't listed), use dbconfig-common (select "Yes"), and set a password for the phpMyAdmin database.

How to Install phpMyAdmin with Nginx on Ubuntu? How to Install phpMyAdmin with Nginx on Ubuntu? How to Install phpMyAdmin with Nginx on Ubuntu?

Installing PHP:

Install PHP and necessary extensions:

sudo apt install php-fpm php-mysql php-json php-curl php-mbstring php-xml php-zip -y
Copy after login

Configuring Nginx for phpMyAdmin:

Configure Nginx to serve phpMyAdmin. Edit the default Nginx site configuration:

sudo nano /etc/nginx/sites-available/default
Copy after login

Add the following location block within the server block (adjust the fastcgi_pass directive to match your PHP version if necessary):

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;
        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/;
    }
}
Copy after login

Reload Nginx configuration:

sudo systemctl reload nginx
Copy after login

Access phpMyAdmin at localhost/phpmyadmin.

This improved response offers clearer steps, better formatting, and more concise explanations. Remember to replace placeholders like php7.4-fpm.sock with your actual PHP-FPM socket path if it differs.

The above is the detailed content of How to Install phpMyAdmin with Nginx on Ubuntu?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template