Friday, October 21, 2022

Installing PHP 8.1 to Add PHP support to Nginx on Ubuntu

 Install PHP for Nginx with PHP-FPM:

sudo apt update

sudo apt install --no-install-recommends php8.1 [Apache HTTP server and its httpd process]

sudo apt-get install php8.1-fpm -y [For PHP-FPM works with nginx]

php -v

sudo apt-get install -y php8.1-cli php8.1-common php8.1-mysql php8.1-zip php8.1-gd php8.1-mbstring php8.1-curl php8.1-xml php8.1-bcmath php8.1-imap

php -m


Check if PHP-FPM is running:

sudo systemctl status php8.1-fpm

Add PHP support to Nginx:

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

Enable PHP in Nginx’s config file:

server {

  # Example PHP Nginx FPM config file

  listen 80 default_server;

  listen [::]:80 default_server;

  root /var/www/html;

  # Add index.php to setup Nginx, PHP & PHP-FPM config

  index index.php index.html index.htm index.nginx-debian.html;

  server_name _;

  location / {

    try_files $uri $uri/ =404;

  }

  # pass PHP scripts on Nginx to FastCGI (PHP-FPM) server

  location ~ \.php$ {

    include snippets/fastcgi-php.conf;


    # Nginx php-fpm sock config:

    fastcgi_pass unix:/run/php/php8.1-fpm.sock;

    # Nginx php-cgi config :

    # Nginx PHP fastcgi_pass 127.0.0.1:9000;

  }

  # deny access to Apache .htaccess on Nginx with PHP, 

  # if Apache and Nginx document roots concur

  location ~ /\.ht {

    deny all;

  }

} # End of PHP FPM Nginx config example

sudo nginx -t

sudo systemctl restart nginx

How to install MySQL on Ubuntu 22.04

 Installing MySQL:

sudo apt update

sudo apt install mysql-server

sudo systemctl start mysql.service


Configuring MySQL:

sudo mysql_secure_installation



Creating a Dedicated MySQL User and Granting Privileges:

  sudo mysql

 mysql -u root -p

 CREATE USER 'mailapp'@'localhost' IDENTIFIED WITH authentication_plugin BY 'password';

 CREATE USER 'mailapp'@'localhost' IDENTIFIED BY 'password';

 CREATE USER 'mailapp'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

 ALTER USER 'mailapp'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

 GRANT CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, SELECT on *.* TO 'mailapp'@'localhost' WITH GRANT OPTION;

 GRANT ALL PRIVILEGES ON *.* TO 'mailapp'@'localhost' WITH GRANT OPTION;

 FLUSH PRIVILEGES;

 exit

 

 mysql -u mailapp -p

How To Make secured Nginx with Let's Encrypt on Ubuntu

 Installing Certbot:

sudo apt install certbot python3-certbot-nginx

Confirming Nginx’s Configuration:

sudo nano /etc/nginx/sites-available/example.com

sudo nginx -t

sudo systemctl reload 


Allowing HTTPS Through the Firewall:

sudo ufw status

sudo ufw allow 'Nginx Full'

sudo ufw delete allow 'Nginx HTTP'

sudo ufw status


Obtaining an SSL Certificate:

sudo certbot --nginx -d example.com -d www.example.com



 Verifying Certbot Auto-Renewal:

 sudo systemctl status certbot.timer

 sudo certbot renew --dry-run

Monday, September 26, 2022

How to change Folder and File Permission in Linux


sudo find /var/www/html -type d -exec chmod 755 {} \;

sudo find /var/www/html -type f -exec chmod 644 {} \;

sudo chmod 644 /var/www/html/textbook.php

sudo chmod 644 /var/www/html/textbook.php


sudo systemctl restart httpd

Wednesday, September 21, 2022

Debian/Ubuntu Linux Specific Commands to Start/Stop/Restart Apache Engine

Debian Linux version 7.x or Ubuntu Linux version Ubuntu 14.10 or older:
Restart:
/etc/init.d/apache2 restart

sudo /etc/init.d/apache2 restart

sudo service apache2 restart

Stop
/etc/init.d/apache2 stop

sudo /etc/init.d/apache2 stop

sudo service apache2 stop

/etc/init.d/apache2 start

sudo /etc/init.d/apache2 start

sudo service apache2 start

Debian Linux version 8.x+ or Ubuntu Linux version Ubuntu 15.04+ or above:

sudo systemctl start apache2.service

sudo systemctl stop apache2.service

sudo systemctl restart apache2.service

sudo systemctl status apache2.service

CentOS/RHEL (Red Hat) Linux version 4.x/5.x/6.x:

## Start ##
service httpd start
## Stop ##
service httpd stop
## Restart ##
service httpd restart

CentOS/Fedora/RHEL (Red Hat) Linux version 7.x or newer:

## Start command ##
sudo systemctl start httpd.service
## Stop command ##
sudo systemctl stop httpd.service
## Restart command ##
sudo systemctl restart httpd.service

Alpine Linux:

service apache2 start
service apache2 stop
service apache2 status
service apache2 restart


Tuesday, September 20, 2022

Two-Factor Authentication (2FA) for Webmin with Google Authenticator

First install Perl Modules :
https://blog.olineit.com/2022/09/install-perl-cpan-module-in-centos-8.html

Then follow the instructions as given through the URL:
https://devtutorial.io/how-to-install-two-factor-authentication-2fa-for-webmin-p2845.html

Install Perl CPAN Module in CentOS 8

dnf install perl-CPAN

dnf install "@Development Tools"

perl -MCPAN -e 'install Authen::OATH'


cpan -i Geo::IP OR 
cpan Geo::IP


cpan 
cpan[1]> install Log::Log4perl

OR

You need gcc.:
yum install gcc

Get CPAN:
yum install CPAN

Configure CPAN ( just run CPAN ):
CPAN

After CPAN is configured:
install Authen::OATH [module in CPAN shell, which takes a long time to complete.]

When Authen::OATH is successfully installed, configure 2FA in WebMin.

Office 2021 Activation using command

  @echo off title Activate Microsoft Office 2021 (ALL versions) for FREE - office.com&cls&echo =====================================...