Install Nginx, PHP, MySQL (Mariadb) on Ubuntu

-Would you be kind to me in which direction to go?
-In the famous you, – replied the cat.
-I don’t know it.
-So, in the unknown. In any case, it is known that in a known time you will find yourself therrre or herrre,-purring cat.

Nginx Installation:

apt update
apt install nginx

Installing PHP and the MariaDB driver

apt install php-fpm php-mysqlnd php-xml

Creating Virtual Domains

mkdir /var/www/domain.com
chmod -R 755 /var/www/domain.com

In the /etc/nginx/sites-available directory, we create a domain.com.conf file

The contents of the domain.com.conf file

server {
     listen 80;
     server_name domain.com;

     root /var/www/domain.com;

     # Add index.php to the list if you are using PHP
     index index.php index.html index.htm index.nginx-debian.html;
 
     server_name domain.com;
 
    location / {
               try_files $uri $uri/ =404;
               if (!-e $request_filename) {
                  rewrite ^.+/?(/wp-.*) $1 last;
            rewrite ^.+/?(/.*\.php)$ $1 last;
                  rewrite ^(.+)$ /index.php?q=$1 last;
      }
}

location ~ \.php$ {
               include snippets/fastcgi-php.conf;
               fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
       }
}

Now you need to reboot the Webserver

service nginx restart

Checking PHP work

In /var/www/domain.com , we will create the index.php file and write in it:

<?php phpinfo(); ?>

Next, open your website in the browser, in the example we use domain.com and if everything is done correctly, we see this picture:

Install MARIADB

sudo apt install mariadb-server mariadb-client

Security settings

mysql_secure_installation

Answer the questions:

Create a database and a user.

Entering the MARIADB:

mysql -u root

If you set the password to root:

mysql -u root -p
CREATE DATABASE domaindb;
CREATE USER 'nameus'@'localhost' IDENTIFIED BY 'user_password';

For the user_password place, enter the user password.

GRANT ALL ON domaindb. * to nameus @ localhost;
Quit

Deploying WordPress

cd /var/www/domain.com
curl -O https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
mv wordpress/* .
rmdir wordpress
chown -R www-data:www-data /var/www/domain.com
chmod -R 755 /var/www/domain.com

How to configure SSH without a password with a key pair in Ubuntu

Create a key pair, leave all values by default:

ssh-keygen

In the console, enter a command that configures the server so that you can sign in with an SSH key:

 ssh-copy-id -i .ssh/id_rsa.pub [email protected] 

Instead of127.0.0.1, specify the IP server.

Take the private key id_rsa rename the extension in PPK, winscp add to the connection SSH authentication and it will offer to convert the file to Putty format and save a new key. and add a new key to the connection, try to connect.

Edit the Sshd_config file

mcedit /etc/ssh/sshd_config

Add the PasswordAuthentication no instruction

Immediately you can change the standard access port, the Port 22  instruction, for example, write Port 4321, now access to SSH will be on port 4321.

Reboot ssh to apply config changes:

systemctl restart ssh

Now when you try to log in by password, we get a window with an error:

Attach a private key to the connection and the task is solved.

Complete removal of postfix, SpamAssassin and Dovecot in Ubuntu

You will not have time to be attached to any pleasant, calm place, and already some voice makes you stand up and retire from it, as the hour of rest has passed.
–Charlotte Bronte. Jane Eyre–Edward Rochester

In case you need to reinstall postfix, spamassassin and dovecot in ubuntu, first remove:

apt-get --purge remove postfix postfix-mysql spamassassin dovecot-core dovecot-common dovecot-imapd dovecot-pop3d