How to Check MySQL Database Size in Linux

‘,
enableHover: false,
enableTracking: true,
buttons: { twitter: {via: ‘tecmint’}},
click: function(api, options){
api.simulateClick();
api.openPopup(‘twitter’);
}
});
jQuery(‘#facebook’).sharrre({
share: {
facebook: true
},
template: ‘{total}’,
enableHover: false,
enableTracking: true,
click: function(api, options){
api.simulateClick();
api.openPopup(‘facebook’);
}
});
jQuery(‘#googleplus’).sharrre({
share: {
googlePlus: true
},
template: ‘{total}’,
enableHover: false,
enableTracking: true,
urlCurl: ‘https://www.tecmint.com/wp-content/themes/tecmint/js/sharrre.php’,
click: function(api, options){
api.simulateClick();
api.openPopup(‘googlePlus’);
}
});
jQuery(‘#linkedin’).sharrre({
share: {
linkedin: true
},
template: ‘{total}’,
enableHover: false,
enableTracking: true,
buttons: {
linkedin: {
description: ‘How to Check MySQL Database Size in Linux’,media: ‘https://www.tecmint.com/wp-content/uploads/2017/12/Check-MySQL-Database-Size-in-Linux.png’ }
},
click: function(api, options){
api.simulateClick();
api.openPopup(‘linkedin’);
}
});
// Scrollable sharrre bar, contributed by Erik Frye. Awesome!
var shareContainer = jQuery(“.sharrre-container”),
header = jQuery(‘#header’),
postEntry = jQuery(‘.entry’),
$window = jQuery(window),
distanceFromTop = 20,
startSharePosition = shareContainer.offset(),
contentBottom = postEntry.offset().top + postEntry.outerHeight(),
topOfTemplate = header.offset().top;
getTopSpacing();
shareScroll = function(){
if($window.width() > 719){ var scrollTop = $window.scrollTop() + topOfTemplate,
stopLocation = contentBottom – (shareContainer.outerHeight() + topSpacing);
if(scrollTop > stopLocation){
shareContainer.offset({top: contentBottom – shareContainer.outerHeight(),left: startSharePosition.left});
}
else if(scrollTop >= postEntry.offset().top-topSpacing){
shareContainer.offset({top: scrollTop + topSpacing, left: startSharePosition.left});
}else if(scrollTop 1024)
topSpacing = distanceFromTop + jQuery(‘.nav-wrap’).outerHeight();
else
topSpacing = distanceFromTop;
}
});
]]>

CrossOver 17 – Run Windows Software and Games on Linux

‘,
enableHover: false,
enableTracking: true,
buttons: { twitter: {via: ‘tecmint’}},
click: function(api, options){
api.simulateClick();
api.openPopup(‘twitter’);
}
});
jQuery(‘#facebook’).sharrre({
share: {
facebook: true
},
template: ‘{total}’,
enableHover: false,
enableTracking: true,
click: function(api, options){
api.simulateClick();
api.openPopup(‘facebook’);
}
});
jQuery(‘#googleplus’).sharrre({
share: {
googlePlus: true
},
template: ‘{total}’,
enableHover: false,
enableTracking: true,
urlCurl: ‘https://www.tecmint.com/wp-content/themes/tecmint/js/sharrre.php’,
click: function(api, options){
api.simulateClick();
api.openPopup(‘googlePlus’);
}
});
jQuery(‘#linkedin’).sharrre({
share: {
linkedin: true
},
template: ‘{total}’,
enableHover: false,
enableTracking: true,
buttons: {
linkedin: {
description: ‘CrossOver 17 – Run Windows Software and Games on Linux’,media: ‘https://www.tecmint.com/wp-content/uploads/2017/12/CrossOver-Run-Windows-Games-on-Linux.png’ }
},
click: function(api, options){
api.simulateClick();
api.openPopup(‘linkedin’);
}
});
// Scrollable sharrre bar, contributed by Erik Frye. Awesome!
var shareContainer = jQuery(“.sharrre-container”),
header = jQuery(‘#header’),
postEntry = jQuery(‘.entry’),
$window = jQuery(window),
distanceFromTop = 20,
startSharePosition = shareContainer.offset(),
contentBottom = postEntry.offset().top + postEntry.outerHeight(),
topOfTemplate = header.offset().top;
getTopSpacing();
shareScroll = function(){
if($window.width() > 719){ var scrollTop = $window.scrollTop() + topOfTemplate,
stopLocation = contentBottom – (shareContainer.outerHeight() + topSpacing);
if(scrollTop > stopLocation){
shareContainer.offset({top: contentBottom – shareContainer.outerHeight(),left: startSharePosition.left});
}
else if(scrollTop >= postEntry.offset().top-topSpacing){
shareContainer.offset({top: scrollTop + topSpacing, left: startSharePosition.left});
}else if(scrollTop 1024)
topSpacing = distanceFromTop + jQuery(‘.nav-wrap’).outerHeight();
else
topSpacing = distanceFromTop;
}
});
]]>

How to Test Local Websites or Apps on Internet Using Ngrok

Are you a website or mobile application developer, and want to expose your localhost server behind a NAT or firewall to the public Internet for testing purposes? In this tutorial, we will reveal how to do this securely using ngrok.

Ngrok is a sensational, free open source and cross-platform reverse proxy server for exposing local servers behind NATs and firewalls to the public Internet over secure tunnels. It is a remarkable computer program that you can use to implement personal cloud services directly from home.

It essentially establishes secure tunnels to your localhost, thus enabling you to: run demos of web sites before actual deployment, testing mobile apps connected to your locally running backend and building web-hook consumers on your development machine.

Ngrok Features:

  • Easy install with zero run-time dependencies for any major platform and works fast.
  • Supports secure tunnels.
  • Captures and analyzes all traffic over the tunnel for later inspection and replay.
  • Allows you to do away with port forwarding in your router.
  • Enables implementing of HTTP authentication (password protection).
  • Uses TCP tunnels to expose networked service that do not use HTTP such as SSH.
  • Supports tunneling only HTTP or HTTPS with SSL/TLS certificates.
  • Supports multiple simultaneous tunnels.
  • Allows for replaying webhook requests.
  • Enables you to work with virtual-host sites.
  • It can be automated via an API plus many options in the paid plan.

Before using it, you need to have a web server installed or consider setting up a functional LAMP or LEMP stack, otherwise follows these guides to:

Install LAMP Stack on Linux:

  1. Installing LAMP (Linux, Apache, MariaDB, PHP/PhpMyAdmin) in RHEL/CentOS 7.0
  2. How to Install LAMP with PHP 7 and MariaDB 10 on Ubuntu 16.10

Install LEMP Stack on Linux:

  1. How to Install LEMP (Linux, Nginx, MariaDB, PHP-FPM) on Debian 9 Stretch
  2. How To Install Nginx, MariaDB 10, PHP 7 (LEMP Stack) in 16.10/16.04
  3. Install Latest Nginx, MariaDB and PHP on RHEL/CentOS 7/6 & Fedora 20-26

How to Install Ngrok in Linux


Ngrok is super easy to install, simple run the commands below to download and unzip the archive file which contains a single binary.

$ mkdir ngrok
$ cd ngrok/
$ wget -c https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
$ unzip ngrok-stable-linux-amd64.zip
$ ls
Download Ngrok Tool

Download Ngrok Tool

Once you have the binary file, let’s create a basic index.html page in the web server’s (Apache) default document root for testing requests to the web server.

$ sudo vi /var/www/html/index.html

Add the following HTML content in the file.

<!DOCTYPE html>
<html>
<body>
<h1>This is a TecMint.com Dummy Site</h1>
<p>We are testing Ngrok reverse proxy server.</p>
</body>
</html>

Save the file and launch ngrok by specifying the http port 80 (if you have configured you web server to listen on another port, you need to use that port):

$ ngrok http 80

Once you start it, you should see an output similar to the one below in your terminal.

Launch Ngrok on Terminal

Launch Ngrok on Terminal

How to Inspect Traffic to Your Web Server Using Ngrok UI

Ngrok offers a simple web UI for you to inspect all of the HTTP traffic running over your tunnels in real-time.

http://localhost:4040 
Ngrok Web Interface

Ngrok Web Interface

From the output above, no requests have been made to the server yet. To get started, make a request to one of your tunnel using the URLs below. Other user will also use these addresses to access your site or app.

http://9ea3e0eb.ngrok.io OR
https://9ea3e0eb.ngrok.io 
Check Local Website Over Ngrok

Check Local Website Over Ngrok

Then check from the inspection UI to get all of the details of the request and response including the time, client IP address, duration, headers, request URI, request payload and the raw data.

Check Website Requests

Check Website Requests

For more information, see the Ngrok Homepage: https://ngrok.com/

Ngrok is simply an amazing tool, it is by far the simplest yet powerful secure local tunnel solution you will find out there. You should consider creating a free ngrok account to get more bandwidth, but if you want even more advanced features, try upgrading to a paid account. Remember to share your thoughts about this piece of software, with us via the comment form below.

How to Reset WordPress Admin Password via MySQL Command Prompt

Sometimes, a WordPress user, with one of the following capabilities, such as administrator, editor, author, contributor or subscriber, forgets its login credentials, especially the password.

WordPress password can be easily changed via “Lost password” WordPress login form. However, if the WordPress account has no way of accessing his email address, changing the password using this mechanism can be impossible. In such cases, the job of updating a WordPress account password can only be managed by a system administrator with full privileges to MySQL database daemon.

In this guide we will show you how to reset a WordPress account password via MySQL command line in Linux.

Before logging in to MySQL/MariaDB database service, first create a MD5 Hash version of the new password that will be assigned to the account, by issuing the below command.


Replace the “newpass” string used in this example with your own strong password. Copy the password MD5 hash to a file in order to later paste the hash to MySQL user password field.

# echo -n "newpass" | md5sum
Create MD5 WordPress Password

Create MD5 WordPress Password

After you’ve generated the new password MD5 hash, log in to MySQL database with root privileges and issue the below command in order to identify and select the WordPress database. In this case the WordPress database is named “wordpress”.

# mysql -u root -p
MariaDB [(none)]> show databases;
MariaDB [(none)]> use wordpress;
Connect and Select WordPress Database

Connect and Select WordPress Database

Next, execute the below command to identify the table responsible for storing WordPress user accounts. Usually the table that stores all user information is wp_users.

Query wp_users table to retrieve all users ID, login name and password and identify the username ID field of the account that needs the password changed.
The username ID value will be used to further update the password.

MariaDB [(none)]> show tables;
MariaDB [(none)]> SELECT ID, user_login, user_pass FROM wp_users;
List All WordPress Users in MySQL

List All WordPress Users in MySQL

After you’ve correctly identified the ID of the user that needs the password changed, issue the below command to update his password. Replace the user ID and password MD5 Hash accordingly.

In this case the user ID is 1 and the new password hash is: e6053eb8d35e02ae40beeeacef203c1a.

MariaDB [(none)]> UPDATE wp_users SET user_pass= "e6053eb8d35e02ae40beeeacef203c1a" WHERE ID = 1;
Reset WordPress Admin Password in MySQL

Reset WordPress Admin Password in MySQL

In case you don’t have an already MD5 hashed password, you can execute MySQL UPDATE command with the password written in plain text, as shown in the below example.

In this case we’ll use MySQL MD5() function to calculate the MD5 hash of the password string.

MariaDB [(none)]> UPDATE wp_users SET user_pass = MD5('the_new_password') WHERE ID=1;

After the password has been updated, query wp_users table with the ID of the user that you’ve changed the password in order to retrieve this user database information.

MariaDB [(none)]> SELECT ID, user_login, user_pass FROM wp_users WHERE ID = 1;

That’s all! Now, inform the user that his password has been updated and it should be able to log in to WordPress with the new password.

How to View Colored Man Pages in Linux

In Unix-like operating systems, a man page (in full manual page) is a documentation for a terminal-based program/too/utility (commonly known as a command). It contains the name of the command, syntax for using it, a description, options available, author, copyright, related commands etc.

Read Also: ccat – Show ‘cat Command’ Output with Syntax Highlighting or Colorizing

You can read the manual page for a Linux command as follows; this will display the man page for the df command:

$ man df 
df Command Man Page

df Command Man Page

By default, the man program normally uses a terminal pager program such as more or less to format its output, and the default view is normally in white color for every kind of text (bold, underlined etc..).


You can make some tweaks to your ~/.bashrc file to get nicely colored man pages by specifying a color scheme using various LESS_TERMCAP variables.

$ vi ~/.bashrc

Add following color scheme variables.

export LESS_TERMCAP_mb=$'\e[1;32m'
export LESS_TERMCAP_md=$'\e[1;32m'
export LESS_TERMCAP_me=$'\e[0m'
export LESS_TERMCAP_se=$'\e[0m'
export LESS_TERMCAP_so=$'\e[01;33m'
export LESS_TERMCAP_ue=$'\e[0m'
export LESS_TERMCAP_us=$'\e[1;4;31m'

Following are the color codes that we used in the above configuration.

  • 31 – red
  • 32 – green
  • 33 – yellow

And here are the meanings of the escape codes used in the above configuration.

  • 0 – reset/normal
  • 1 – bold
  • 4 – underlined

You can additionally reset your terminal by typing reset or even start up another shell. Now when you try to view a man page df command, it should look like this, nicer than the default view.

Colored Man Page

Colored Man Page

Alternatively, you can use the MOST paging program, which works on Unix-like operating systems and supports multiple windows and can scroll left and right.

$ sudo apt install most #Debian/Ubuntu # yum install most #RHEL/CentOS
# dnf install most #Fedora 22+

Next, add the line below in your ~/.bashrc file, then source the file like before and possibly reset your terminal.

export PAGER="most"
Most Paging Program for Linux

Most Paging Program for Linux

Read Also: How to Customize Bash Colors and Content in Linux Terminal Prompt

In this article, we showed you how to display beautifully colored man pages in Linux. To send us any queries or share any useful Linux shell tips/tricks, use the comment section below.

ccat – Show ‘cat Command’ Output with Syntax Highlighting or Colorizing

ccat is command line similar to cat command in Linux that displays the content of a file with syntax highlighting for the following programming languages: Javascript, Java, Go, Ruby, C, Python and Json.

To install ccat utility in your Linux distribution, first assure that the wget utility is present in your system. If the wget command line is not installed in the system, issue the below command to install it:

# yum install wget [On CentOS/RHEL/Fedora]
# apt-get install wget [On Debian and Ubuntu]

In order to install the latest version of ccat command line via the latest compiled binaries, first download the compressed tarball by issuing the below command. The binary and source code releases archives can be found at the official ccat github webpage.

-------------- On 64-Bit -------------- # wget https://github.com/jingweno/ccat/releases/download/v1.1.0/linux-amd64-1.1.0.tar.gz -------------- On 32-Bit -------------- # wget https://github.com/jingweno/ccat/releases/download/v1.1.0/linux-386-1.1.0.tar.gz 

After archive download completes, list the current working directory to show the files, extract the ccat tarball (the linux-amd64-1.x.x Tarball file) and copy the ccat executable binary from the extracted tarball into a Linux executable system path, such as /usr/local/bin/ path, by issuing the below commands.

# ls
# tar xfz linux-amd64-1.1.0.tar.gz # ls linux-amd64-1.1.0
# cp linux-amd64-1.1.0/ccat /usr/local/bin/
# ls -al /usr/local/bin/
ccat Command Executable Files

ccat Command Executable Files


If for some reasons the ccat file from your executable system path has no executable bit set, issue the below command to set executable permissions for all system users.

# chmod +x /usr/local/bin/ccat

In order to test ccat utility capabilities against a system configuration file, issue the below commands. The content of the displayed files should be highlighted according to file programming language sytnax, as illustrated in the below command examples.

# ccat /etc/sysconfig/network-scripts/ifcfg-ens33 # ccat /etc/fstab 
ccat Command Usage

ccat Command Usage

In order to replace cat command with ccat command system wide, add a bash alias for ccat in system barshrc file, log out from the system and log in back again to apply the configuration.

-------------- On CentOS, RHEL & Fedora -------------- # echo "alias cat='/usr/local/bin/ccat'" >> /etc/bashrc # exit
-------------- On Debiab & Ubuntu -------------- # echo "alias cat='/usr/local/bin/ccat'" >> /etc/profile
# exit

Finally, run cat command against an arbitrary configuration file to test if ccat alias has replaced cat command, as shown in the below example. The output file syntax should be highlighted now.

# cat .bashrc
Replace cat Command with ccat

Replace cat Command with ccat

ccat utility can also be used to concatenate multiple files and display the output in HTML format, as illustrated in the below example.

# ccat --html /etc/fstab /etc/sysconfig/network-scripts/ifcfg-ens33> /var/www/html/ccat.html

However, you will need a web server installed in your system, such as Apache HTTP server or Nginx, to display the content of the HTML file, as illustrated in the below screenshot.

Display File Content in HTML

Display File Content in HTML

For other custom configurations and command options visit ccat official github page.

How to Run Multiple Websites with Different PHP Versions in Nginx

Sometimes PHP developers want to build and run different websites/applications using different versions of PHP on the same web server. As a Linux system administrator, you are required to setup a environment where you can run multiple websites using different PHP version on a single web server i.e. Nginx.

In this tutorial, we will explain you how to install multiple versions of PHP and configure the web server Nginx to work with them via the server blocks (virtual hosts in Apache) in CentOS/RHEL 7 distributions using LEMP stack.

Nginx uses PHP-FPM (stands for FastCGI Process Manager), which is an alternative PHP FastCGI implementation with some extra, useful features for heavily loaded websites.

Testing Environment Setup

  1. A CentOS 7 or RHEL 7 server with minimal installation.
  2. Nginx HTTP Server.
  3. PHP 7.1 (to be used as default version) and 5.6.
  4. MariaDB Database Server.
  5. Server IP address: 192.168.56.10.
  6. Websites: example1.com and example2.com.

Step 1: Installing and Enabling EPEL and Remi Repository

1. First start by installing and enabling the EPEL and Remi repository, which offers the latest versions of the PHP stack on CentOS/RHEL 7 distributions.

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


2. Next install the yum-utils package, which extends yum’s native functionalities and provides yum-config-manager command, which is used to enable or disable Yum repositories on the system.

# yum install yum-utils

Note: On RHEL 7 you can enable the optional channel for some dependencies using the following command.

# subscription-manager repos --enable=rhel-7-server-optional-rpms

Step 2: Installing Nginx Web Server

3. To install latest version of Nginx, we need to add the official Nginx repository, create a file named /etc/yum.repos.d/nginx.repo.

# vi /etc/yum.repos.d/nginx.repo

Add the following lines to file as per your distribution.

--------------- On CentOS 7 --------------- [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1 --------------- On RHEL 7 ---------------
[nginx] name=nginx repo baseurl=http://nginx.org/packages/rhel/7.x/$basearch/ gpgcheck=0 enabled=1 

4. Once nginx repo has been added, you can install Nginx using yum package manager tool as shown.

# yum install nginx

Step 3: Installing MariaDB Database Server

5. To install latest version of MariaDB, we need to add the official MariaDB repository, create a file named /etc/yum.repos.d/mariadb.repo.

# vi /etc/yum.repos.d/mariadb.repo

Add the following lines to file as per your distribution.

--------------- On CentOS 7 --------------- [mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
--------------- On RHEL 7 ---------------
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2/rhel7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1 

6. Once MariaDB repo has been added, you can install MariaDB using yum package manager tool as shown.

# yum install MariaDB-client MariaDB-server

7. Afterwards, secure the database server installation using the script below. Set a root password and answer y and press [Enter] for the rest of the subsequent questions to disable remote root user login, remove anonymous-user accounts and test database which by default can be accessed by all users, even anonymous users.

# mysql_secure_installation

Read Also: 12 MySQL/MariaDB Security Best Practices for Linux

Step 4: Installing Multiple Versions of PHP

8. To install different versions of PHP for your projects, use yum-config-manager command to install multiple versions of PHP along with most required modules as shown.

Install PHP 7.1 Version

# yum-config-manager --enable remi-php71 [Default]
# yum install php php-common php-fpm
# yum install php-mysql php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml php-pecl-apc php-cli php-pear php-pdo

Install PHP 5.6 Version

# yum install php56 php56-php-common php56-php-fpm
# yum install php56-php-mysql php56-php-pecl-memcache php56-php-pecl-memcached php56-php-gd php56-php-mbstring php56-php-mcrypt php56-php-xml php56-php-pecl-apc php56-php-cli php56-php-pear php56-php-pdo

9. Once installed PHP, you can use following command to check the default version of PHP used on your server.

# php -v
Check Default PHP Version

Check Default PHP Version

Step 5: Configuring PHP-FPM and PHP56-PHP-FPM

10. This is the most interesting part of this tutorial, it explains how you can actually run multiple PHP versions on your server. Here, you will configure the different versions of php-fpm that Nginx will work with. You should define the user/group of the FastCGI processes as well as the ports they will listen on.

These are the following two configuration files that you will going to edit.

  • php-fpm (default 7.1) – /etc/php-fpm.d/www.conf
  • php56-php-fpm – /opt/remi/php56/root/etc/php-fpm.d/www.conf

Open the files above, set the user/group of FastCGI processes.

# vi /etc/php-fpm.d/www.conf [PHP 7.1]
# vi /opt/remi/php56/root/etc/php-fpm.d/www.conf [PHP 5.6] 

The default values should be apache, change them to nginx as shown.

user = nginx
group = nginx

11. Next, find the listen parameters, and define the address:port on which FastCGI requests will be received.

listen = 127.0.0.1:9000 [php-fpm]
listen = 127.0.0.1:9001 [php56-php-fpm]

12. Once all the above configuration done, you need to start and enable Nginx, MariaDB and PHP-FPM to auto-start at system boot.

# systemctl enable nginx # systemctl start nginx # systemctl enable mariadb # systemctl start mariadb ---------------- PHP 7.1 ---------------- # systemctl enable php-fpm # systemctl start php-fpm ---------------- PHP 5.6 ----------------
# systemctl enable php56-fpm # systemctl start php56-php-fpm 

Attention: In case you get any errors while starting the second instance of PHP, php56-php-fpm, a SELinux policy could be blocking it from starting. If SELinux is in enforcing mode, set it to permissive mode, then try starting the service once again.

# getenforce
# setenforce 0 

Step 6: Setup Websites with Permissions

13. At this point, you can now create the necessary directories for your websites under /var/www/html/. You also need to create directories to store logs as follows:

---------------- Website 1 ----------------
# mkdir -p /var/www/html/example1.com/ # mkdir -p /var/www/html/example2.com/ ---------------- Website 2 ----------------
# mkdir -p /var/log/nginx/example1.com/ # mkdir -p /var/log/nginx/example2.com/ 

14. Set the appropriate ownership permissions on all the directories.

---------------- Website 1 ----------------
# chown -R root:nginx /var/www/html/example1.com/ # chmod -R 755 /var/www/html/example1.com/ # chown -R root:nginx /var/log/nginx/example1.com/
# chmod -R 660 /var/log/nginx/example1.com/ ---------------- Website 2 ----------------
# chown -R root:nginx /var/www/html/example2.com/ # chmod -R 755 /var/www/html/example2.com/
# chown -R root:nginx /var/log/nginx/example2.com/ # chmod -R 660 /var/log/nginx/example2.com/

Step 7: Setup Nginx Server Blocks for Websites

15. Now configure how Nginx will process requests to your websites using the server block configuration files which should be located in /etc/nginx/conf.d/.

Create the configuration files for your websites ending with .conf extension.

# vi /etc/nginx/conf.d/example1.com.conf
# vi /etc/nginx/conf.d/example2.com.conf

Then paste the following server block configurations in the respective files.

Website 1

Configuration for example1.com

server {
listen 80;
server_name example1.com www.example1.com;
root /var/www/html/example1.com/;
index index.php index.html index.htm;
#charset koi8-r;
access_log /var/log/nginx/example1.com/example1_access_log;
error_log /var/log/nginx/example1.com/example1_error_log error;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root /var/www/html/example1.com/;
fastcgi_pass 127.0.0.1:9000; #set port for php-fpm to listen on
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include /etc/nginx/fastcgi_params;
}
}

Website 2

Configuration for example2.com

server {
listen 80;
server_name example2.com www.example2.com;
root /var/www/html/example2.com/;
index index.php index.html index.htm;
#charset koi8-r;
access_log /var/log/nginx/example2.com/example2_access_log;
error_log /var/log/nginx/example2.com/example2_error_log error;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root /var/www/html/example2.com/;
fastcgi_pass 127.0.0.1:9001; #set port for php56-php-fpm to listen on
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include /etc/nginx/fastcgi_params;
}
}

16. Make sure that you have the following line in the closing part of the http block in /etc/nginx/nginx.conf. It helps to include all configuration files inside the /etc/nginx/conf.d/ directory when Nginx is running.

include /etc/nginx/conf.d/*.conf;

Step 8: Testing Different PHP Versions

17. Finally, you need to test that your server is using the two versions of PHP. You can create a very basic info.php script in the document root directories of your websites as shown.

# echo "<?php phpinfo(); ?>" > /var/www/html/example1.com/info.php
# echo "<?php phpinfo(); ?>" > /var/www/html/example2.com/info.php

18. To apply all the changes you have made above, you need to restart Nginx, php-fpm and php56-php-fpm. But you can first of all check that the Nginx configuration files for any syntax errors before doing so.

# nginx -t # systemctl restart nginx php-fpm php56-php-fpm
Verify Nginx Configuration

Verify Nginx Configuration

19. There is one other last thing to do, especially if you are running your server locally, you need to setup local DNS using /etc/hosts file as shown in the screen shot below.

192.168.56.10 example1.com example1
192.168.56.10 example2.com example2
Add Websites to-Hosts File

Add Websites to-Hosts File

20. Finally, open a web browser and type the following addresses to verify the versions of PHP installed on the system.

http://example1.com/index.php
http://example2.com/index.php
Check PHP 7.1 Version

Check PHP 7.1 Version

Check PHP 5.6 Version

Check PHP 5.6 Version

That’s It! Now you can deploy files and test websites with different PHP versions. If you have any additions to make or questions to put forward, make use of the comment form below.

How to Find a Specific String or Word in Files and Directories

Do you want to find all files that contain a particular word or string of text on your entire Linux system or a given directory. This article will guide you on how to do that, you will learn how to recursively dig through directories to find and list all files that contain a given string of text.

A simple way to work this out is by using grep pattern searching tool, is a powerful, efficient, reliable and most popular command-line utility for finding patterns and words from files or directories on Unix-like systems.

Read Also: 11 Advanced Linux ‘Grep’ Commands on Character Classes and Bracket Expressions

The command below will list all files containing a line with the text “check_root”, by recursively and aggressively searching the ~/bin directory.

$ grep -Rw ~/bin/ -e 'check_root'
Find a Word in Directory

Find a Word in Directory


Where the -R option tells grep to read all files under each directory, recursively, following symbolic links only if they are on the command line and option -w instructs it to select only those lines containing matches that form whole words, and -e is used to specify the string (pattern) to be searched.

You should use the sudo command when searching certain directories or files that require root permissions (unless you are managing your system with the root account).

 $ sudo grep -Rw / -e 'check_root' 

To ignore case distinctions employ the -i option as shown:

$ grep -Riw ~/bin/ -e 'check_root'

If you want to know the exact line where the string of text exist, include the -n option.

$ grep -Rinw ~/bin/ -e 'check_root'
Find String with Line Number

Find String with Line Number

Assuming there are several types of files in a directory you wish to search in, you can also specify the type of files to be searched for instance, by their extension using the --include option.

This example instructs grep to only look through all .sh files.

$ grep -Rnw --include=\*.sh ~/bin/ -e 'check_root'

In addition, it is possible to search for more than one pattern, using the following command.

$ grep -Rinw ~/bin/ -e 'check_root' -e 'netstat'
Find Multiple Words in Files

Find Multiple Words in Files

That’s It! If you know any other command-line trick to find string or word in files, do share with us or ask any questions regarding this topic, use the comment form below.

Testssl.sh – Testing TLS/SSL Encryption Anywhere on Any Port

testssl.sh is a free and open source, feature-rich command line tool used for checking TLS/SSL encryption enabled services for supported ciphers, protocols and some cryptographic flaws, on Linux/BSD servers. It can be run on MacOS X and Windows using MSYS2 or Cygwin.

Features of Testssl.sh

  • Easy to install and use; produces clear output.
  • Highly flexible, it can be used to check any SSL/TLS enabled and STARTTLS services.
  • Perform a general check or single checks.
  • Comes with several command line options for various categories of single checks.
  • Supports different output types, including colored output.
  • Supports SSL Session ID check.
  • Supports checking for multiple server certificates.
  • Offers absolute privacy, it’s only you who can sees the result, not a third party.
  • Supports logging in (flat) JSON + CSV format.
  • Supports mass testing in serial (default) or parallel modes.
  • Supports presetting of command line options via environment variables, and so much more.

Important: You should be using bash (which comes preinstalled on almost Linux distributions) and a newer OpenSSL version (1.0) is recommended for effective usage.

How to Install and Use Testssl.sh in Linux

You can install testssl.sh by cloning this git repository as shown.

# git clone --depth 1 https://github.com/drwetter/testssl.sh.git
# cd testssl.sh

After cloning testssl.sh, the general use case is probably just run the following command to run a test against a website.

# ./testssl.sh https://www.google.com/
Test SSL TLS Encryption

Test SSL TLS Encryption


To run a check against STARTTLS enabled protocols: ftp, smtp, pop3, imap, xmpp, telnet, ldap, postgres, mysql, use the -t option.

# ./testssl.sh -t smtp https://www.google.com/

By default, all mass tests are done in serial mode, you can enable parallel testing using the --parallel flag.

# ./testssl.sh --parallel https://www.google.com/

If you do not want to use the default system openssl program, use the –openssl flag to specify an alternative.

# ./testssl.sh --parallel --sneaky --openssl /path/to/your/openssl https://www.google.com/

You might want to keep logs for later analysis, testssl.sh has the --log (store log file in the current directory) or --logfile (specify log file location) option for that.

# ./testssl.sh --parallel --sneaky --logging https://www.google.com/

To disable DNS lookup, which can increase test speeds, use the -n flag.

# ./testssl.sh -n --parallel --sneaky --logging https://www.google.com/

Run Single Checks Using testssl.sh

You can also run single checks for protocols, server defaults, server preferences, headers, various types of vulnerabilities plus many other tests. There are a number of options provided for this.

For example, the -e flag enables you to check each local cipher remotely. If you want to make the test much faster, use include the --fast flag; this will omit some checks, in case you are using openssl for all ciphers, it only displays the first proffered cipher.

# ./testssl.sh -e --fast --parallel https://www.google.com/

The -p option allows for testing TLS/SSL protocols (including SPDY/HTTP2).

# ./testssl.sh -p --parallel --sneaky https://www.google.com/

You can view the server’s default picks and certificate using the -S option.

# ./testssl.sh -S https://www.google.com/

Next, to see the server’s preferred protocol+cipher, use the -P flag.

# ./testssl.sh -P https://www.google.com/

The -U option will help you test all vulnerabilities (if applicable).

# ./testssl.sh -U --sneaky https://www.google.com/

Unfortunately, we can not exploit all the options here, use the the command below to see a list of all options.

# ./testssl.sh --help

Find more at testssl.sh Github repository: https://github.com/drwetter/testssl.sh

Conclusion

testssl.sh is a useful security tool that every Linux system administrator needs to have and use for testing TSL/SSL enabled services. If you have any questions or thoughts to share, use the comment form below. In addition, you can also share with us any similar tools, that you have come across out there.

How to Run Multiple Commands on Multiple Linux Servers

If you are managing multiple Linux servers, and you want to run multiple commands on all the Linux servers, but you have no idea about how to do it. There is no need to worry, in this simple server management guide, we will show you how to run multiple commands on multiple Linux servers simultaneously.

To achieve, this you can use the pssh (parallel ssh) program, a command line utility for executing ssh in parallel on a number of hosts. With it, you can send input to all of the ssh processes, from a shell script.

Requirements

  1. Install Pssh to Run Commands on Multiple Remote Linux Servers
  2. You must be using SSH passwordless authentication for all remote servers.

Create a Shell Script

Therefore, you need to start by preparing a script which contains the Linux commands you want to execute on the different servers. In this example, we will write a script that will collect the following information from multiple servers:

  • Check uptime of servers
  • Check who is logged on and what they are doing
  • List top 5 running processes according to memory usage.

First create a script called commands.sh with your favorite editor.

# vi commands.sh


Next, add the following commands to the script as shown.

#!/bin/bash ###############################################################################
#Script Name : commands.sh #Description : execute multiple commands on multiple servers #Author : Aaron Kili Kisinga #Email : [email protected] ################################################################################
echo
# show system uptime
uptime
echo
# show who is logged on and what they are doing
who
echo
# show top 5 processe by RAM usage ps -eo cmd,pid,ppid,%mem,%cpu --sort=-%mem | head -n 6
exit 0

Save the file and close it. Then make the script executable as shown.

# chmod +x commands.sh

Create PSSH Hosts File

Next, add the list of servers that you want to run the commands on, in a hosts.txt file, in the format [[email protected]]host[:port] or simply give the server IP addresses.

But we suggest you use ssh aliases which can be specified in .ssh/config file as explained in how to configure custom ssh connections to simplify remote access.

This method is more efficient and reliable, it allows you to specify configuration options (such as host name, identify file, port, username etc..) for each remote server.

Following is our sample ssh hosts aliases file a.k.a user specific ssh configuration file.

# vi ~/.ssh/config
SSH Hosts Aliases File

SSH Hosts Aliases File

Next, create a hosts.txt file, here you can simply specify the aliases (names defined using Host keyword in .ssh/config file) as shown.

# vi hosts.txt 

Add the server aliases.

server1
server2
server3

Run Commands via a Script on Multiple Linux Servers

Now run the following pssh command by specifying hosts.txt file along with the script that contains multiple commands to run on multiple remote servers.

# pssh -h hosts.txt -P -I<./commands.sh

Meaning of the flags used in the above command:

  • -h – reads the hosts file.
  • -P – tells pssh to display output as it arrives.
  • -I – reads input and sends to each ssh process.
Run Multiple Commands On Remote Servers

Run Multiple Commands On Remote Servers

That’s It! In this article, we showed how to execute multiple commands on multiple servers in Linux. You can share any thoughts relating to this topic via the comment section below.