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

How to Install phpMyAdmin with Nginx on Ubuntu?

Patricia Arquette
Patricia ArquetteOriginal
2025-02-07 11:12:09275browse

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:

<code class="language-bash">sudo apt update</code>

Then, install Nginx:

<code class="language-bash">sudo apt install nginx</code>

Verify the installation:

<code class="language-bash">nginx -v</code>

How to Install phpMyAdmin with Nginx on Ubuntu?

Check Nginx's status:

<code class="language-bash">sudo systemctl status nginx</code>

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:

<code class="language-bash">sudo nano /etc/apache2/ports.conf</code>

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

<code class="language-bash">sudo nano /etc/apache2/sites-available/000-default.conf</code>

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

<code class="language-bash">sudo systemctl restart apache2
sudo systemctl restart nginx</code>

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):

<code class="language-bash">sudo apt install mariadb-server mariadb-client</code>

Verify the MariaDB version:

<code class="language-bash">mariadb --version</code>

Installing phpMyAdmin:

Install phpMyAdmin:

<code class="language-bash">sudo apt install phpmyadmin</code>

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:

<code class="language-bash">sudo apt install php-fpm php-mysql php-json php-curl php-mbstring php-xml php-zip -y</code>

Configuring Nginx for phpMyAdmin:

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

<code class="language-bash">sudo nano /etc/nginx/sites-available/default</code>

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

<code class="language-nginx">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/;
    }
}</code>

Reload Nginx configuration:

<code class="language-bash">sudo systemctl reload nginx</code>

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!

Statement:
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