Categories
Tutorial

Keep last N lines of a log file with Cron

If you wish to keep last (bottom) N lines of a log file and delete the older lines, you can use this command with Cron:

echo "$(tail -100 /home/home/public_html/log.txt)" > /home/home/public_html/log.txt

Categories
Tutorial

How to add swap on CentOS 7

If your vps does not come with swap, you can easily add swap to centos 7 following this guide: https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-centos-7

Categories
Solution

Failed loading plugin “osmsplugin”: No module named ‘librepo’ – Oracle Cloud

On a CentOS installation over Oracle Cloud, when running yum or dnf, you may get the error: Failed loading plugin “osmsplugin”: No module named ‘librepo’

To fix this error install the python3-librepo package with:
sudo dnf install python3-librepo

Categories
Tutorial

How to get visitor ip on cPanel NGINX Reverse Proxy with PHP

If you are using cPanel NGINX Reverse Proxy setup you may notice PHP $_SERVER['REMOTE_ADDR'] is returning server main IP address instead of visitor IP address.

To get visitor IP address use $_SERVER['HTTP_X_REAL_IP']

Source: https://stackoverflow.com/questions/44145688/remote-addr-ip-from-user-instead-of-nginx-reverse-proxy-server

Categories
Tutorial

Change Server Timezone in Linux

How to change server time zone in linux:
https://linuxize.com/post/how-to-set-or-change-timezone-in-linux/

Check Timezone: timedatectl

Set Timezone: timedatectl set-timezone <your_time_zone>
Example: timedatectl set-timezone Asia/Dhaka

Categories
Tutorial

ioping-1.1-1.el7.x86_64.rpm – ioping for CentOS 7

Download ioping-1.1-1.el7.x86_64.rpm (ioping for CentOS 7):
https://rpmfind.net/linux/epel/7/x86_64/Packages/i/ioping-1.1-1.el7.x86_64.rpm

Download ioping for CentOS 7
CentOS7 ioping rpm download

Categories
Tutorial

How to Set or Change Hostname in CentOS 7/8

To set or change hostname on CentOS 7/8 use the command:
hostnamectl set-hostname your-new-hostname

Check your hostname:
hostnamectl or hostname

Categories
Solution

[fix] At least xMB more space needed on the /boot filesystem

How to fix: At least xMB more space needed on the /boot filesystem:
https://haydenjames.io/fix-least-xmb-space-needed-boot-filesystem/

Categories
Solution

[solution] cmake 3.1 or higher is required. you are running version 2.8

If you are getting the error “cmake 3.1 or higher is required. you are running version 2.8” while trying to compile znc or something else on CentOS, follow the solution given here to upgrade your cmake from cmake 2 to cmake 3:
https://stackoverflow.com/a/59689105

If you get the error “Cannot find a C++ compiler that supports both C++11 and the specified C++ flags.” while compiling cmake, you can try installing cmake 3.9.6 instead of the latest
https://github.com/Kitware/CMake/releases/download/v3.9.6/cmake-3.9.6.tar.gz

If cmake --version gives you error:
-bash: /usr/bin/cmake: No such file or directory
run hash -r and then check again.

Issues covered over this solution:
cmake 3.1 or higher is required. you are running version 2.8.12.2
Cannot find a C++ compiler that supports both C++11 and the specified C++ flags.
-bash: /usr/bin/cmake: No such file or directory

Categories
Solution

[solution] Unable to bind: Address already in use

When trying to run an app if you are getting the error “Unable to bind: Address already in use”, you can use this command on linux to check which process is already using that port:

netstat -tulpn

Then you can kill the process with:

kill <pid>

If you are on windows you can check the port usage with:

netstat -a -o -n

And kill process on windows with:

taskkill /F /PID <pid>