Showing posts with label CentOS. Show all posts
Showing posts with label CentOS. Show all posts

Sunday, April 7, 2024

How to forward all outbound mail sent from an email account on your centOS server

 

Filters and forwarders that can be managed directly within a cPanel account are only applied to incoming messages. They do not affect outbound messages. To forward outbound messages, you need to create a system filter. This article provides an example of how you can use an Exim system filter in cPanel to forward all outbound mail from an email account. 

Please note that cPanel is not able to provide support for customizing the specific contents of your Exim filters. If you need help crafting a custom filter, you should reach out to a systems administrator with the skills, training, and expertise required to do so for you.

 

Procedure

1.      Access the server's command line as the 'root' user via SSH or "Terminal" in WHM.

2.      Create the filter file.

touch /usr/local/cpanel/etc/exim/sysfilter/options/fowardOutbound.conf

3.      Open the newly created filter file in your preferred text editor.

4.      Add the following to the file.

if ("$h_from:" contains "from@domain.tld")
then
   ## The following will make it so that the original recipient is skipped and
   ## and only recipient@domain.tld will recieve the message
   deliver "recipient@domain.tld"
   ## If you add the word unseen in front, the message will be forwarded to
   ## recipient@domain.tld as well as delivered to the original recipient.
   ## For example, you would remove the above deliver line and replace it with:
   ## unseen deliver "recipient@domain.tld"
endif

For multiple :
if $h_from: contains "user1@domain.com"
or $h_from: contains "user2@domain.com""
or $h_from: contains "user3@domain.com""
then
unseen deliver "user@domain.com"
endif

Please note that 'from@domain.tld' and 'recipient@domain.tld' must be replaced with the sender and recipient email addresses, respectively.

5.      Rebuild the Exim configuration.

/scripts/buildeximconf

Please note that cPanel will copy your custom filter into the system filter file, /etc/cpanel_exim_system_filter.

6.      Restart Exim.

/scripts/restartsrv_exim

 

Monday, January 22, 2024

How to Install and Use PHP Composer on CentOS 7

 sudo yum install php-cli php-zip wget unzip

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

HASH="$(wget -q -O - https://composer.github.io/installer.sig)"

php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer


composer



Sunday, August 13, 2023

Wednesday, April 19, 2023

How to add an additional IP address in Centos 7

Method -1:

Create file /etc/sysconfig/network-scripts/ifcfg-eth0:0 with the following content:

DEVICE=eth0:0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.0.11
NETMASK=255.255.255.255

service network restart

Method-2:

Run the following command
ipadd your_ip

Example: ipadd 192.168.0.1

Thursday, April 6, 2023

Sovled ! Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist

 # sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*

# sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*


or


# sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-Linux-*

# sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-Linux-*

Monday, February 20, 2023

How to Install Nginx, MariaDB, PHP and Create Virtual Server Block with Nginx on AlmaLinux 8

yum install nginx -y
systemctl start nginx
systemctl enable nginx
systemctl status nginx
nginx -v


firewall-cmd --permanent --zone=public --add-service=http 
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
chown nginx:nginx /usr/share/nginx/html -R

################ MariaDB ##############################

yum install mariadb-server mariadb -y
systemctl start mariadb
systemctl enable mariadb
systemctl status mariadb
mysql_secure_installation
mysql -e "SHOW DATABASES;" -p

################ PHP installation ##########################

yum install php php-mysqlnd php-fpm php-opcache php-gd php-xml php-mbstring php-json -y

################### For Specific PHP Version #################
sudo dnf config-manager --set-enabled crb
sudo dnf install epel-release -y
sudo dnf install http://rpms.remirepo.net/enterprise/remi-release-9.rpm
sudo dnf update -y
sudo dnf module list php
sudo dnf -y install yum-utils
sudo dnf module enable php:remi-8.2 -y
########################################################
systemctl start php-fpm

systemctl enable php-fpm

systemctl status php-fpm

vi /etc/php-fpm.d/www.conf

user = nginx
group = nginx

systemctl reload php-fpm

echo "<?php phpinfo() ?>" > /usr/share/nginx/html/info.php

systemctl restart nginx php-fpm
########################################################
            Host File
=====================================================
sudo vi /etc/hosts
IP_ADDRESS mt.baycombd.com
chown nginx:nginx /var/www/example.com/public_html -R
echo "<?php phpinfo() ?>" > /var/www/example.com/public_html/info.php
======================================================
         Custom  Public_html Directory
=====================================================
sudo mkdir -p /var/www/example.com/public_html
sudo chown -R nginx:nginx /var/www/example.com/public_html
sudo chmod -R +x /var/www
sudo chcon -t httpd_sys_content_t /var/www/example.com -R
sudo chcon -t httpd_sys_rw_content_t /var/www/example.com -R
=====================================================
             Create Custom Server Block 
=====================================================
touch /etc/nginx/conf.d/example.com.conf
# Web root location & port listining
server 
{
        listen 80;
        root /var/www/example.com/public_html;
        index index.php index.html index.htm;
        server_name example.com www.example.com;
        access_log /var/www/example.com/access.log;
        error_log /var/www/example.com/error.log;

# Redirect server error pages to the static page
        location / 
{
try_files $uri $uri/ /index.php;
        }
        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
        location = /50x.html 
{
        root /var/www/example.com/public_html;
        }
# Pass the PHP scripts to FastCGI server
location ~ \.php$ 
{
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        try_files $uri =404;
       # fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php-fpm/www.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_index index.php;
        include fastcgi_params;
        }
}      
======================================================
systemctl restart nginx php-fpm
nginx -t

Sunday, February 19, 2023

503 Service Unavailable : PHP-FPM issue

Error: 503 Service Unavailable The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

Solution: 

systemctl start php80-php-fpm (if face the error follow the next command )

systemctl status php80-php-fpm.service

ERROR: unable to bind listening socket for address '127.0.0.1:9000': Address already in use (98)

netstat -tulpn | grep -w 9000 

tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      884/php-fpm: master 

kill 884

systemctl start php80-php-fpm


Note: Use your PHP version, PID and Port in the command. if netstat not works install net-tools first: yum install net-tools

How to Install PHP 8.0/8.1on Linux Centos 7

Method-1 for PHP 8.0

Remi Repository
# yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm

PHP 8.0 install
# yum install -y --enablerepo=remi-php80 php php-cli

Exntesions:
#yum install -y --enablerepo=remi-php80 php-mysqlnd

Method-1 for PHP 8.1

yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum -y install yum-utils
yum-config-manager --disable 'remi-php*'
yum-config-manager --enable remi-php81
yum repolist
yum -y install php php-{cli,fpm,mysqlnd,zip,devel,gd,mbstring,curl,xml,pear,bcmath,json,opcache,redis,memcache}

Thursday, February 16, 2023

How to Send an email using Telnet in CentOS

sudo apt install telnet

sudo yum install telnet


telnet targetserver.tld 25


HELO sourceserver.tld 

MAIL FROM: username@sourcedomain.tld

RCPT TO: username@example.com

DATA 
Subject: Sending an email using  SMTP through telnet 
Hi, 
This is just a Test Email ? You may disregard this? 

regards;
Mr. Y

.

Note: We can start writing some subject and body. To do that we need to use the DATA command. First type DATA followed by Subject: and the body. Once done, enter " . "  (without quote)to send the email to be queued.

Wednesday, February 15, 2023

Stop and Disable Firewalld on CentOS 7

sudo firewall-cmd --state

sudo systemctl stop firewalld

sudo systemctl disable firewalld

sudo systemctl mask --now firewalld

Saturday, January 21, 2023

How to Extend Swap Space using Swap file in Linux

dd if=/dev/zero of=/swap_file bs=1G count=1

sudo fallocate -l 1G /swap_file

chmod 600 /swap_file

mkswap /swap_file

echo "swap_file swap swap defaults 0 0" >> /etc/fstab 
or 
vi /etc/fstab/swap_file swap swap defaults 0 0

swapon /swap_file

Thursday, September 15, 2022

How to remove directory in Linux

 To permanently remove a directory in Linux, use either rmdir or rm command:

  • For empty directories, use rmdir [dirname] or rm -d [dirname]
  • For non-empty directories, use rm -r [dirname]

Before you remove a directory, you need to know the name of it. To discover files and directories, use the ls command, and to know the current directory you are in, use the pwd command.

The options you use together with these commands are also important to determine how they work. Here’s a quick recap of rm command options:

Command and OptionDescription
rm -dRemove an empty directory using the rm command.
rm -rRemove a non-empty directory and its content.
rm -fIgnore any prompt when deleting a write-protected file.
rm -rfIgnore any prompt when deleting a write-protected non-empty folder.
rm -iOutput a prompt before deleting every file.
rm -IOutput a prompt only once before deleting more than three files.
rm *Wildcard that represents multiple characters.
rm ?Wildcard that represents a single character.
rmdir -pRemove an empty subdirectory and its parent directory.
rmdir -vPrint the information that the specified directory was deleted.

Monday, September 12, 2022

Reset MySQL Root Password on Red Hat Enterprise Linux 8

sudo systemctl stop mysqld

sudo systemctl set-environment MYSQLD_OPTS=”--skip-grant-tables”

sudo systemctl start mysqld

sudo mysql -u root

mysql> FLUSH PRIVILEGES;

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewRootPassw0rd!'; 

mysql> FLUSH PRIVILEGES;

mysql> QUIT;

sudo systemctl stop mysqld

sudo systemctl unset-environment MYSQLD_OPTS

sudo systemctl start mysqld

sudo mysql -u root -p

mysql> QUIT;

sudo mysql -u root -p

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'ChangeRootPassw0rd!';

mysql> ALTER USER 'shola'@'localhost' IDENTIFIED BY 'ChangeSholaPassw0rd!';

mysql> FLUSH PRIVILEGES;

mysql> QUIT;

Now login again with new root password !!

Sunday, September 4, 2022

How to access EC2 instance if lost key Pair and root credentials

Step-1: 

Create a new instance with same OS as previous one or create it from AIM made from old instance

Step-2: 

Shutdown the old instance and detach the volume

Step-3: 

Shutdown new instance Attached the detached volume to new instance and start the instance

Step-4: 

Login new instance using ssh console

Run the following commands:

lsblk

df -h

cd mnt

mkdir oldvolume

sudo mount /dev/sda1 mnt/oldvolume

cd mnt/oldvolume/root/.ssh

sudo vi authorized_keys

Now add your public key and save 

umount /dev/sda1

sudo shutdown now

Step-5: 

Now detach the dev/sda1 volume from new instance and attach to old instance as dev/sda

Step-6:

Reboot old instance from AWS dashboard and login your old instance using ssh console 

 Note: Your old instance IP will be changed after doing this if no elastic IP

Tuesday, August 30, 2022

How to Install Apache2 to make Web Server on Ubuntu 20.04

 sudo apt update

sudo apt install apache2

sudo systemctl is-active apache2

sudo systemctl is-enabled apache2

sudo systemctl status apache2

sudo systemctl stop apache2      #stop apache2

sudo systemctl start apache2     #start apache2

sudo systemctl restart apache2   #restart apache2

sudo systemctl reload apache2    #reload apache2

sudo systemctl disable apache2   #disable apache2

sudo systemctl enable apache2    #enable apache2

ls /etc/apache2/*

sudo vim /etc/apache2/apache2.conf 

ServerName webserver1.tecmint.com

sudo apache2ctl configtest

sudo systemctl restart apache2

sudo systemctl status apache2

sudo ufw allow http

sudo ufw allow https

sudo ufw reload

OR

sudo ufw allow 80/tcp

sudo ufw allow 443/tcp

sudo ufw reload


ls /var/www/html/

sudo mkdir -p /var/www/html/olineit.info

sudo chown www-data:www-data -R /var/www/html/olineit.info

sudo chmod 775 -R /var/www/html/olineit.info

sudo vim /var/www/html/olineit.info/index.html

sudo vim /etc/apache2/sites-available/olineit.info.conf

sudo a2ensite olineit.info.conf

sudo systemctl reload apache2


Monday, August 29, 2022

How to install NGINX and configure on Ubuntu 20.04

sudo apt-get update

sudo apt upgrade

sudo apt install nginx

sudo systemctl status nginx

sudo ufw allow http

sudo ufw reload


sudo systemctl status nginx

sudo systemctl stop nginx

sudo systemctl start nginx


sudo systemctl disable nginx

sudo systemctl enable nginx

sudo systemctl restart nginx

sudo systemctl reload nginx



sudo unlink /etc/nginx/sites-enabled/default

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

sudo nginx -t

sudo systemctl restart nginx

sudo mkdir /var/www/example.com

How to unzip tar.gz file in linux

sudo apt-get install zip

unzip file.zip -d destination_folder

unzip file.zip

tar -xf archive.tar.gz

Thursday, June 16, 2022

How to Install Desktop(GUI) on CentOS 7

 Step 1: Prerequisites


a) You should have a running RHEL/CentOS 7 System.

b) You should have sudo or root access to run privileged commands.

c) You should have yum utility available in your System.
Step 2: Update Your Server

Before installing a new package, it is always a good idea to update the System with the latest available versions using yum update command as shown below. If any of the packages needs upgradation then upgrade it by using yum upgrade command.

Step 3: Check Package Groups

You can check all the available package groups by using yum grouplist or yum group list command. As you can see from the below output, we need to basically install GNOME Desktop and Graphical Administration Tools package groups.
Step 4: Install GNOME Desktop(GUI)

To install GNOME Desktop and Graphical Administration Tools package groups, you need to use either yum groupinstall "GNOME Desktop" "Graphical Administration Tools" or yum group install "GNOME Desktop" "Graphical Administration Tools" command as shown below.
Step 5: Enable GUI

After successful installation of GNOME Desktop environment, you need to enable and make the graphical mode as default. This can be done by using systemctl set-default graphical command as shown below.
Step 6: Reboot Server

Finally reboot the Server using reboot command to start the Graphical mode.
Step 7: Setup GNOME Desktop(GUI)

After reboot, you should be able to see the GNOME Desktop environment like below.

Once you logged in, you should be able to see the below Window to select your language. By default, English will be selected so I will leave it as it is and Click on Next.

In the next step, you need to setup your Keyboard layout. By default, it will be selected as English(US) so I will leave as it is and Click on Next. You are free to choose any Keyboard layout here based on your preference.

In the next window, you will see an option to turn Location Services ON or OFF. Turning ON will allow applications to determine your geographical location. By default, it will selected as ON so for the moment I will leave as it is and Click on Next. If you don't want to any application to see your geographical location then you can switch OFF your Location Services.

In the next windows, you will be asked to connect your accounts to easily access your email, online calendar, contacts, documents and photos. You can either connect it or skip for the moment. I am choosing to skip this as of now so I will click on Skip.

This concludes your setup and now you are ready to use your System. To finish the setup Click on Start Using CentOS Linux.

This will bring you to the Server Desktop where you can start using your System as shown below.
Step 8: Uninstall GNOME Desktop(GUI)

In case, you decide not to use GNOME Desktop anymore then you can uninstall it by using yum groupremove "GNOME Desktop" "Graphical Administration Tools" or yum group remove "GNOME Desktop" "Graphical Administration Tools" command as shown below.

Tuesday, June 14, 2022

How to add additional IP address to CentOS 7 using command


Navigate to the network interface configuration folder using the following command:
cd /etc/sysconfig/network-scripts

Create a new virtual interface with:
nano ifcfg-eth0:0

The file will be created and opened with the text-editor “nano”. Now the following paragraphs must be added:

DEVICE=eth0:0
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.51.100.42
NETMASK=255.255.255.255


systemctl restart network
or
sudo reboot 

See the video:https://youtu.be/-Y5LXdpnEYY
Followed by: Contabo VPS

Extract Domain from email in Excel or Google sheet

  =TEXTAFTER( A2 , "@") or, =MID(A1, FIND("@", A1) + 1, LEN(A1) - FIND("@", A1))