Step By Step Install Nginx And Phpmyadmin On Ubuntu


Step By Step Install Nginx And Phpmyadmin On Ubuntu

Introduction

Setting up a web server on Ubuntu is easy and straightforward. Nginx is a popular web server for Ubuntu, and it can be used for hosting websites, running web applications, and managing databases. Additionally, phpMyAdmin is a widely used web-based database management system. Nginx and phpMyAdmin are both available in Ubuntu’s repositories, which makes installation and set-up relatively easy. In this article, we’ll install Nginx and phpMyAdmin on Ubuntu 18.04.

Prerequisites

Before you begin, you will need the following:

  • A server running Ubuntu 18.04.
  • A user with sudo privileges.

Step 1 – Installing Nginx

Nginx is available in Ubuntu’s repositories, so we can install it using apt. To do this, connect to your server via SSH and update your package list with the command:


sudo apt update

Now, you can install Nginx with:


sudo apt install nginx

Once installed, you should see the output below:


Output
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
...
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
...
Nginx is being configured
Setting up nginx (1.14.0-0ubuntu1.2) ...

When the installation completes, you can check if the service is running with the command:


sudo systemctl status nginx

You should see something similar to the following output, which indicates that Nginx is running:


Output
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2018-04-10 17:10:09 UTC; 8min ago
Docs: man:nginx(8)
Main PID: 3165 (nginx)
Tasks: 2 (limit: 1153)
CGroup: /system.slice/nginx.service
├─3165 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─3166 nginx: worker process

Apr 10 17:10:08 ubuntu1804 systemd[1]: Starting A high performance web server and a reverse proxy server...
Apr 10 17:10:09 ubuntu1804 systemd[1]: Started A high performance web server and a reverse proxy server.

You can also verify that Nginx is running by accessing the IP address of your server in a web browser. You should see a welcome page, which looks like this:

Step 2 – Installing phpMyAdmin

Now we can install phpMyAdmin. First, we need to add the repository:


sudo add-apt-repository ppa:ondrej/php

When prompted, press ENTER to continue. Now, we can update our packages and install phpMyAdmin with the command:


sudo apt update
sudo apt install phpmyadmin

You will be asked a few questions during the installation. For the webserver selection, select apache2.

You’ll also be asked to configure a database for phpMyAdmin to use. Select yes, and then choose a password for the phpMyAdmin user. Make sure to remember this password. When you’ve finished, press OK.

Once it’s installed, you can access phpMyAdmin in a web browser. You’ll be asked to sign in with the user and password you just created. When you log in, you’ll see the phpMyAdmin dashboard.

Step 3 – Configuring Nginx

Now that Nginx and phpMyAdmin are both installed, we can configure Nginx to serve phpMyAdmin. First, we need to create a configuration file in the sites-available directory.


sudo nano /etc/nginx/sites-available/phpmyadmin

Add the following lines to the file:


server {
listen 80;
server_name the_domain_or_IP;

location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass unix:/run/php/php7.2-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|txt))$ {
root /usr/share/;
}
}
}

Save the file, exit the text editor, and activate the configuration with the command:


sudo ln -s /etc/nginx/sites-available/phpmyadmin /etc/nginx/sites-enabled/

You can verify the configuration syntax with:


sudo nginx -t

If it’s valid, you should see the output below:


Output
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Finally, restart Nginx for the changes to take effect:


sudo systemctl restart nginx

Now, you can access phpMyAdmin in a web browser. You will be asked to log in with the user and password you created during installation.

Conclusion

We’ve successfully installed and configured Nginx and phpMyAdmin on Ubuntu 18.04. You should now have a basic web server that you can use to serve websites and web applications. Good job!

FAQs

Q: What is Nginx?

A: Nginx is a popular high performance web server used by websites and applications.

Q: What is phpMyAdmin?

A: phpMyAdmin is a web-based database management system used for managing MySQL and MariaDB databases.

Q: What is the default port for Nginx?

A: The default port for Nginx is port 80.

Q: How can I access phpMyAdmin?

A: You can access phpMyAdmin in a web browser by navigating to http://your-server-IP/phpmyadmin.

Thank you for reading this article. For more information please visit our other articles.

Leave a Reply

Your email address will not be published. Required fields are marked *