Published February 08, 2019 by

Configure GitHub Webhook in Jenkins Job

In this tutorial, we will learn how to Jenkins automatically create a build if it detects changes to a GitHub repository.

GitHub webhooks feature in Jenkins is used to trigger the build whenever a developer commits something to the master branch.


Read More
Published February 02, 2019 by

AWS S3 LifeCycle rules for moving data from S3 to Glacier

In this tutorial, we learn how do you move your data from Amazon S3 to Glacier? Using Lifecycle Policies. These policies are basically just rules that you can set up to move the data from S3 to Glacier at specific times. Let’s learn how to create a Lifecycle Policy.

Read More
Published January 01, 2019 by

Shell Script for Install NextCloud in Ubuntu

This post shows you how to install NextCloud on Ubuntu 16.04 LTS with Apache2, MySQL, and PHP. NextCloud is a fork of OwnCloud. Like DropBox and other cloud storage services, NextCloud and OwnCloud provide similar functions and unlike the others, they both are free to use.
This guide will show you how to install and set up Nextcloud on Ubuntu using a single shell script.

Before Install nextcloud make sure you are properly pointed DNS record with your IP address. 

Install NextCloud

What this script does:
  1. Install Apache Web server
  2. Install MySQL
  3. Install PHP
  4. Install Redis Server
  5. Install Nextcloud
  6. Install SSL certificate for your nextcloud server
For Install Nextcloud Create a file named nextcloud.sh
 sudo vim nextcloud.sh  
Insert Below script in a nextcloud.sh file and save.
 #!/bin/bash  
   
 # NextCloud Installation Script for Ubuntu  
 # with SSL certificate provided by Let's Encrypt (letsencrypt.org)  
 # Author: Subhash (serverkaka.com)  
   
 # Check if running as root  
 if [ "$(id -u)" != "0" ]; then  
   echo "This script must be run as root" 1>&2  
   exit 1  
 fi  
   
 datapath='/myData' # Path where user data is stored  
 read -p 'nextcloud_url [xx.xx or xx.xx.xx]: ' nextcloud_url  
 read -p 'nextcloud_version [x.x.x]: ' nextcloud_version  
 read -p 'letsencrypt_email [xx@xx.xx]: ' letsencrypt_email  
 read -p 'db_root_password [secretpasswd]: ' db_root_password  
 read -p 'db_user_password [passwd]: ' db_user_password  
 echo  
   
 # Check All variable have a value  
 if [ -z $nextcloud_url ]|| [ -z $nextcloud_version ] || [ -z $letsencrypt_email ]|| [ -z $db_root_password ] || [ -z $db_user_password ]  
 then  
    echo run script again please insert all value. do not miss any value  
 else  
     
 # Installation start  
   
 ocpath='/var/www/html' # Path where NextCloud is installed  
 htuser='www-data' # User Apache runs as  
 htgroup='www-data' # Group Apache runs as  
 rootuser='root'  
   
 # Update System  
 apt-get update  
   
 # Install Apache  
 apt-get install apache2 -y  
   
 # Disable directory listing  
 sudo sed -i "s/Options Indexes FollowSymLinks/Options FollowSymLinks/" /etc/apache2/apache2.conf  
   
 # Install PHP  
 sudo apt-get install php libapache2-mod-php php-common libapache2-mod-php php-mbstring php-xmlrpc php-soap php-apcu php-smbclient php-ldap php-redis php-gd php-xml php-intl php-json php-imagick php-mysql php-cli php-ldap php-zip php-curl -y  
   
 # Install Redis  
 apt-get install redis-server -y  
   
 # Install MySQL database server  
 export DEBIAN_FRONTEND="noninteractive"  
 debconf-set-selections <<< "mysql-server mysql-server/root_password password $db_root_password"  
 debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $db_root_password"  
 apt-get install mysql-server php-mysql -y  
   
 # Enable Apache extensions  
 a2enmod proxy_fcgi setenvif  
 a2enconf php-fpm  
 service apache2 reload  
 a2enmod rewrite  
 service apache2 reload  
   
 # Download Nextcloud and move to web directory  
 wget https://download.nextcloud.com/server/releases/nextcloud-$nextcloud_version.zip  
 apt-get install unzip -y  
 unzip nextcloud-$nextcloud_version.zip  
 cd nextcloud  
 mv * $ocpath  
 mv .* $ocpath   
   
 # Delete Downloaded File  
 cd ..  
 rm -rf nextcloud nextcloud-$nextcloud_version.zip  
   
 # Create data directory  
 mkdir -p $datapath  
   
 # Set file and folder permissions  
 printf "Creating possible missing Directories\n"  
 mkdir -p $ocpath/data  
 mkdir -p $ocpath/assets  
 mkdir -p $ocpath/updater  
   
 printf "chmod Files and Directories\n"  
 find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640  
 find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750  
   
 printf "chown Directories\n"  
 chown -R ${rootuser}:${htgroup} ${ocpath}/  
 chown -R ${htuser}:${htgroup} ${ocpath}/apps/  
 chown -R ${htuser}:${htgroup} ${ocpath}/assets/  
 chown -R ${htuser}:${htgroup} ${ocpath}/config/  
 chown -R ${htuser}:${htgroup} ${ocpath}/data/  
 chown -R ${htuser}:${htgroup} ${datapath}/  
 chown -R ${htuser}:${htgroup} ${ocpath}/themes/  
 chown -R ${htuser}:${htgroup} ${ocpath}/updater/  
 chown -R ${htuser}:${htgroup} /tmp  
 chmod +x ${ocpath}/occ  
   
 printf "chmod/chown .htaccess\n"  
 if [ -f ${ocpath}/.htaccess ]  
 then  
  chmod 0644 ${ocpath}/.htaccess  
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess  
 fi  
   
 if [ -f ${ocpath}/data/.htaccess ]  
 then  
  chmod 0644 ${ocpath}/data/.htaccess  
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess  
 fi  
   
 # Configure Apache  
 touch /etc/apache2/sites-available/nextcloud.conf  
 printf "<VirtualHost *:80>\n\nServerName ${nextcloud_url}\nAlias /nextcloud "/var/www/html/"\n\n<Directory /var/www/html/>\n Options +FollowSymlinks\n AllowOverride All\n\n<IfModule mod_dav.c>\n Dav off\n</IfModule>\n\nSetEnv HOME /var/www/html\nSetEnv HTTP_HOME /var/www/html\n\n</Directory>\n\n</VirtualHost>" > /etc/apache2/sites-available/nextcloud.conf  
 ln -s /etc/apache2/sites-available/nextcloud.conf /etc/apache2/sites-enabled/nextcloud.conf  
 a2enmod headers  
 a2enmod env  
 a2enmod dir  
 a2enmod mime  
 service apache2 reload  
   
 # Configure MySQL database  
 mysql -uroot -p$db_root_password <<QUERY_INPUT  
 CREATE DATABASE nextcloud;  
 CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY '$db_user_password';  
 GRANT ALL PRIVILEGES ON nextcloud.* TO nextclouduser@localhost;  
 FLUSH PRIVILEGES;  
 EXIT  
 QUERY_INPUT  
   
 # Enable NextCloud cron job every 15 minutes  
 crontab -u www-data -l > cron  
 echo "*/15 * * * * php -f /var/www/html/cron.php" >> cron  
 crontab -u www-data cron  
 rm cron  
   
 # Enable HTTPS with Let's Encrypt SSL Certificate   
 apt-get install git -y  
 cd /etc  
 git clone https://github.com/certbot/certbot  
 cd certbot  
 ./letsencrypt-auto --non-interactive --agree-tos --email $letsencrypt_email --apache -d $nextcloud_url --hsts  
 printf "<VirtualHost *:80>\n   ServerName $nextcloud_url\n   Redirect / https://$nextcloud_url/\n</VirtualHost>" > /etc/apache2/sites-enabled/nextcloud.conf  
 service apache2 reload  
 # Set up cron job for certificate auto-renewal every 90 days  
 crontab -l > cron  
 echo "* 1 * * 1 /etc/certbot/certbot-auto renew --quiet" >> cron  
 crontab cron  
 rm cron  
   
 # Install complete  
 printf "\n\nInstallation complete.\nNavigate to http://$nextcloud_url in a web browser to complete the setup wizard, before you run the optimization script.\n\n"  
 fi  


Give execute permission to nextcloud.sh file
 sudo chmod +x nextcloud.sh  

Finally, now run the nextcloud.sh file
 sudo ./nextcloud.sh  

After successfully script execute, Go to a browser and hit http://localhost/ OR http://your_domain_name

Please follow the wizard carefully.


Click Finish setup and you’re done.

After Successfully configure Nextcloud you need to performance tuning and optimize your nextcloud server. For this run below script.
 #!/bin/bash  
   
 # NextCloud Optimization Script  
 # with PHP Opcache and Redis Memcache  
 # Important: Do not run until the setup wizard in your browser is complete (has initialized the config.php file).  
 # Author: Subhash (serverkaka.com)  
   
 upload_max_filesize=4G # Largest filesize users may upload through the web interface  
 post_max_size=4G # Same as above  
 memory_limit=512M # Amount of memory NextCloud may consume  
 datapath='/data' # Path where user data is stored  
   
 # DO NOT EDIT BELOW THIS LINE  
   
 dirpath='/var/www/html' # Path where NextCloud is installed  
   
 # Check if running as root  
 if [ "$(id -u)" != "0" ]; then  
   echo "This script must be run as root" 1>&2  
   exit 1  
 fi  
   
 # Server Stop  
 service apache2 stop  
   
 # Enable PHP Opcache  
 cd /etc/php/7.2/apache2/  
 rm php.ini  
 wget https://s3.amazonaws.com/serverkaka-pubic-file/nextcloud/php.ini  
   
 # Enable Redis memory caching  
 sed -i '$i'"'"'memcache.local'"'"' => '"'"'\\OC\\Memcache\\Redis'"'"',''' ${dirpath}/config/config.php  
 sed -i '$i'"'"'memcache.locking'"'"' => '"'"'\\OC\\Memcache\\Redis'"'"',''' ${dirpath}/config/config.php  
 sed -i '$i'"'"'redis'"'"' => array('"\n""'"'host'"'"' => '"'"'localhost'"'"','"\n""'"'port'"'"' => 6379,'"\n"'),''' ${dirpath}/config/config.php  
   
 # Change the upload cache directory  
 # Makes it easier to exclude cache from rsync-style backups  
 sed -i '$i'"'"'cache_path'"'"' => '"'"${datapath}'/cache'"'"',''' ${dirpath}/config/config.php  
   
 # Change the PHP upload and memory limits  
   
 for key in upload_max_filesize post_max_size memory_limit  
 do  
 sed -i "s/^\($key\).*/\1=$(eval echo \${$key})/" ${dirpath}/.user.ini  
 done  
   
 # Server Start  
 service apache2 start  
   
 # Run OCC for DB optimization  
 cd /var/www/html/  
 echo y | sudo -u www-data php occ db:convert-filecache-bigint  
   
 printf "\n\nOptimization complete."  

Reference: https://github.com/SubhashPatel?tab=repositories
Read More
Published December 16, 2018 by

Install Redmine in Ubuntu using Shell Script


Redmine is a project management tool that allows users to manage projects flexibly while offering robust tracking tools and an extensive library of plug-ins. This free and open source solution offers an alternative to paid project management tools and includes support for wikis, forums, calendars, and data visualization tools.

This guide will show you how to install and set up Redmine on Ubuntu using a single shell script.


Install Redmine

What this script does:
  1. Install Apache Web server
  2. Install MySQL
  3. Install Redmine
For Install Redmine Create a file named redmine.sh
 sudo vim redmine.sh  

Insert Below script in a redmine.sh file and save.
 #!/bin/bash  
   
 #######################################  
 # Bash script to install a Redmine Project Management Tool in ubuntu  
 # Author: Subhash (serverkaka.com)  
   
 # Check if running as root  
 if [ "$(id -u)" != "0" ]; then  
   echo "This script must be run as root" 1>&2  
   exit 1  
 fi  
   
 # Check port 80 is Free or Not  
 netstat -ln | grep ":80 " 2>&1 > /dev/null  
 if [ $? -eq 1 ]; then  
    echo go ahead  
 else  
    echo Port 80 is allready used  
    exit 1  
 fi  
   
 # Ask value for mysql root password   
 read -p 'db_root_password [secretpasswd]: ' db_root_password  
 echo  
   
 # Update System  
 apt-get update  
   
 # Install Apache and mod-passenger  
 apt-get install apache2 libapache2-mod-passenger -y  
   
 # Install MySQL database server  
 export DEBIAN_FRONTEND="noninteractive"  
 debconf-set-selections <<< "mysql-server mysql-server/root_password password $db_root_password"  
 debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $db_root_password"  
 apt-get install mysql-server mysql-client -y  
 unset DEBIAN_FRONTEND  
   
 # Installing and configuring the Ubuntu Redmine package  
 apt-get install redmine redmine-mysql -y  
   
 # Install bundler gem  
 gem update  
 gem install bundler  
   
 # Configuring Apache  
 cd /etc/apache2/mods-available/   
 rm passenger.conf  
 wget https://s3.amazonaws.com/serverkaka-pubic-file/redmine/passenger.conf  
   
 # create a symlink to connect Redmine into the web document space  
 ln -s /usr/share/redmine/public /var/www/html/redmine  
   
 # Configuring Apache  
 cd /etc/apache2/sites-available/  
 rm 000-default.conf  
 wget https://s3.amazonaws.com/serverkaka-pubic-file/redmine/000-default.conf  
   
 # Create and set the ownership of a Gemfile.lock file so that apache's www-data user can access it  
 touch /usr/share/redmine/Gemfile.lock  
 chown www-data:www-data /usr/share/redmine/Gemfile.lock  
   
 # Adjust the Firewall  
 ufw allow 80/tcp  
   
 # Restart Apache  
 service apache2 restart  
   
 # Set auto start tomcat as a system boot  
 sudo systemctl enable apache2  
   
 echo "Redmine is successfully installed. For Access Redmine Go to http://localhost/redmine/  

Give execute permission to redmine.sh file
 sudo chmod +x redmine.sh  

Finally, now run the redmine.sh file
 sudo ./redmine.sh  

After successfully script execute, Go to a browser and hit http://localhost/redmine OR http://ip_address/redmine

For login press sign in button



When it asks for login and password provide default credentials. Your default login is admin and Password is also admin.


Now Redmine is ready to use.

Take Backup of Redmine

Below script is take auto backup for Redmine files and database
 #!/bin/bash  
   
 /usr/bin/mysqldump -u root -p<password> redmine_default | gzip > /path/to/backups/redmine_db_`date +%y_%m_%d`.gz  
 rsync -a /var/lib/redmine/default/files /path/to/backups/files  
Before run backup script, insert proper database password and Backup path.


Reference: https://github.com/SubhashPatel?tab=repositories
Read More
Published December 16, 2018 by

How to Increase EBS Volume Size of AWS EC2 Linux Instance

If we face data limitations in our EC2 instance's volume, we can modify or resize it.

In this tutorial, I will show you how to increase the EBS volume size in AWS using a Linux instance.

First, stop EC2 instance:


You can also perform this step in running instance without stopping it, but if possible to take downtime, then I suggest stopping the instance. 

Select instance>>Actions>>Insatnce State>>Stop

Read More
Published December 15, 2018 by

Install LAMP stack in Ubuntu using Shell Script


Read More
Published December 15, 2018 by

Install and Configure Latest WordPress in CentOS using Shell Script


Read More
Published December 15, 2018 by

Install and Configure Latest WordPress in Ubuntu using Shell Script

Read More