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
Then, install Nginx:
sudo apt install nginx
Verify the installation:
nginx -v
Check Nginx's status:
sudo systemctl status nginx
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
Change Listen 80
to Listen 8080
. Then, edit the Apache virtual host configuration:
sudo nano /etc/apache2/sites-available/000-default.conf
Change port 80 to 8080 within the <VirtualHost>
block. Finally, restart both servers:
sudo systemctl restart apache2 sudo systemctl restart nginx
Now, Apache will be accessible at localhost:8080
and Nginx at localhost
. Verification can be done via browser or curl
.
Installing MariaDB:
Install MariaDB (or MySQL):
sudo apt install mariadb-server mariadb-client
Verify the MariaDB version:
mariadb --version
Installing phpMyAdmin:
Install phpMyAdmin:
sudo apt install phpmyadmin
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.
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
Configuring Nginx for phpMyAdmin:
Configure Nginx to serve phpMyAdmin. Edit the default Nginx site configuration:
sudo nano /etc/nginx/sites-available/default
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/; } }
Reload Nginx configuration:
sudo systemctl reload nginx
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!