Servers

How to Install PHP 7.4 on CentOS 8 / RHEL 8

PHP (Hypertext Preprocessor) is the most popular server-side scripting language and used in developing static and dynamic web sites. In this article, we will demonstrate on how to install latest version of PHP 7.4 on CentOS 8 and RHEL 8.

Minimum System Requirements for PHP 7.4

  • Minimal CentOS 8 / RHEL 8 OS
  • Sudo or Root Privileges
  • Basic Package Repositories
  • Internet Connection

Let’s jump into installation steps,

Step:1) Enable EPEL and Remi Repository

In the default CentOS 8 and RHEL 8 package repositories, PHP 7.2 / 7.3 is available and to install latest version of PHP 7.4, we must configure EPEL and REMI repositories, so to enable the repositories, run the following commands:

[[email protected] ~]$ sudo dnf install epel-release -y
[[email protected] ~]$ sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y

Once the repositories are configured and enabled, run the following dnf command to view available PHP versions,

[[email protected] ~]$ dnf module list php

dnf-module-list-php-centos8

As we can see in above output, PHP 7.2 is the default package from CentOS-8 AppStream repository, so in the next step, we will enable latest PHP module stream (redmi-7.4) so that when we install install PHP using dnf then it will automatically pick packages from remi-7.4 module

Step:2) Enable latest PHP Module Stream (remi-7.4)

Execute the following dnf command to enable remi-7.4 PHP module,

[[email protected] ~]$ sudo dnf module enable php:remi-7.4

Enable-remi-7-4-mdoule

Step:3) Install and Verify PHP

Now run the following dnf command to install PHP 7.4,

[[email protected] ~]$ sudo dnf install php php-cli php-common

Install-php-7-4-CentOS8-RHEL8

As we can see that it is installing its dependencies like httpd and nginx, So once above packages are installed successfully, run below “php -v” command to verify installed php version,

[[email protected] ~]$ php -v

php-version-centos8

While installing PHP, php-fpm is also installed as its dependency, it will be treated as FastCGI Server, so use below command to start and enable FPM service,

[[email protected] ~]$ sudo systemctl start php-fpm
[[email protected] ~]$ sudo systemctl enable php-fpm

Step:4) Updating PHP Parameters

While using the php in different CMS (Content Management System) like WordPress, Drupal, Joomla and MediaWiki etc we might have to update default PHP parameters to improve the performance. These parameters can be alerted from its configuration file “/etc/php.ini”,

[[email protected] ~]$ sudo vi /etc/php.ini
…………
upload_max_filesize = 32M 
post_max_size = 48M 
memory_limit = 256M 
max_execution_time = 600 
max_input_vars = 3000 
max_input_time = 1000
………

Save and exit the file, To make the above changes into the effect restart your web server service (httpd or nginx )

[[email protected] ~]$ sudo systemctl restart httpd

That’s all from this article, I hope these steps help you install and configure PHP 7.4 on your CentOS 8 and RHEL 8 System. Your feedback and comments are most welcome.

from Linuxtechi https://www.linuxtechi.com/install-php-on-centos-8-rhel-8/…

0
Read More

Being on the Safe Side of Being Online

Oh, the world wide web, how fascinating our lives have been with it! It has opened is to a whole new dimension of information we have no access to before. But then, just like any other place that’s worth exploring, there may be dangers that lurk on the sides that if you fall victim to, will damage your entire experience. So, you need to be aware of these hazards and keep yourself safe when surfing online. What’s great is that you don’t really need to be a computer science genius to know how to amply protect yourself when exploring the internet. Minimize your risk by taking note of these tips to enjoy a safer web experience.

The Importance of Upgrading

Let’s admit it: Most, if not all of us, get annoyed when programs in our computer get upgraded without our permission. These silent upgrades are not done for no reason, though, as they play a key role in keeping everyone safe. Moreover, browsers and OSes have made it point to roll out their updates in a seamless fashion, making it a point to not bother users. It would be best to apply these updates on all applications and programs, not just on your browser or frequently used programs. Don’t allow old versions of programs to be left in your machine, as they are susceptible to attacks, not to mention that they may soon (or may have already) be without support.

Silent upgrades might occasionally be annoying (and costly), but they’re a big part of keeping you safe, which is why the updates for most OSes and browsers now happen seamlessly. Apply updates whenever you’re asked to on all your applications, not just your browser, and be wary of leaving older hardware gathering dust on your network.

Viruses and malware are constantly evolving to exploit vulnerabilities in your software and hardware. Software developers try to fix these flaws as soon as they are discovered. What many people don’t realise is that infections occur because people delay software updates that fix these flaws. In short, they could have protected themselves by installing the updates to fix the security holes as soon as they came out.

(Via: https://www.necl-it.co.uk/2019/03/08/the-importance-of-keeping-software-up-to-date/)

That Required Two-Step Verification

Users are pretty much exposed to two-step verification, with most tech firms giving users the option to set it up on their accounts. What it is, basically, is that users can have an SMS or code to supplement their usernames and passwords every time they log in on a new device. Google and Microsoft highly encourage two-step verification, while for Mac users, they call it 2FA, or 2 Factor Authentication. There’s a slight difference in the process but the overall idea is the same.

Two-factor authentication (usually abbreviated 2FA) is a way to prove that you actually are the owner of a particular account by providing two “factors” of evidence. One factor is a piece of knowledge—your password or PIN, for instance. Another factor may be possession of a particular object—a phone that receives texts sent to a certain number, a USB key fob, or access to an email address. A another factor may be inheritance—something inherent to you, like your fingerprint or a retinal scan.

(Via: https://www.macworld.com/article/3520993/getting-started-with-2fa-secure-your-accounts-now-or-regret-it-later.html)

Is

0
Read More

How to Install LEMP Stack on Arch Linux

In this guide, you will learn how to install LEMP stack on an Arch Linux server. LEMP is a popular stack used by web developers for testing and hosting websites and applications. LEMP is an abbreviation for Linux Nginx (pronounced as Engine X) MariaDB / MySQL and PHP.  Nginx is a high-performance and stable web server which can also be used as a reverse proxy. It’s popular for serving high traffic sites and is usually preferred to Apache in production servers. MariaDB / MySQL are open source database Engines for storing website data. MariaDB is a fork of MySQL and is mostly preferred since the takeover of MySQL by Oracle. Lastly, we have PHP which is a server-side scripting language used for developing dynamic web pages. We are going to install each of these components and test their installation on Arch Linux.

Let’s begin!

Step 1) Install Nginx Web Server

Before the installation of any package, it’s always a good idea to update the system packages. So, proceed and update Arch packages using the command:

$ sudo pacman -Syy

To install Nginx, run the command:

$ sudo pacman -S nginx

Install-nginx-arch-linux

Once installed, enable Nginx to start upon boot and start Nginx service by running the commands:

$ sudo systemctl enable nginx
$ sudo systemctl start nginx

start-enable-nginx-service-arch-linux

To confirm that Nginx is running, execute the command:

$ sudo systemctl status nginx

Verify-Status-nginx-arch-linux

The output indicates that Nginx is up and running. Additionally, you can confirm that the Nginx web server is up by launching your browser and typing your server’s IP address in the URL bar as shown.

http://server-IP

Nginx-web-page-arch-linux

To check the version of Nginx installed, run:

$ nginx -v

nginx-version-check-arch-linux

By default, Nginx listens on port 80. To confirm this, use the netstat command as shown:

$ sudo netstat -plntu

nginx-port-netstat-arch-linux

Step 2) Install MariaDB database Engine

To install MariaDB database engine, run the command:

$ sudo pacman -S mariadb

install-mariadb-arch-linux

Once installed, proceed and initialize the MariaDB data directory and create system tables as shown below

$ sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

initialize-mysql-data-directory-arch-linux

After the initialization is complete, enable and start the MariaDB service as shown

$ sudo systemctl enable mariadb
$ sudo systemctl start mariadb

start-enable-mariadb-service-arch-linux

By default, upon installation, MariaDB database engine does not have a password for the root user. This can create a loop hole for a potential breach. To prevent that from happening,we need to secure our database engine and enforce a list of other restrictions.

So change to root user and run the command below to begin hardening MariaDB

$ mysql_secure_installation

This will start a series of prompts. First, you will be required to set the root password. Initially, you will be notified that the root account is protected and that you can proceed at your discretion and ignore changing the root password.

If you feel that you need to change the password hit ‘Y’ on the keyboard and provide a strong password and confirm it.

mysql-secure-installation-arch-linux

The rest of the prompt will require you to perform a few hardening tweaks to your MariaDB database engine. This includes removing anonymous users, disabling remote root login , removing the test database and finally reloading the privileges tables to which you should answer Yes to all …

0
Read More

Free Your Phone by Unlocking It

Let’s admit it: Not all of us can buy a phone outright. We would need to save and penny-pinch on some unnecessary expenses for months just to gather enough cash. By the time we have saved enough, it would be most likely that the phone we are eyeing to buy is already not the latest. Thus, it makes sense for most of us to rely on a monthly contract with a carrier to make the phone’s cost more manageable, not to mention you can get the phone the moment you sign the contract. But then, once the contract period is over, you may already legally own the phone, but do you still want to carry on with your carrier? There may be plans with better value on other carriers, so you may want to use your phone when you make that switch.

Of course, the biggest hindrance to your plans is that more often than not, phones that are given through contracts are locked to the carrier. After all, phone locking is a way for carriers to maintain their hold on their customers and prevent them from using the phone they acquired with their contracts to other carriers. However, recent legislation has made it easier and legal for phone unlocking to be done. Finally, not just because it has become easier and legal does not mean that you can DIY yourself through the process.

T-Mobile

Should you bother to unlock your T-Mobile phone? Yes, because they are GSM-based. This means that an unlocked T-Mobile phone can be used with other international carriers, including AT&T.

T-Mobile makes it pretty easy to unlock your phone, but there are just a couple things you need to do first.

(Via: https://www.androidguys.com/guides/how-to-unlock-your-t-mobile-phone/)

 

Sprint

An unlocked Sprint phone can be used as a prepaid phone and can also be used in mobile virtual network operator (MVNO) brands like Net10, Twigby, and Boost Mobile, among others.

For postpaid customers with SIM unlock-capable devices, Sprint has chosen to simply unlock active eligible SIM unlock-capable devices without requiring our customers to initiate an unlock request. Once you meet the requirements outlined in the Unlock Policy, Sprint will automatically unlock your active eligible SIM unlock-capable device.

(Via: https://www.androidguys.com/guides/how-to-unlock-your-sprint-phone/)

 

AT&T

AT&T is one of the world’s largest wireless service providers with subscribers. With over 150 million in their fold, they are attracting more subscribers, but surely, there are also current AT&T who want to escape its clutches.

AT&T’s phones operate on a GSM-based network which means they can theoretically work with numerous other carriers. The catch, of course, being that the handsets need to be unlocked first.

(Via: https://www.androidguys.com/guides/how-to-unlock-your-att-phone/)

 

Verizon

A Verizon phone operates on a CDMA, which means even if unlocked there may not be a lot of options for you to use it with another carrier. This means your options are limited to international coverage, prepaid and MVNO brands. But there are still other options.

Also worth noting, you should still be able to use an unlocked Verizon LTE phone on AT&T or T-Mobile — or their MVNO brands. More and more we’re finding their handsets to be compatible with both carriers’ LTE bands.

(Via: https://www.androidguys.com/guides/how-to-unlock-your-verizon-phone/)

 

Have an S10? Here’s what

0
Read More

How to Configure NIC Teaming on CentOS 8 / RHEL 8

NIC teaming is the concept of combining or bonding 2 or more network interfaces into one logical interface to provide high throughput and redundancy. This practice is popular especially with critical servers where high availability is expected at all times. In a server with 2 or more NIC cards, the concept of NIC teaming is critical in the event where one NIC card fails. With NIC teaming, the logical network interface will ensure that the remaining NIC will continue functioning and serving the purpose of the defective NIC. In this guide, we take you through the configuration of NIC teaming in CentOS 8 and RHEL 8.

Let’s take a look at some of the concepts around

  • Teamd –  This is a daemon that allows you to configure a  team network interface.  Teamd is a part of the libteam project and leverages the libteam library for implementation of load balancing and round-robin logic.
  • Teamdctl  – This is a utility tool for querying an instance of teamd for configuration information and detailed statistics.
  • Runners – These are distinct units of code in JSON format used for implementing different concepts of NIC teaming such as Round robbin

Runners exist in the following modes:

  • Round-robin: In this mode, data is transmitted across all ports in turn.
  • Broadcast: Here data is transmitted across all ports.
  • Load-balance: Traffic is distributed across all NICs.
  • Active-backup: Where one link or port is activated as the rest are reserved as a backup. This is used for failover to provide redundancy as we shall later see in this guide.
  • Lacp: Uses the the 802.3ad Protocol for link aggregation

Let’s now go ahead and configure NIC teaming in CentOS 8.

Step :1) Install Teamd daemon

Teamd  is the daemon that makes it possible  for configuration of team networks. Gladly, CentOS 8 comes with the daemon already installed. If for whatever reason teamd is missing on your CentOS 8 / RHEL 8 system, run the command:

$ sudo dnf install teamd

dnf-install-teamd-centos8

Upon completion of its installation, you can gather in-depth information about teamd by executing the command:

$ rpm -qi teamd

Step :2) Configure NIC teaming with nmcli tool

Nmcli is a command-line utility that is used for managing NetworkManager.  But first, let’s check the attached network interfaces on our system. Run the command

$ nmcli device status

nmcli-device-status-command-centos8

From the output above, there are 2 ethernet connections and 1 Wi-Fi connection on the system. I’m going to use enp0s3 and enp0s8 network devices as slave connections.

Also you can use the command:

$ nmcli connection show

nmcli-connection-show-command-centos8

I’m therefore going to delete the enp0s3 and enp0s8 network devices which will be used as slave devices using the syntax

$ nmcli connection delete UUID

So, proceed and run the commands:

$ nmcli connection delete a2533841-93bf-4a78-9c84-4f7e8669e92f
$ nmcli connection delete 77c70d70-2fb2-4a19-bc02-d71b49a6ffac

nmcli-connection-delete-centos8

After deletion, the two network devices should now be disconnected. You can verify this by running:

$ nmcli device status

nmcli-device-disconnected-output-command

Now let’s create a new team interface and call it bond0

$ nmcli connection add type team con-name bond0 ifname bond0 config '{"runner": {"name": "activebackup"}}'

nmcli-add-teamd-centos8

The value ‘activebackup’ is a runner that can be replaced with either round-robin, broadcast , random or lacp.

The configuration is appended …

0
Read More

How to Install VirtualBox on Arch Linux

VirtualBox is a free and open source, cross platform virtualization tool from Oracle that allows you to create virtual machines and try out different operating systems. It’s easy to install and use and you can create your own virtual machines, assign them resources such as CPU and RAM and even clone them. In this topic we will demonstrate how you can install VirtualBox and its extension pack on Arch Linux.

Installing VirtualBox on Arch Linux

To get VirtualBox on your system, follow the steps below.

Step 1)  Install VirtualBox package

Installing VirtualBox is as easy as it gets. Just launch the terminal and a s a sudo user, simply run the command:

$ sudo pacman -S virtualbox virtualbox-guest-iso

pacman-command-install-virtualbox

When prompted to proceed with installation type ‘Y’ and hit continue to install the VirtualBox packages and dependencies.

Next, add the current user to the vboxusers group by running the command:

$ sudo gpasswd -a $USERS vboxusers

add-user-vboxusers-archlinux

Next, load the virtualbox kernel module using the command:

$ sudo modprobe vboxdrv

modprobe-vboxdrv-archlinux

At this point, VirtualBox is installed on your Arch Linux system. However, we do need to install the VirtualBox extension pack to enable VirtualBox USB 2.0 and 3.0 capabilities. This will allow your virtual machines to detect and work with USB pen drives which are plugged on the host system.

Step 2) Install VirtualBox extension package

To install the Virtualbox extension package, first update the system using either yaourt or yay package managers as shown:

$ yaourt -Syy
OR
$ yay -Syy

update-archlinux

Next, install the VirtualBox extension pack using the command:

$ yay -S virtualbox-ext-oracle

install-virtualbox-extension-archlinux

You also need to enable vboxweb for it to start on boot and start the service

$ sudo systemctl enable vboxweb.service
$ sudo systemctl start vboxweb.service

start-enable-virtualbox-service-archlinux

Perfect, Service also got started successfully. Let’s verify the VirtualBox Kernel module is loaded or not, run below lsmod command

$ lsmod | grep -i vbox

lsmod-vbox-kernel-module-arch-linux

The output should display vbox kernel modules as shown above.

Step 3) Launching VirtualBox

To launch Virtualbox, use the applications manager by pressing the Super Key or Windows Key – for the case of GNOME desktop manager –  and search for VirtualBox as shown below.

acces-virtualbox-archlinux

Thereafter, click on the Virtualbox icon to launch it. You should finally see the VirtualBox window as shown below.

VirtualBox-Window-ArchLinux

To confirm that the extension pack was installed, click on ‘File’ then navigate to ‘Preferences’. You can alternatively hit the ‘CTRL + G’ keyboard shortcut.

VirtualBox-Preferences-ArchLinux

On the next window, click on ‘Extensions’. On the right pane, the Name and the version of the extensions package will be displayed. To return to the main window click on the ‘OK’ button.

VirtualBox-Extension-ArchLinux

We have finally installed VirtualBox and VirtualBox extensions pack to provide extra functionality to your virtual machines.

from Linuxtechi https://www.linuxtechi.com/install-virtualbox-on-arch-linux/…

0
Read More

How to Enable Nested Virtualization in VirtualBox on Linux

By default nested virtualization in Oracle VM VirtualBox on linux system is disabled. With the release of VirtualBox 6.1 we can enable nested virtualization on Intel CPUs starting with 5th generation Core i.

Prerequisites for VirtualBox Nested Virtualization:

  • VirtualBox Version 6.1 or higher
  • AMD CPU / Intel CPU ( Core i5 or higher)

In article we will demonstrate how to enable nested virtualization on Intel CPUs for VirtualBox VM on Linux.

Install / Upgrade VirtualBox to latest version

Note: You can Skip this step if already have VirtualBox 6.1 on your Linux system

At time of writing this article, latest version of VirtualBox is 6.1, so in case you are running an older version of virtualbox on system then run the following commands to install and upgrade it.

For Ubuntu / Debian

[email protected]:~$ wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
[email protected]:~$ wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add -
[email protected]:~$ sudo add-apt-repository "deb [arch=amd64] http://download.virtualbox.org/virtualbox/debian $(lsb_release -cs) contrib"
[email protected]:~$ sudo apt-get update
[email protected]:~$ sudo apt-get install virtualbox-6.1 -y

If you get the following error message while starting or creating a VM after upgrading VirtualBox,,

VirtualBox-error-after-upgrade

To resolve this issue, execute the following commands

[email protected]:~$ sudo apt-get remove virtualbox-dkms -y
[email protected]:~$ sudo /sbin/vboxconfig

For CentOS / RHEL / Fedora

Create VirtualBox 6.x repo file with following contents,

[[email protected] ~]# vi /etc/yum.repos.d/virtualbox.repo
[virtualbox]
name=Oracle Linux / RHEL / CentOS-$releasever / $basearch - VirtualBox
baseurl=http://download.virtualbox.org/virtualbox/rpm/el/$releasever/$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://www.virtualbox.org/download/oracle_vbox.asc

save and exit the file,

Run below Yum / DNF command to install virtualbox 6.1

[[email protected] ~]# yum install VirtualBox-6.1 -y
or
[[email protected] ~]# dnf install VirtualBox-6.1 -y

Note: In case on your Linux system, if VirtualBox 6 repository is already configured then skip the repository configuration part, You can directly install or upgrade virtualbox.

Enable Nested Virtualization for VirtualBox VM

Let’s suppose i have a centos vm on my virtualbox, i want to enable nested virtualization for this vm, before enabling it login to vm console and execute the following command,

# grep -E --color 'vmx|svm' /proc/cpuinfo

CentosVM-VirtualBox

Above command’s blank output confirms that nested virtualization is not enabled on centos vm.

Let’s power off this VM and enable VT-x /AMD-v , Select the VM for which you want to enable nested virtualization, then click on settings. Under the System Tab, select Processor and click on “Enable Nested VT-x/AMD-v” under the Extended Features Tab,

enable-vtx-amdv-virtualbox

click on Ok to save the changes

In case “enable Nested VT-x/AMD-v” is greyed out then we can enable it via command line , execute the following command,

$ VBoxManage modifyvm  <VM-Name> –nested-hw-virt on

Example :

[email protected]:~$ VBoxManage modifyvm ubuntu18 --nested-hw-virt on

Now let’s verify from Centos VM whether nested virtualization is enabled or not, power on the VM and login to console and run following commands,

# egrep -E –color ‘svm|vmx’ /proc/cpuinfo
# lscpu

nested-virtualization-inside-virtualbox-vm

Output of above commands confirm that Nested Virtualization has been enabled on CentOS VirtualBox VM.

That’s all from this article, I hope this article was informative and you get better understanding on how to enable Nested VT-x / AMD-v feature on Oracle VM VirtualBox. Please don’t  hesitate to share your feedback and comments.

from Linuxtechi https://www.linuxtechi.com/enable-nested-virtualization-virtualbox-linux/…

0
Read More

Do’s and Dont’s for Starting Your First Website

Starting a website is one of the best things you could do for your business. A website will make sure that your work gets seen by more people and will allow you to create a first impression that lasts. However, if someone has a bad experience on your site, they’re likely to leave it and […]

Source

from ThisHosting.Rocks https://thishosting.rocks/dos-and-donts-for-starting-your-first-website/…

0
Read More

How to Use Variables in Ansible Playbook

If you have done some programming in Python, Java, C, C++ or in any other programming language, then variables are not alien. Just like in programming languages, variables in Ansible are used to store a value.

In Ansible, variables provide the much-needed flexibility in Playbooks, templates and inventories as we shall later see in this tutorial. Built-in variables can be used to provide system information such as hostname, system architecture, interfaces etc. Variables can also be used to replace strings and also in loops to loop through a given set of values.

A valid variable name is made of the following characters

  • Letters
  • Numbers
  • Underscores
  • A combination of any two or all of the above

A variable SHOULD ALWAYS START WITH A LETTER  and SHOULD NOT CONTAIN ANY SPACES.

Examples of acceptable variable names include:

  •  turntable
  •  turn_table
  •  turntable01
  •  turntable_01

The names below do not qualify as valid variable names

  •   turn table
  •  turn-table
  •  01turntable
  •  01

Let’s now look at different use cases of Variables in Ansible

Variables in Playbooks

As you know, A playbook is a collection of plays or tasks to be performed on a remote system. In playbooks, variables are handy in determining how tasks can be executed. Assigning a value to a variable in a playbook is quite easy and straightforward.

Begin by calling the vars keyword then call the variable name followed by the value as shown.

---
 - hosts: all
   vars:
     salutations: Hello guys!
   tasks:
   - name: Ansible Variable Basic Usage
       debug:
       msg: ""

In the playbook above, the variable name is  salutations  and the value is Hello world! When the playbook is run, the value of the playbook is accessed by placing the variable between curly braces as shown above. When executed, the playbook prints the message ‘Hello guys’ on the terminal.

Basic-Variable-ansible-playbook

Variables with Arrays

You can use arrays and assign them to variables as shown in the syntax below:

vars:

     arrayname:

        – value1

        – value2

For example, the playbook below contains an array of 5 student names stored in a variable called students. You can access the student names through indexing ( as you would in arrays in any other programming language)  For example, to retrieve the name ‘Arthur’ from the array list use the syntax students [2] as shown below.

- hosts: all
  vars:
    students:
      - Mark
      - Melisa
      - Arthur
      - Kevin
      - Lisa

  tasks:
  - name: Ansible List variable Example
    debug:
      msg: ""

Variables with dictionaries

From the Array list, you can further define each of the entries using a key value pair forming what we call a dictionary list. The syntax is shown below

vars:

     arrayname:

         dictionary_name1:

              value1: itemvalue1

              value2: itemvalue2

         dictionary_name2:

            value1: itemvalue1

            value2: itemvalue2

Using our previous example, we can have dictionary lists below

- hosts: all
  vars:
    students:
      Mark:
      city: Melbourne
      address: 0045-0987-8642
      
      Angela:
      city: Sydney
      address: 3456-7685-9087

Variables in Inventory files

If you have different host systems that share similar attributes or values, you can define what we call group variables. These are used  to assign the attributes which are common to all the hosts.

For example:

Let’s assume we have 2 web servers: webserver_1 and webserver_2 which are both listening to port 443 and whose  ntp server is us.pool.ntp.org. The inventory file …

0
Read More

Learn Pgrep and Pkill Command with Examples in Linux

Linux is loved by developers and enthusiasts alike. You can do lots of things you usually can’t do on operating systems such as windows and OSX.

Linux is the best operating system for programmers, developers, and anyone who wants to understand operating systems properly. Now Linux has many functions and capabilities. Today you are going to learn about Linux pgrep and pkill command and how you can use them to make your Linux experience worthwhile. As name suggests pgrep command is used to search the process based on name and pkill command will terminate or kill the process based on the name.

Prerequisites

  • A Linux operating system (screenshots are from a centos / rhel machine)

pgrep command

Syntax: # pgrep [options] pattern

pgrep-command-options-linux

Most Linux users recognize the grep command which is used to find specific words or characters. pgrep works in almost the same way. The pgrep command is used while searching for processes (based on name) that are running on the system at the time of use.

Let’s deep dive into pgrep command examples,

Example:1) List Process ID owned by specific user (-u)

When used, pgrep lists the process IDs which match the criteria that you specify. For example, when you type;

[[email protected] ~]# pgrep -u apache httpd
1274
1275
1278
1282
1283
1284
1286
1291
[[email protected] ~]#

The system lists all processes called httpd that are owned by apache user.

Example:2) List all processes owned by multiple users

Let’s assume we want to list all processes owned by root and apache user, execute following command,

[[email protected] ~]# pgrep -u apache,root

Here users are separated by commas (,)

Output:

pgrep-different-users

Example:3) Count Number of Matching Process (-c)

Let’s suppose we want to count number process owned by apache and root user, run the beneath command

[[email protected] ~]# pgrep -u apache -c
8
[[email protected] ~]# pgrep -u root -c
95
[[email protected] ~]#

In above command, ‘-c’ option is used to count number of process associated to a user.

Example:4) List Process IDs along with process name (-l & -a)

Let’s suppose we want to list process ids and process name associated to a user, then use -l or -a option in pgrep command. -l option will list only process name whereas -a will list full path of process name,

[[email protected] ~]# pgrep -u apache -l
4353 httpd
4354 httpd
4355 httpd
4356 httpd
4357 httpd
4358 httpd
4359 httpd
4360 httpd
[[email protected] ~]#

[[email protected] ~]# pgrep -u apache -a
4353 /usr/sbin/httpd -DFOREGROUND
4354 /usr/sbin/httpd -DFOREGROUND
4355 /usr/sbin/httpd -DFOREGROUND
4356 /usr/sbin/httpd -DFOREGROUND
4357 /usr/sbin/httpd -DFOREGROUND
4358 /usr/sbin/httpd -DFOREGROUND
4359 /usr/sbin/httpd -DFOREGROUND
4360 /usr/sbin/httpd -DFOREGROUND
[[email protected] ~]#

Example 5) List the process ids associated to a user using custom delimiter (-d)

Use ‘-d’ option in pgrep to list process ids of user by using custom delimiter, let’s suppose we list the process ids associated to apache user separated by comma (,) or space.

[[email protected] ~]# pgrep -u apache -d,
4353,4354,4355,4356,4357,4358,4359,4360
[[email protected] ~]# pgrep -u apache -d" "
4353 4354 4355 4356 4357 4358 4359 4360
[[email protected] ~]#

Example:6) List newest process name and it’s id (-n)

Let’s assume we want to list newest process name and its ids owned by root user, execute below pgrep command

Syntax:

# pgrep -u <user>

0
Read More