A complete tutorial of ngnix server configuration in ubuntu 22.04

1. Overview

Nginx is an open-source web server that is often used as a reverse proxy or HTTP cache. It is available for Linux for free.

In this tutorial, we’ll install Nginx and set up a basic site.

What you’ll learn

  • How to set up Nginx
  • PHP installation
  • Mysql Installation
  • Basic Mysql configuration
  • Firewall install and configuration
  • Website demo hosting

Setup Nginx

To install Nginx, use following command:

sudo apt update
sudo apt install nginx

PHP installation

To run PHP 8.2 on Ubuntu 22.04, we need to add Ondrej sury PPA into our system. This is the maintainer of the PHP repository at the moment. This PPA is not currently checked so installing from it will not be guaranteed 100% results.

To add this PPA use the following command on our terminal.

sudo add-apt-repository ppa:ondrej/php
After installation is complete we need to update the repositories again for the changes to take effect.

sudo apt update
Install PHP 8.2 on Ubuntu 22.04
We should now be able to install PHP 8.2 on Ubuntu 22.04 Linux machine. The commands to run are as shared below:

sudo apt install php8.2 -y
Check for the currently active version of PHP with the following command:

php –version

MYsqL server install and configuration

To install it, update the package index on your server if you’ve not done so recently:

Then install the mysql-server package:
sudo apt install mysql-server
Ensure that the server is running using the systemctl start command:
sudo systemctl start mysql.service

Then run mysql secure command:

These commands will install and start MySQL, but will not prompt you to set a password or make any other configuration changes. Because this leaves your installation of MySQL insecure, we will address this next.

First, open up the MySQL prompt:

mysql -u root -p

Then go back to using the default authentication method using this command:

ALTER USER ‘root’@’localhost’ IDENTIFIED WITH auth_socket;
This will mean that you can once again connect to MySQL as your root user using the sudo mysql command.

Run the security script with sudo:

sudo mysql_secure_installation

This will take you through a series of prompts where you can make some changes to your MySQL installation’s security options. The first prompt will ask whether you’d like to set up the Validate Password Plugin, which can be used to test the password strength of new MySQL users before deeming them valid.

Database Installation command: 

mysql> CREATE DATABASE wpdb;
mysql> CREATE USER ‘wpuser’@’localhost’ IDENTIFIED BY ‘BNlerp4@38%4o^G7’;
mysql> GRANT ALL ON wpdb.* TO ‘wpuser’@’localhost’;
mysql> FLUSH PRIVILEGES;
mysql> EXIT;

Another basic command of mysql database;

SHOW DATABASES;
systemctl status mysql.service
mysql -v

Leave a Comment

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

Scroll to Top