How To Install BIND9 DNS Server on Ubuntu Step by Step

BIND is a widely used DNS Server. Ideally, DNS server consist of 2 machines that work together simultaneously, one act as master and the other one act as slave. If your domain registrar doesn’t provide you a free DNS server, or if you want to create a custom DNS record, then you might need to host your own DNS server.

In this tutorial, we will learn how to install and configure BIND9 Master and Slave DNS server. Both server will use Ubuntu OS. We will start configuring the master then the slave.

Install BIND9 Master and Slave DNS Server on Ubuntu

Here are the servers example data:

Server1 (master) IP address: 108.100.100.1
Server2 (slave) IP address: 108.100.100.2
Domain: wpcademy.com
This domain will be hosted on this server: 192.168.100.07

ON MASTER

Step1. Update ubuntu repository and install Bind using apt-get.

apt-get update
apt-get install bind9

Step2. Configure bind options

*)do this if you haven't installed nano text editor: 
apt-get install nano

nano /etc/bind/named.conf.options
options {
	directory "/var/cache/bind";
	additional-from-auth no;
	additional-from-cache no;
	version "Bind Server";

	// If there is a firewall between you and nameservers you want
	// to talk to, you may need to fix the firewall to allow multiple
	// ports to talk.  See http://www.kb.cert.org/vuls/id/800113

	// If your ISP provided one or more IP addresses for stable 
	// nameservers, you probably want to use them as forwarders.  
	// Uncomment the following block, and insert the addresses replacing 
	// the all-0's placeholder.

	 forwarders {
	 	8.8.8.8;
		8.8.4.4;
	 };

	//========================================================================
	// If BIND logs error messages about the root key being expired,
	// you will need to update your keys.  See https://www.isc.org/bind-keys
	//========================================================================
	dnssec-validation auto;
	allow-recursion { 127.0.0.1; };
	auth-nxdomain no;    # conform to RFC1035
	listen-on-v6 { any; };
};

Step 3. Store the domain name and zone file setting

 nano /etc/bind/named.conf.local
//place these lines at the bottom of file

zone "wpcademy.com" {
        type master;
        file "/etc/bind/zones/wpcademy.com.db";
        allow-transfer { 108.200.200.2; };
        also-notify { 108.200.200.200.2; };
};

Step4. Because in the above config we put zone file in “/etc/bind/zones/wpcademy.com.db”, then we need to create the folder and file

mkdir /etc/bind/zones
nano /etc/bind/zones/wpcademy.com.db
$TTL    86400
$ORIGIN wpcademy.com.
@       IN      SOA     ns1.wpcademy.com. root.wpcademy.com. (
                              1         ; Serial
                          86400         ; Refresh
                           7200         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      ns1.wpcademy.com.
@       IN      NS      ns2.wpcademy.com.
ns1      IN      A       108.100.100.1
ns2      IN      A       108.100.100.2

;also list other computers
@       IN      A       192.168.100.07
www     IN      A       192.168.100.07

Step 5. (last step on master) Restart bind9 dns service

 service bind9 restart

ON SLAVE

Repeat step 1-2 similar to the master.

Step 3. Configure slave bind options

 nano /etc/bind/named.conf.options
zone "wpcademy.com" {
	type slave;
	file "/var/cache/bind/wpcademy.com.db";
	masters {108.100.100.1;};
};

notice the difference in this config file from the master.

Step 4. Restart bind9 service.

 service bind9 restart

What to do next?

This DNS server will not work until you change your domain’s nameserver. It can be done from your domain’s registrar website. In this scenario, we change nameserver to:

ns1.wpcademy.com
ns2.wpcademy.com

Testing BIND

This test could be done either on the DNS server itself or from another server, or from your own PC. In this case, we will do the test from another server running Ubuntu OS.

Step 1.Install dnsutils

 apt-get install dnsutils

Step 2. Do the dig dns test

 dig wpcademy.com

Step 3. Do the nslookup dns test

 nslookup wpcademy.com

How To Install and Configure Squid 3 on CentOS

Install and Configure Squid 3 on CentOS

Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. It runs on most available operating systems, including Windows and is licensed under the GNU GPL.

This article assumes you have at least basic knowledge of linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges.

In this tutorial we are going to learn how to install and configuration of Squid on your CentOS server.

Install and Configure Squid 3 on CentOS

Step 1. To install, first you must update yum repository and packages by typing the below command:

 #yum -y update

Step 2. Installing Squid 3.

Install squid package and dependencies using the below command :

 #yum -y install squid

Step 3. Configuration Squid.

Edit squid configuration file ‘/etc/squid/squid.conf’

 #nano /etc/squid/squid.conf
# Recommended minimum configuration:
auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/squid_passwd
acl ncsa_users proxy_auth REQUIRED
http_access allow ncsa_users

acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32
acl SSL_ports port 443
acl Safe_ports port 80        # http
acl Safe_ports port 21        # ftp
acl Safe_ports port 443        # https
acl Safe_ports port 1025-65535    # unregistered ports
acl Safe_ports port 280        # http-mgmt
acl Safe_ports port 488        # gss-http
acl Safe_ports port 591        # filemaker
acl Safe_ports port 777        # multiling http
acl CONNECT method CONNECT

http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access deny all
http_port 3128

hierarchy_stoplist cgi-bin ?
coredump_dir /var/spool/squid
cache deny all

refresh_pattern ^ftp:        1440    20%    10080
refresh_pattern ^gopher:    1440    0%    1440
refresh_pattern -i (/cgi-bin/|\?) 0    0%    0
refresh_pattern .        0    20%    4320

icp_port 3130

forwarded_for off

request_header_access Allow allow all
request_header_access Authorization allow all
request_header_access Proxy-Authorization allow all
request_header_access Proxy-Authenticate allow all
request_header_access Cache-Control allow all
request_header_access Content-Encoding allow all
request_header_access Content-Length allow all
request_header_access Content-Type allow all
request_header_access Date allow all
request_header_access Expires allow all
request_header_access Host allow all
request_header_access If-Modified-Since allow all
request_header_access Last-Modified allow all
request_header_access Location allow all
request_header_access Pragma allow all
request_header_access Accept allow all
request_header_access Accept-Charset allow all
request_header_access Accept-Encoding allow all
request_header_access Accept-Language allow all
request_header_access Content-Language allow all
request_header_access Mime-Version allow all
request_header_access Retry-After allow all
request_header_access Title allow all
request_header_access Connection allow all
request_header_access Proxy-Connection allow all
request_header_access User-Agent allow all
request_header_access Cookie allow all
request_header_access All deny all
visible_hostname wpcademy.com

Step 4. Create our authentication file which Squid can use to verify for user authentications:

 #htpasswd -b /etc/squid/squid_passwd username password

Example:

 #htpasswd -b -c /etc/squid/squid_passwd ranty ratna

Congratulation’s! You have successfully installed squid. Thanks for using this tutorial for installing squid proxy on CentOS system. For additional help or useful information, we recommend you to check the official squid web site.

You Might Also Like: How To Install Redis on Ubuntu 16.04 LTS

How to install Java on Ubuntu

How to install Java on Ubuntu

There are many programs and scripts that require java to run it, but usually Java is not installed by default on VPS/Dedicated Server. In this tutorial we are going to learn a simple step to install Java on your Ubuntu machine.

Java is at the heart of our digital lifestyle. It’s the platform for launching careers, exploring human-to-digital interfaces, architecting the world’s best applications, and unlocking innovation everywhere—from garages to global organizations.

Java technology allows you to work and play in a secure computing environment. Upgrading to the latest Java version improves the security of your system, as older versions do not include the latest security updates.

Java allows you to play online games, chat with people around the world, calculate your mortgage interest, and view images in 3D, just to name a few.

install Java on Ubuntu

First step, update apt-get repository

 apt-get update

Second step, install java run time

 apt-get install default-jre

Third step, install java development kit

 apt-get install default-jdk

Fourth step, check java installation

 java -version

Result:

java version "1.7.0_55"
OpenJDK Runtime Environment (IcedTea 2.4.7) (7u55-2.4.7-1ubuntu1)
OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)

OK that’s all for now the tutorial to install Java Runtime and Java Development Kit on Ubuntu.

Congratulation’s! You have successfully installed Java. Thanks for using this tutorial for installing Oracle Java on Ubuntu system. For additional help or useful information, we recommend you to check the official Java web site.

You Might Also Like: How To Install Oracle Java on Ubuntu 17.04

How To Reset Root Password on MySQL Server

Reset Root Password on MySQL Server

By default, MySQL server will be installed with root account and password is blank. Have you ever forgotten the root password on one of your MySQL servers? If you have set the password for root and forget it, then you will need to reset the root password for MySQL. To reset your mysql password just follow these instructions and we assume that you already have a small amount of knowledge on MySQL.

This article assumes you have at least basic knowledge of linux, know how to use the shell, and most importantly, you host your site on your own VPS. The reset password MySQL is quite simple. I will show you through the step by step reset root password MySQL server.

Reset Root Password MySQL Server

Step 1. First thing to do is stop MySQL.

### CentOS 6 ###
service mysqld stop

### CentOS 7 ###
systemctl stop mysqld

Step 2. Next we need to start MySQL in safe mode with the –skip-grant-tables option so that it will not prompt for password.

 mysqld_safe --skip-grant-tables &

Step 3. Start the mysql client process using this command with root account and blank password.

 mysql -u root

Step 4. Change password for root account.

mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where #User='root';
mysql> flush privileges;
mysql> quit

Step 5. Restart MySQL.

Once complete, you can restart MySQL is installed by running the below command:

### CentOS 6 ###
service mysqld restart

### CentOS 7 ###
systemctl restart mysqld

Congratulation’s! You have successfully reset password MySQL. Thanks for using this tutorial for reset root password MySQL on Linux system. For additional help or useful information, we recommend you to check the official MySQL web site

You Might Also Like: How To Backup and Restore MySQL Database Using Command Line

How To Enable Slow Query Log for MySQL

Enable Slow Query Log for MySQL

MySQL has built-in functionality that allows you to log SQL queries to a file, You can enable the full SQL queries logs to a file or only slow running queries log. It is easy for us to troubleshoot/ debug the sql statement if SQL queries log enable, The slow query log is used to find queries that take a long time to execute and are therefore candidates for optimization. We assume that you already have MySQL installed on Linux system with administrative privileges and we assume that you already have know how on MySQL.

In order to enable slow query logs for MySQL on your system you would need to do the following.

Enable Slow Query Log for MySQL

Step 1. Edit the /etc/my.cnf file with your favorite text editor.

 #nano /etc/my.cnf

 Step 2. Once you have your my.cnf file open, add the following line under the “[mysqld]” section.

[mysqld]
log-slow-queries
log-slow-queries= /var/log/mysql/slow-queries.log
long_query_time=1

 Step 3. Then create the file slow-queries.log. You can have the file in any spot you wish, as long as you define the path in your my.cnf.

#touch /var/log/mysql/slow-queries.log
#chown mysql.mysql /var/log/mysql/slow-queries.log

Step 4. After that, restart mysql service. Enter the following command:

 #service mysqld restart

Congratulation’s! You have successfully enable slow query log on MySQL. Thanks for using this tutorial for enable slow query log on MySQL in Linux system. For additional help or useful information, we recommend you to check the official MySQL web site.

You Might Also Like: How To Install Mtop (MySQL Database Server Monitoring) on CentOS 6

How To Increase PHP Memory Limit

Increase PHP Memory Limit

If you have seen an error like ”Fatal Error: PHP Allowed Memory Size Exhausted” in webserver logs or your browser, this means that PHP has exhausted the maximum memory limit. This tutorial we will show two different ways on how you can increase the php memory limit in your server.

Check PHP Memory Limit

You can check by creating a file called info.php in /var/www/html/ with the following content:

<?php phpinfo(); ?>

php-memory-limit

Increase PHP Memory Limit

Method 1. Changing memory limit from php.ini

First find locate the php.ini file used by your web server.

 #nano /etc/php.ini

Search “memory_limit” in your php.ini, and change it. If no “memory_limit” found, add the following line at the end of php.ini

 #memory_limit = 64M ;Maximum amount of memory a script may consume (64MB)

Restart webserver

#service httpd restart
or
#service nginx restart

Method 2. Changing memory limit using .htaccess

Find the “.htaccess” in your root directory of the specified domain, edit the .htaccess file in the web root directory. Look for the section:

 #php_value memory_limit 64M; Maximum amount of memory a script may consume (64MB)

Edit your wp-config.php file, if you are using WordPress

define('WP_MEMORY_LIMIT', '256M');

Congratulation’s! You have successfully increase PHP memory limit. Thanks for using this tutorial for increase PHP memory limit linux system. For additional help or useful information, we recommend you to check the official PHP web site

You Might Also Like: How To Install PHP 5.5 on CentOS

How To Install Nginx With GeoIP Module

Install Nginx With GeoIP Module

Nginx GeoIP module for country and city geo targeting can be installed in a few easy steps. It brings you a geo targeting layer allowing you to show some parts of your websites, or even split traffic according to the geographical location of the end users. By default, when you install modules from yum, nginx will not come with GeoIP module (This is module: HttpGeoipModule), so we will install from source and the active the module. This article assumes you have at least basic knowledge of linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple.

In this tutorial we will show you how to install and configuration of Nginx With GeoIP Module on your Linux server.

Install Nginx With GeoIP Module

Step 1. First install require package for compiling:

 yum install gcc-c++ pre pcre-devel zlib zlib-devel -y

Step 2. Download the latest stable version of Nginx from here and build it with GeoIP module support.

## cd /opt/nginx/
## wget http://nginx.org/download/nginx-1.6.2.tar.gz
## tar -zxf nginx-1.6.2.tar.gz
## cd nginx-1.6.2/
## ./configure
--prefix=/etc/nginx \
--sbin-path=/etc/nginx/sbin/nginx \
--conf-path=/etc/nginx/conf/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/ninx.lock \
--user=nobody \
--with-http_geoip_module \
--with-http_gzip_static_module \
--with-http_secure_link_module \
--without-mail_pop3_module \
--without-mail_imap_module \
--without-mail_smtp_module \
--without-http_ssi_module

## make
## make install


Step 3. Create an init script for Nginx.

get -O /etc/init.d/nginx https://raw.githubusercontent.com/Fleshgrinder/nginx-sysvinit-script/master/nginx
chmod 0755 /etc/init.d/nginx
chown root:root /etc/init.d/nginx

Step 4. Finally, start Nginx.

 service nginx start

Step 5. Install GeoIP library via yum

# For CentOS 6 – 64-bit

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm 

# yum install geoip geoip-devel -y

After successful installation, the library will be stored in: /usr/share/GeoIP/GeoIP.dat
For the latest updates can be downloaded at: http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz

Configure Nginx

  • Configure on main file:
#nano /etc/nginx/conf/nginx.conf

http {
[...]
geoip_country /usr/share/GeoIP/GeoIP.dat;
map $geoip_country_code $allowed_country {
default yes;
CN no;
}
[...]
}
  • Configure nginx virtualhost:
#nano /etc/nginx/conf.d/yourdomain.conf

server {
[...]
if ($allowed_country = no) {
return 444;
# # This means the server will stop processing, returns error 444 (The connection was reset),
# # And ignore always sending the response header.
# # Replace 444 by 403 if you want
}
[...]
}

The above configuration will accept all IP and banned only from China IP (CN). About Code of the country in GeoIP database you can refer here: http://dev.maxmind.com/geoip/legacy/codes/iso3166/

Congratulation’s! You have successfully installed Nginx With GeoIP Module. Thanks for using this tutorial for installing Nginx With GeoIP Module on Linux system. For additional help or useful information, we recommend you to check the official Nginx web site.

You Might Also Like: How To Install Nginx Web Server On CentOS