Published January 25, 2018 by

Disable Directory Listing in Apache

If our website document directory does not have an index file, that time the Apache web server will show all the files and folder of the document root directory. Like as below image.

This feature could be turned off for a specific directory through 'options directive' available in the Apache configuration file.

Edit apache virtual host file.

# vim /etc/httpd/conf/httpd.conf                   ## for centos/redhat
# vim /etc/apache2/apache2.conf                  ## for ubuntu/debian

Add following line into virtual host file

<Directory /var/www/html>
    Options -Indexes
</Directory>

Restart Apache

# service httpd restart                                           ## for centos/redhat
# systemctl restart apache2                           ## for ubuntu/debian

Now apache shows /index of look like this:


Read More
Published January 25, 2018 by

Turn off shows Apache version, OS and Port information at 404 not found

Apache displays its version, Server OS and Port Number where any page not found in websites.

In order to prevent Apache web server from displaying this information, we have to modify 'server signature' available in the Apache configuration file.

We have also set 'ServerTokens Prod' that tells the web server to return the only apache and suppress the OS major and minor version

Edit apache virtual host file.

# vim /etc/httpd/conf/httpd.conf                   ## for centos/redhat
# vim /etc/apache2/apache2.conf                  ## for ubuntu/debian

Add following line into virtual host file

ServerSignature Off
ServerTokens Prod

Restart Apache

# service httpd restart                                           ## for centos/redhat
# systemctl restart apache2                           ## for ubuntu/debian

Now apache shows 404 page not found look like this:

Read More
Published January 25, 2018 by

Run Multiple Websites on Single Server (Apache) - Name Based Virtual Host

Using Apache Name Based Virtual host we can run multiple websites on a single server.
Point your both domains to your server's public IP.

In order to configure name-based virtual hosting, you have to set the IP address on which you are going to receive the Apache requests for all the desired websites.  You can do this by NameVirutalHost directive within the Apache configuration file /etc/httpd/conf/httpd.conf file.

File excerpt: /etc/httpd/conf/httpd.conf

<VirtualHost 192.168.0.30:80>
ServerAdmin webmaster@serverkaka1.com
DocumentRoot /var/www/html/serverkaka1     
ServerName www.serverkaka1.com
</VirtualHost>

<VirtualHost 192.168.0.30:80>
ServerAdmin admin@serverkaka2.com
DocumentRoot /var/www/html/serverkaka2
ServerName www.serverkaka2.com
</VirtualHost>

Now, Restart Apache and Test.

# service httpd restart
Read More
Published January 24, 2018 by

Redirect IP to Domain Name in Apache

Sometimes we host website or application on Apache on Linux. After hosting, we hit URL: www.mydomain.com so it's working fine. But when I hit server IP that time also it's working. But not redirect to www.mydomain.com

So today We set IP to Domain Redirection in Apache. Using RewriteEngine rule.

IP to Domain Name Redirect

Insert following code into your <VirtualHost *:80> file. and replace highlighted text with your IP and domain name.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^34\.239\.44\.197$
RewriteRule ^(.*)$ http://www.serverkaka.com/$1 [L,R=301]

Enable RewriteEngine

# sudo a2enmod rewrite

Restart Apache

# sudo service apache2 restart
Read More
Published January 23, 2018 by

Crontab in Linux with Examples to Schedule Jobs

Crontab

A software utility to a Linux operating system or server for a job that is to be executed at a specified time.

A Linux system admin knows the importance of running the routine maintenance jobs in the background automatically. Linux Cron utility is an effective way to schedule a routine background job at a specific time and/or day on an on-going basis.

Often, you will want to use cron to schedule daily, weekly, hourly etc... tasks on your Linux system. Ok, so cron is what is used on your Linux system to schedule repeating events. It’s used to rotate logs, run clean-up scripts, and anything else you can think of that you’d want to schedule.

To View Crontab

# crontab -l

To Edit Crontab

# crontab -e

Edit another user's crontab

# crontab -u serverkaka -e

View another user's crontab

# crontab -u serverkaka -l

Crontab Format

Minute        Hour        DOM        Month        DOW        Command

Field
Allowed Values
Minute
0 – 59
Hour
0 – 23
Day of month
1 – 31
Month
1 – 12
Day of week
0 – 7

String
Crontab Value
Yearly
0 0 1 1 *
Monthly
0 0 1 * *
Weekly
0 0 * 0 0
Daily
0 0 * * *
Hourly
0 * * * *

Example

Minute
Hour
Day of Month
Month
Day of Week
Command
0 – 59
0 – 23
1 – 31
1 – 12
0 – 6

     0             15                    *                      *                     *               /root/backup.sh

This crontab executes the "/root/backup.sh" script at 3 PM on every day.

Some Another Example

0 23 * * * /root/backup.sh
This Script run at everyday 11:00 PM

0 11,23 * * * /root/backup.sh
This Script run at everyday 11:00 AM and 11:00 PM

0 7 * * 0 /root/backup.sh
This Script run at every Sunday morning 7 AM

0 7 * 5 6 /root/backup.sh
This Script run at every Saturday of May month at morning 7 AM

15 7 * 5 6 /root/backup.sh
This Script run at every Saturday of May month at morning 7:15 AM

* * * * * /root/backup.sh
This Script run at every minutes

*/5 * * * * /root/backup.sh
This Script run at every 5 minutes

0 17 * * 1,5 /root/backup.sh
This Script run at every 5:00 PM at Monday and Friday

*/5 * * * * /root/backup.sh
This Script run at every 5 minutes

0 */5 * * * /root/backup.sh
This Script run at every 5 hours

* * * * * sleep 30; /root/backup.sh
This Script run at every 30 seconds

0 * * * * /root/backup.sh
OR
@hourly /root/backup.sh
This Script run at every hour

0 0 * * * /root/backup.sh
OR
@daily /root/backup.sh
This Script run at daily

0 0 * 0 0 /root/backup.sh
OR
@weekly /root/backup.sh
This Script run at every week

0 0 1 * * /root/backup.sh
OR
@monthly /root/backup.sh
This Script run at every month

0 0 1 1 * /root/backup.sh
OR
@yearly /root/backup.sh
This Script run at every year

Also, You can run multiple scripts or command in one crontab using (;) semicolumn.

0 0 * * * /root/backup.sh; /home/script.sh
This Script run at daily

Also, You can run script on system reboot

@reboot /root/backup.sh
This Script run on every system reboot
Read More
Published January 22, 2018 by

Install GitLab on CentOS 7

Gitlab is web GUI based manager for git repositories with support for CI\CD, issue tracking & wiki. Gitlab provides easy to use commands & controls for the git repositories, we can easily create new git repositories, manage them & all that using a nice graphical interface. With Gitlab, we can make our repositories completely private or can also allow public access over LAN or over the internet.

Versions of Gitlab:
  • Gitlab CE ( Community Edition )    ##This is the free version.
  • Gitlab EE (Enterprise Edition)        ##This is paid version.
Install GitLab CE

Update System And Set Firewall

# sudo yum update
sudo yum install -y curl policycoreutils-python openssh-server
# sudo systemctl enable sshd
# sudo systemctl start sshd
# sudo firewall-cmd --permanent --add-service=http
# sudo systemctl reload firewalld

Install Postfix to send notification emails


sudo yum install postfix
# sudo systemctl enable postfix
# sudo systemctl start postfix

Enable mail sending

# yum install mailx

Setup Gitlab Reposotiry

# curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash

Install GitLab Package

Change the highlighted text in command to the URL at which you want to access your GitLab Server. And please wait sometimes it takes time approx 30 minutes (depending on internet speed). 

# sudo EXTERNAL_URL="http://gitlab.serverkaka.com" yum install -y gitlab-ee

Access GitLab

Go to browser and hit URL: localhost or server_ip or gitlab.serverkaka.com


It asks for change password set your GitLab password and login. Remeber by default your username is root


After successful login, you can access GitLab

Read More
Published January 22, 2018 by

Install GitLab on Ubuntu/Debian

Gitlab is web GUI based manager for git repositories with support for CI\CD, issue tracking & wiki. Gitlab provides easy to use commands & controls for the git repositories, we can easily create new git repositories, manage them & all that using a nice graphical interface. With Gitlab, we can make our repositories completely private or can also allow public access over LAN or over the internet.

Versions of Gitlab:
  • Gitlab CE ( Community Edition )    ##This is the free version.
  • Gitlab EE (Enterprise Edition)        ##This is paid version.
Install GitLab CE

Update System

# sudo apt-get update
# sudo apt-get install -y curl openssh-server ca-certificates

Install Postfix to send notification emails


# sudo apt-get install postfix -y


Select Internet Site  and Hit <Ok>


Give System mail name or and hit <OK>

Enable mail sending

# sudo apt-get install mailutils

Setup Gitlab Reposotiry

# curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash

Install GitLab Package

Change the highlighted text in command to the URL at which you want to access your GitLab Server. And please wait sometimes it takes time approx 30 minutes (depending on internet speed). 

# sudo EXTERNAL_URL="http://gitlab.serverkaka.com" apt-get install gitlab-ee

Access GitLab

Go to browser and hit URL: localhost or server_ip or gitlab.serverkaka.com


It asks for change password set your GitLab password and login. Remeber by default your username is root


After successful login, you can access GitLab


Read More
Published January 21, 2018 by

Useful Basic Linux Command

Here is some basic Linux command which can help you use more easily day to day Linux system.


Command
Description
ln
Create shortcut
Example:
# ln –s subhash.doc /root/serverkaka/
less
Open or view a plain text file in a viewer. Hit Q for quit
Example:
# less subhash.txt
df
Show amount of free disk space on all attached filesystems.
Example:
# df –h
free
Show amount of free memory.
Example:
# free –mt
‐t: Show totals column
‐g: Show output in gigabytes
‐m: Show output in megabytes
grep
Search through a specified file for a word or phrase. First, specify the word, and then the file to be searched through.
Example:
# grep –i serverkaka subhash.txt
‐i: Ignore upper/lowercase
man
View the manual page for a specified command.
Example:
# man ls
vim
Simple text editor. Hit  Esc +:wq for saving.
Example:
# vim /root/Subhash.txt
locate
Find specified file
Example:
# locate -i subhash.doc
‐i: Ignore upper/lowercase when searching
ls
List files and folders.
Example:
# ls ‐l
‐l: show permissions, ownership etc...
‐a: Show including hidden files
‐h: Show in KB, MB etc...
cd
Change Directory.
Example:
# cd /root/
cp
Copy file or folder
Example:
# cp -r /root/subhash /opt/website/
-r: copy include sub file/folder
pwd
Show present work directory
Example:
# pwd
mv
Move file or folder. Also use for rename files/folders if a new destination is not specified.
Example (moving):
# mv /root/subhash.doc /opt/website/
Example (renaming):
# mv subhash.doc serverkaka.doc
rm
Delete file/folder
Example:
# rm -rf /root/subhash.doc
date
Show system current time and date
Example:
# date
su
Switch another user
Example:
# su subhash
Read More