Running VS Code on Linux

Curtsy/ Original post: https://code.visualstudio.com/docs/setup/linux

Running VS Code on Linux

Installation

  1. Download Visual Studio Code for your distribution, .deb for Debian-based distributions such as Ubuntu or .rpm for Red Hat-based distributions such as Fedora or CentOS. Note that 32-bit binaries are also available on the download page.
  2. Install the package through a GUI package manager by double clicking on the package file, or through the command line:
 # For .deb
 sudo dpkg -i <file>.deb
 # install dependencies
 sudo apt-get install -f

 # For .rpm (Fedora 21 and below)
 sudo yum install <file>.rpm

 # For .rpm (Fedora 22 and above)
 sudo dnf install <file>.rpm
  1. VS Code should now be available to run through the launcher or the command line by running code.

Tip: Run code . in any folder to start editing files in that folder.

Note:

Visual Studio is tightly integrated with Windows and Developing a .NET application using any language (C# or VB) takes more than just having Wine, and since Wine is not capable enough to provide complete development runtime as .NET in Linux.

If you want to develop software specifically in C#, on Linux, you can use MonoDevelop

Since, you’re asking for Visual Studio 2010 (.NET 4.0), with MonoDevelop, you’ll not be able to develop an app that particularly uses .NET 4, as of now MonoDevelop is in version 3.0.2 (somewhat equivalent to .NET 3.0).

You can still use Windows virtually within Ubuntu, using VirtualBox. And then install Visual Studio there, but still a serious app development is not recommended to be done in Virtualized environment.

Download Visual Studio Code

https://code.visualstudio.com/download

http://www.monodevelop.com/download/

 

Setup mail server on centos 7

Original Post: http://www.krizna.com/centos/setup-mail-server-centos-7/

This article helps you to install and configure basic mail server on Centos 7. Here i have used Postfix for SMTP, Dovecot for POP/IMAP and Dovecot SASL for SMTP AUTH.
Before proceeding please make sure you have assigned static IP for the server and have internet connectivity for installing packages.

Setup mail server on centos 7

1. Installing packages
2. Postfix configuration
3. Dovecot configuration
4. User creation

Installing packages

Step 1 » Assign hostname for the server using the below command.
[root@krizna ~]# hostnamectl set-hostname mail.krizna.com
Step 2 » Make a host entry with your IP in /etc/hosts file.
172.27.0.51 mail.krizna.com
Step 3 » Now start installing packages.
[root@krizna ~]# yum -y install postfix dovecot
After package installation continue with postfix configuration.

Postfix configuration

First create SSL certificate for encryption.
Step 4 » Follow the below steps one by one for creation.
[root@mail ~]# mkdir /etc/postfix/ssl
[root@mail ~]# cd /etc/postfix/ssl
[root@krizna ssl]# openssl genrsa -des3 -out server.key 2048
[root@krizna ssl]# openssl rsa -in server.key -out server.key.insecure
[root@krizna ssl]# mv server.key server.key.secure
[root@krizna ssl]# mv server.key.insecure server.key
Leave blank for A challenge password [] value in the below step.
[root@krizna ssl]# openssl req -new -key server.key -out server.csr
[root@krizna ssl]# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

Step 5 » Now open /etc/postfix/main.cf file for changes.
Find and uncomment the below lines.
#inet_interfaces = localhost #---> line no 116
#mydestination = $myhostname, localhost.$mydomain, localhost #--> line no 164

and add below lines at the end of the file. change myhostname and mydomain values with yours and home_mailbox value to your desired directory. Here it will store mails in the users home directory (Eg: /home/john/mail ).

Step 6 » Open /etc/postfix/master.cf file, add the below lines after “smtp inet n – n – – smtpd” line.

Now check the configuration using postfix check command.
Step 7 » Now configure Dovecot SASL for SMTP Auth. Open /etc/dovecot/conf.d/10-master.conf file, find “# Postfix smtp-auth” line ( line no:95 ) and add the below lines.
# Postfix smtp-auth
unix_listener /var/spool/postfix/private/auth {
mode = 0660
user = postfix
group = postfix
}

Step 8 » Open /etc/dovecot/conf.d/10-auth.conf file, find “auth_mechanisms = plain” ( Line no: 100 ) and add login to the value like below.
auth_mechanisms = plain login
Step 9 » Postfix configuration is over. Now restart both postfix and dovecot services and enable auto start.
[root@mail ~]# systemctl restart postfix
[root@mail ~]# systemctl enable postfix
[root@mail ~]# systemctl restart dovecot
[root@mail ~]# systemctl enable dovecot

Step 10 » Add the firewall rules to allow 25, 587 and 465 ports.
[root@mail ~]# firewall-cmd --permanent --add-service=smtp
[root@mail ~]# firewall-cmd --permanent --add-port=587/tcp
[root@mail ~]# firewall-cmd --permanent --add-port=465/tcp
[root@mail ~]# firewall-cmd --reload
Now start testing connectivity for each ports 25,587 and 465 using telnet and make sure you are getting AUTH PLAIN LOGIN line after issuing ehlo mail.krizna.com command in telnet.
[root@mail ~]# telnet mail.krizna.com 465
Trying 172.27.0.51...
Connected to mail.krizna.com.
Escape character is '^]'.
220 mail.krizna.com ESMTP Postfix
ehlo mail.krizna.com <------- Type this command
250-mail.krizna.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN

Dovecot configuration

Start configuring Dovecot .
Step 11 » Open /etc/dovecot/conf.d/10-mail.conf file, find #mail_location = (line no : 30 ) and add the same directory which is given to home_mailbox in the postfix config file ( Step 5).
mail_location = maildir:~/mail
Step 12 » Open /etc/dovecot/conf.d/20-pop3.conf file, find and uncomment the below line ( line no : 50 ) .
pop3_uidl_format = %08Xu%08Xv
Step 13 » Restart dovecot service.
[root@mail ~]# systemctl restart dovecot
Step 14 » Add firewall rules to allow 110,143,993 and 995.
[root@mail ~]# firewall-cmd --permanent --add-port=110/tcp
[root@mail ~]# firewall-cmd --permanent --add-service=pop3s
[root@mail ~]# firewall-cmd --permanent --add-port=143/tcp
[root@mail ~]# firewall-cmd --permanent --add-service=imaps
[root@mail ~]# firewall-cmd --reload

Check the connectivity for the ports 110,143,993 and 995 using telnet.

User creation

Now create user for testing .
Step 15 » Create user with /sbin/nologin shell to restrict login access.
[root@mail ~]# useradd -m john -s /sbin/nologin
[root@mail ~]# passwd john

Mail server is ready now, Configure user in your mail client and test send/receive.
Setup mail server on centos 7

Also see : https://nazimkuet.wordpress.com/2015/06/16/setup-mail-server-using-postfix-dovecot-and-squirrelmail-in-centosrhelscientific-linux-6-3-step-by-step/

Setup Mail Server using Postfix, Dovecot and SquirrelMail in CentOS/RHEL/Scientific Linux 6.3 step by step

Original Post: https://ostechnix.wordpress.com/2013/02/08/setup-mail-server-using-postfixdovecotsquirrelmail-in-centosrhelscientific-linux-6-3-step-by-step/

Before install postfix, remove sendmail from the server. Because sendmail is the default MTA in Redhat/CentOS.
[root@server ~]# yum remove sendmail

Prerequisites:

  • The mail server should contain a valid MX record in the DNS server. Navigate to this link how to setup DNS server.
  • Firewall and SELinux should be disabled.
[root@server ~]# service iptables stop
[root@server ~]# service ip6tables stop
[root@server ~]# chkconfig iptables off
[root@server ~]# chkconfig ip6tables off
[root@server ~]# vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

Reboot the server.

Scenario

In this tutorial my test box
Hostname     = server.ostechnix.com
IP Address    = 192.168.1.200/24
And my server is configured with proper MX record in DNS server.

Installation

Postfix is installed by default. If it is not installed, use the below command to install postfix.
[root@server ~]# yum install postfix

Configuration

Open the postfix config file /etc/postfix/main.cfFind the below lines and edit them as shown below.
[root@server ~]# vi /etc/postfix/main.cf
myhostname = server.ostechnix.com ##line no 75 - uncomment and enter your host name
mydomain = ostechnix.com  ##line no 83 - uncomment and enter your domain name 
myorigin = $mydomain  ##line no 99 - uncomment
inet_interfaces = all  ##line no 116 - change to all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain  ##line no 164 - add $domain at the end
mynetworks = 192.168.1.0/24, 127.0.0.0/8  ##line no 264 - uncomment and add your network range
home_mailbox = Maildir/  ##line no 419 - uncomment
Start the postfix service.
[root@server ~]# service postfix start
Starting postfix:                                          [  OK  ]
[root@server ~]# chkconfig postfix on

Test Postfix

The commands shown in bold letters should be entered by the user.
Note: The dot after the test command is important.
[root@server ~]# telnet localhost smtp
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 server.ostechnix.com ESMTP Postfix
ehlo localhost
250-server.ostechnix.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:<user1>
250 2.1.0 Ok
rcpt to:<user1>
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
test
.
250 2.0.0 Ok: queued as 117113FF18
quit
221 2.0.0 Bye
Connection closed by foreign host.

Check Mail

Navigate to the user mail directory and check for the new mail.
[root@server ~]# cd /home/user1/Maildir/new/
[root@server new]# ls
1360236956.Vfd00I35afM181256.server.ostechnix.com
[root@server new]# cat 1360236956.Vfd00I35afM181256.server.ostechnix.com 
Return-Path: <user1@ostechnix.com>
X-Original-To: user1
Delivered-To: user1@ostechnix.com
Received: from localhost (localhost [IPv6:::1])
 by server.ostechnix.com (Postfix) with ESMTP id 117113FF18
 for <user1>; Thu,  7 Feb 2013 17:05:32 +0530 (IST)
Message-Id: <20130207113547.117113FF18@server.ostechnix.com>
Date: Thu,  7 Feb 2013 17:05:32 +0530 (IST)
From: user1@ostechnix.com
To: undisclosed-recipients:;
test
Thats it. Postfix working now.

Install Dovecot

[root@server ~]# yum install dovecot

Configure Dovecot

Open the dovecot config file /etc/dovecot/dovecot.conf. Find and uncomment the line as shown below.
[root@server ~]# vi /etc/dovecot/dovecot.conf
protocols = imap pop3 lmtp
Open the file /etc/dovecot/conf.d/10-mail.conf and uncomment the line as shown below.
[root@server ~]# vi /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:~/Maildir  ##line no 24 - uncomment
Open the /etc/dovecot/conf.d/10-auth.conf and edit as shown below.
[root@server ~]# vi /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no  ##line no 9 - uncomment and change from yes to no.
auth_mechanisms = plain login  ##line no 97 - add the text "login"
Open the /etc/dovecot/conf.d/10-master.conf and edit as shown below.
unix_listener auth-userdb {
    #mode = 0600
    user = postfix  ##line no 83 - uncomment and enter postfix
    group = postfix  ##line no 84 - uncomment and enter postfix
Start the dovecot service.
[root@server ~]# service dovecot start
Starting Dovecot Imap:                                     [  OK  ]
[root@server ~]# chkconfig dovecot on

Test Dovecot

The commands shown in bold should be entered by the user.
[root@server ~]# telnet localhost pop3
Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user user1
+OK
pass user1
+OK Logged in.
list
+OK 1 messages:
1 428
.
retr 1
+OK 428 octets
Return-Path: <user1@ostechnix.com>
X-Original-To: user1
Delivered-To: user1@ostechnix.com
Received: from localhost (localhost [IPv6:::1])
 by server.ostechnix.com (Postfix) with ESMTP id 117113FF18
 for <user1>; Thu,  7 Feb 2013 17:05:32 +0530 (IST)
Message-Id: <20130207113547.117113FF18@server.ostechnix.com>
Date: Thu,  7 Feb 2013 17:05:32 +0530 (IST)
From: user1@ostechnix.com
To: undisclosed-recipients:;
test
.
quit 
+OK Logging out.
Connection closed by foreign host.
[root@server ~]#
Dovecot is working now.

Install Squirrelmail

Install EPEL repository first. And install SquirrelMail package from EPEL repository.
[root@server ~]# wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
[root@server ~]# rpm -ivh epel-release-6-8.noarch.rpm 
[root@server ~]# yum install squirrelmail
[root@server ~]# service httpd start
Starting httpd:                                            [  OK  ]
[root@server ~]# chkconfig httpd on
[root@server ~]#

Configure Squirrelmail

Go to the squirrelmail config directory and use the command ./conf.pl to start configure as shown below.
[root@server ~]# cd /usr/share/squirrelmail/config/
[root@server config]# ./conf.pl 
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1.  Organization Preferences
2.  Server Settings
3.  Folder Defaults
4.  General Options
5.  Themes
6.  Address Books
7.  Message of the Day (MOTD)
8.  Plugins
9.  Database
10. Languages
D.  Set pre-defined settings for specific IMAP servers
C   Turn color off
S   Save data
Q   Quit
Command >>1

Select option 1 and set organization details.

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Organization Preferences
1.  Organization Name      : Ostechnix
2.  Organization Logo      : ../images/sm_logo.png
3.  Org. Logo Width/Height : (308/111)
4.  Organization Title     : Welcome to Ostechnix webmail
5.  Signout Page           : 
6.  Top Frame              : _top
7.  Provider link          : http://ostechnix.com
8.  Provider name          : Ostechnix
R   Return to Main Menu
C   Turn color off
S   Save data
Q   Quit
Command >>R

Press R to return main menu and select option 2. Enter your domain name and select dovecot in the Sendmail or SMTP parameter.

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Server Settings
General
-------
1.  Domain                 : ostechnix.com
2.  Invert Time            : false
3.  Sendmail or SMTP       : SMTP
A.  Update IMAP Settings   : localhost:143 (uw)
B.  Update SMTP Settings   : localhost:25
R   Return to Main Menu
C   Turn color off
S   Save data
Q   Quit
Command >> S
Once you done, press S to save datas and press Q to exit.
Add the following lines in the httpd.conf file at the end.
[root@server ~]# vi /etc/httpd/conf/httpd.conf
Alias /squirrelmail /usr/share/squirrelmail
<Directory /usr/share/squirrelmail>
    Options Indexes FollowSymLinks
    RewriteEngine On
    AllowOverride All
    DirectoryIndex index.php
    Order allow,deny
    Allow from all
</Directory>
Restart the httpd service.
[root@server ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[root@server ~]#

Create Users

[root@server ~]# useradd user1
[root@server ~]# useradd user2
[root@server ~]# passwd user1
[root@server ~]# passwd user2
Open the browser from any clients. Type the following in the address bar.
http://serveripaddress/webmail
or
http://yourdomainname/webmail
Now let us compose a mail from user1 to user2. Refer a below screenshot.
Then sign-out and sign-in back from user2.
Thats it. We have got a mail from user1. If you have any issues in the configuration, post them in the comment section.
Have a good day.

Tomcat Clustering – A Step By Step Guide

Apache Tomcat is a great performer on its own, but if you’re expecting more traffic as your site expands, or are thinking about the best way to provide high availability, you’ll be happy to know that Tomcat also shines in a clustered environment. With built-in support for both synchronous and asynchronous in-memory and external session replication, cluster segmentation, and compatibility with all common load balancing solutions, your Tomcat servers are ready for the cluster right out of the box.

In this article, we’ll show you how easy it is to set up a simple Tomcat cluster with load balancing and session replication.

This simple step-by-step guide will walk you through every step of the process in plain English, from installing the load balancer, to configuring mod_jk, to enabling Tomcat’s built-in session replication capabilities. Along the way, we’ll point out common problem areas, to help you avoid configuration mistakes before they happen.

A Simple Explanation of Clustering

Although clustering can seem like a complicated topic, the premise is quite simple. A clustered architecture is used to solve one or more of the following problems:

  • A single server cannot handle the high number of incoming requests efficiently
  • A stateful application needs a way of preserving session data if its server fails
  • A developer requires the capability to make configuration changes or deploy updates to their applications without discontinuing service.

A clustered architecture solves these problems using a combination of load balancing, multiple server “workers” to process the balanced load, and some kind of session replication. Depending on the needs of the application, only some of these components may be used, or additional components such as caching and compression engines.

Since this is a how-to guide, we’ll stop the general information session here, and move on to setting up a working Tomcat cluster. However, if you’re new to clustering, it’s probably a good idea to do a little more reading up on the subject.

For more information about the how and why of clustered architecture, check out our Tomcat Clustering Basics article for an in-depth look at all the components of a cluster, comparisons of different approaches, and more.

About Our Example Set-Up

For the purposes of this tutorial, we’ll use a simple clustered configuration:

  • Apache HTTPD with mod_jk (for load balancing)
  • 2 Tomcat 6.x instances
  • in-memory session replication (via Tomcat’s built in functionality)

This configuration was chosen because it is a simple example of a very common clustering configuration used by many Tomcat users. Additionally, Apache HTTPD with mod_jk or mod_proxy is currently the default clustering solution recommended in the official Tomcat documentation provided by Apache.

We demonstrate configuration with mod_jk rather than mod_proxy for two reasons: it’s a little more complex, and requires some additional steps, and it’s currently the more mature load balancing connector, with a wider user base in the Tomcat community. Additionally, while new releases of mod_proxy are tied to Apache HTTPD releases, mod_jk is developed and released separately from Tomcat, so its features tend to be more current.

Using this tutorial as a basic reference, you should be able to find enough information elsewhere to create more customized or complex configurations. If you are curious about these kinds of situations, or want to know more about how other common approaches to Tomcat clustering stack up against one another, check out our Tomcat Cluster basics article for an in-depth guide.

Setting Up Your Tomcat Cluster

Let’s get started!

Step 1 – Install Tomcat instances and Apache HTTPD

If you haven’t already installed them, the first thing to do is to download and install the latest stable versions of Apache Tomcat 6.x and Apache HTTPD. You can find the latest stable versions on the Apache HTTPD and Tomcat project sites.

Depending on how you want to set up your servers for the purposes of this tutorial, you can either install these elements on multiple servers or a single server; the only differences will be in the port and address configuration steps. Simply follow standard conventions for sharing a single machine with multiple network services (don’t overlap ports, don’t use conflicting names, and so on). If you only want to use this tutorial to test different clustering configurations, the multiple Tomcat instances can live on the same machine, and even share the same base directory, using the CATALINA_BASE variable, as long as you remember that you should move to a set-up that reflects your actual production environment before doing any benchmark testing.

For the purposes of this tutorial, we’ll assume that you understand how to install these components. If you need additional help, don’t worry – the Apache HTTPD installation documentation is quite good, and we’ve created a simple guide to installing Tomcat 6 on multiple platforms, which you can find here.

Step 2 – Download and install mod_jk

mod_jk is the Apache HTTPD module that will be used to provide our cluster with its load balancing and proxy capabilities. It uses the AJP protocol to facilitate fast communication between Tomcat servers and the Apache Web Server that will receive the client requests.

The mod_jk module is distributed separately from Apache HTTPD as part of the Tomcat project. Binary distributions of the module are available for most major platforms, and can be downloaded here. If the version and platform you are looking for is not yet available as a binary distribution, you can build the appropriate version from the source.

Once you have either downloaded and unzipped or built the module, place it in the ‘modules’ directory of your Apache HTTPD server.

Step 3 – Configure mod_jk

Next, we’ll have to set up the mod_jk module in Apache HTTPD’s configuration files. This configuration is a two step process, and can be a little confusing, as mod_jk does not separate its proxy capabilities from its load balancing capabilities.

First, let’s configure the module itself. This is done by adding a few lines to the main Apache HTTPD configuration file, httpd.conf. Take a look at this example configuration (we’ll explain what each attribute does in a second):


# Load module

LoadModule jk_module path/to/apache2/mod_jk.so

# Specify path to worker configuration file

JkWorkersFile /path/to/apache2/conf/workers.properties

# Configure logging and memory

JkShmFile /path/to/desired/log/location/mod_jk.shm

JkLogFile /path/to/desired/log/location/mod_jk.log

JkLogLevel info

# Configure monitoring

JkMount /jkmanager/* jkstatus

<Location /jkmanager>

Order deny, allow

Deny from all

Allow from localhost

</Location>

# Configure applications

JkMount /webapp-directory/* LoadBalancer

Here’s a quick explanation of the parameters we just configured.

  • LoadModule – this command makes the mod_jk module available for use. The extension of the module itself will vary by operating system.
  • JkWorkersFile – sets the path to the worker configuration file, which we will create in the next step.
  • JkShmFile – sets the path to the shared memory files for the module. Generally, you’ll want to keep this with the logs.
  • JkLogFile – sets the path to the module log file.
  • JkLogLevel – sets the level of logging for the module. The valid values for this attribute, in descending order by verbosity, are “debug”, “error” or “info”.
  • JkMount – this is used to map a certain URL pattern to a specific worker configured in the worker configuration file. Here, we use it twice – once to enable /jkmanager as the access URL for jkstatus, a virtual monitoring worker, and once to map all requests we want to be handled by the cluster to the “lb” worker, a virtual worker that contains the load balancing capability
  • Location – this is a security constraint. The settings we have included allow access to the jkmanager only from the localhost (this is a Good Idea).

Step 4 – Configure the cluster workers

Now that we’ve configured the main settings, we will configure the workers. “Workers” is a blanket term used within mod_jk to refer to both real Tomcat servers that will process requests, and virtual servers included in the module to handle load balancing and monitoring. In other words, rather than creating a separate apparatus to manage load balancing, mod_jk simply loads an additional virtual worker with load balancing functionality. If this seems confusing to you, you’re not alone – this is one area where mod_jk shows its age compared to mod_proxy, which keeps all of its configuration in the main httpd.conf file, and doesn’t use the concept of virtual workers.

Here’s a (very) basic workers.properties configuration example (see below for an explanation of the configuration directives):


# Define worker names

worker.list=jkstatus, LoadBalancer

# Create virtual workers

worker.jkstatus.type=status

worker.loadbalancer.type=lb

# Declare Tomcat server workers 1 through n

worker.worker1.type=ajp13

worker.worker1.host=hostname

worker.worker1.port=8009

# …

worker.worker[n].type=ajp13

worker.worker[n].port=8010

worker.worker[n].host=hostname

# Associate real workers with virtual LoadBalancer worker

worker.LoadBalancer.balance_workers=worker1,worker2,…worker[n]

Here’s a quick explanation of the directives we just configured:

Global Directives

These are directives that apply to the entire configuration. There are only two of these directives, and here, we only use one.

worker.list – Allows you to specifically name any workers that should be loaded when the server starts up. These are the only workers to which you can map requests in httpd.conf. This has more uses when using mod_jk as a proxy server. For our purposes, the two workers we’ve defined are enough.

General Worker Directives

These are directives that pertain specifically to workers, but not to virtual workers. They always take the following form:

worker.[name].[directive]=[value]

Worker names are defined as part of a directive (unless set in worker.list). Subsequent directives using the same name value will apply to the same worker. Names may only contain underscores, dashes, and alphanumeric characters, and are case sensitive.

There is a very long list of worker directives, allowing configuration of everything from session replication partner nodes, to connection timeout values, to weights for use with load balancing algorithms. It’s even possible to include workers within multiple nodes, allowing you to do things such as using a very fast server as a pinch hitter to handle spikes in multiple clusters. The extensive control this provides over load balancing scenarios is the reason why using mod_jk over mod_proxy is currently worth the extra configuration trouble. As this is a simple tutorial, we won’t go into the list here, but you can find the whole thing on the Apache project site, and it is highly recommended reading.

worker.[name].type – This allows you to declare a “type” for a given worker. This type can either refer to a virtual worker type (i.e. “lb” for load balancer worker, “status” for the status worker), or to the protocol that the server should use to communicate with a real worker.

Here, we use the type ajp13, which refers to the latest version of the Apache Jserv Protocol, as well as the “lb” and “status” types, which define the virtual load balancing and status manager workers.

worker.[name].host – this allows you to define the appropriate host for a worker. You can also include port in this entry by separating the host name from the port value with a “:”.

worker.[name].port – This allows you to set a port number to access the relevant server. This is especially useful if you want to cluster multiple Tomcat instances running on a single server.

Load Balancer Directives

The mod_jk virtual workers each have their own specialized subsets of directives, which provide extra levels of control over their functions. For example, although the “lb” worker uses a load balancing algorithm based on requests and each server’s lbfactor to distribute the load by default, mod_jk actually includes three additional load balancing algorithms, some of which are more appropriate for certain situations, and can be configured with the “method” directive.

As this is a bare-bones example configuration, we haven’t configured any non-required directives, but as with the worker directives, the full list is available on the Tomcat Connectors project site, and is recommended reading.

worker.[name].balance_workers=[name1],[name2],…[name[n]] – this is the only required load balancer directive, and is used to associate a group of workers with a given load balancer. You can define multiple load balancer names in the global worker list if you will be balancing multiple clusters with a single Apache instance.

If you’d like to learn more about load balancing with mod_jk, visit the load balancing how-to article on the Apache site.

Tips and Tricks

In the interest of simplicity, we’ll leave it up to you to explore the other configuration options on your own. However, before we move on, here’s two quick tricks that can be real time-savers when you start configuring your real-world clusters.

Variables

The mod_jk worker configuration file supports the use of variables to make adding new clusters or migrating configurations to a new server an easier process. Variables can be used in place of any directive-defined value. It’s very simple to define a variable. Simply use the format below, making sure that you do not use a word already associated with a specific function:

[variable_name]=[value]

Variable names can contain any alphanumeric character, as well as dashes, underscores, and periods, and are not case sensitive. To call a variable, use the following syntax:

worker.[name].directive=$(variable_name)

For example, you could define a base network address:

mynetwork=193.228.43

…And then use it to configure multiple workers:


worker.worker1.host=$(mynetwork).12

worker.worker2.host=$(mynetwork).13

worker.worker3.host=$(mynetwork).14

Property Inheritance

If you are configuring multiple similar workers or clusters, you can use the “reference” directive to cause a worker to inherit any properties of another existing worker for which you have not provided an explicit value for the new worker. References are inherited by hierarchy, so you can even create multiple subclasses of reference worker. Use the following syntax to create a reference:

worker.worker1.reference=worker.WorkerTemplate

This will cause “worker1” to inherit all the properties of the “WorkerTemplate” worker. You can create a template worker simply by defining it in the usual way and excluding it from workers.list and any balanced_worker lists. A common use for the reference directive is to define a single load balancer, and use inherited values to split its workers across two domains.

Putting It All Together

A good combined use of property inheritance and variables would be to comment a section at the top of the mod_jk configuration section of your httpd.conf file as “Global Settings and Templates”, and then use something like this:


# Global Settings

myHost=my/host/name.domain

myOtherHost=my/other/hostname.domain

worker.default.connection_timeout=1

worker.default.host=$(myHost)

worker.fastserver.lbfactor=4

worker.fastserver.host=$(myOtherHost)

Using this technique, you can create whole cluster profiles simply by referencing these archetypes, and migrate entire configurations to new servers by changing just a few variables.

For a more in-depth look at defining workers, and some more inspiration for tricky configurations, visit the Workers HowTo [http://tomcat.apache.org/connectors-doc/generic_howto/workers.html] article on Apache’s website.

Step 5 – Configure your Tomcat workers

Now that we’ve finally gotten the mod_jk configuration out of the way, it’s time to configure our Tomcat instances to support clustering. To make this task a little easier to swallow, we’ve divided the process into two steps – enabling session replication, and configuring the actual cluster.

Step 5a – Configure your Tomcat workers – Enabling session replication

In this example, we’ll use simple all-to-all in-memory session replication. This means every worker in our example cluster will replicate their sessions across every other worker. This is not always the most efficient method of session replication in higher load environments, but you can easily build on the concepts we’ll introduce in this section to create a more specific solution when you design clusters for your production environment.

Tomcat provides in-memory session replication through a combination of serializable session attributes, “sticky sessions”, which are provided by the load balancer, and specialized components configured in Tomcat’s XML configuration files. We’ll tackle each of these components one by one.

Serializable Session Attributes

In order to use Tomcat’s built-in session replication, any session attribute or class that will need to be available in the event of failover must implement java.io.Serializable. This interface allows the JVM to convert session objects into bytecode that can be stored in memory and copied to other instances. All JavaBeans are technically required to be serializeable by default, but you should make sure that all your session attributes properly implement the interface.

Sticky Sessions

Load balancers use a variety of methods to make sure that requests are sent to the machine that has the most current session data. The easiest of these, and the one we will use for this example, is called “sticky sessions”.

A load balancer with sticky sessions enabled, after routing a request to a given worker, will pass all subsequent requests with matching sessionID values to the same worker. In the event that this worker fails, the load balancer will begin routing this request to the next most available server that has access to the failed server’s session information. Tomcat’s method of in-memory session replication relies on sticky sessions for both normal and failover load balancing situations.

The latest version of mod_jk enables sticky sessions by default. If you want to be absolutely sure that sticky sessions is enabled for your configuration, you can add the worker.lb.stickysessions=true attribute to your workers.properties file.

Make Your Applications Distributable

In the context of clustered Java application servers, the term “distributable” is used to denote an application that allows its information to be distributed to more than one JVM. This is essential for session replication. You can mark your applications as “distributable” in one of two places. First, you can include the <distributable> element in your application’s deployment descriptor (WEB-INF/web.xml), like this:

<distributable />

Note that the distributable element is one of the rare “self-closing” XML tags in Tomcat; nest it anywhere inside the enclosing <web-app> elements.

Your other option is to simply add the “distributable” attribute to the relevant application’s Context element, as follows:

<Context distributable=”true”>

Even if you have marked your application as distributable, you may run into problems if you haven’t created your web application with clustering in mind. In addition to being declared as such, distributable applications must satisfy the following requirements:

Session attributes must implement java.io.Serializable.

HttpSession.setAttribute() must be called any time changes are made to an object that belongs to a session, so that the session replicator can distribute the changes across the cluster

The sessions must not be so big that they overload the server with traffic when copied.

Setting jvmRoute

The jvmRoute attribute of the Engine element allows the load balancer to match requests to the JVM currently responsible for updating the relevant session. It does this by appending the name of the JVM to the JSESSIONID of the request, and matching this against the worker name provided in workers.properites.

In order to configure jvmRoute, make sure that the value of “jvmRoute” for all your Engines is paired with an identically named Worker name entry in mod_jk’s worker.properties configuration file.

Keeping your Workers in Sync

When clustering multiple servers, it is important that each worker in the cluster have the same understanding of real world time, as some of Tomcat’s clustering features are time-dependent.

In order to eliminate this concern, make sure that all of your servers update their time settings automatically by connecting to the same Network Time Protocol (NTP) service. This is a function of the server OS itself, not of the Tomcat instance. If you are unsure of how to set up this connection, consult the documentation provided by your OS vendor. You can find a list of NTP servers and more information about the service at the NTP Project Wiki.

Step 5b – Configure your Clusters

Finally, you can now configure your cluster to work with Tomcat. This is done in Tomcat’s main configuration file, server.xml, which can be found in the $CATALINA_HOME/conf directory, within a special Cluster element. The cluster element is nested

As not every server configuration requires clustering, the Cluster element is commented out by default. Open server.xml and uncomment the following entry:


<!–

<Cluster className=”org.apache.catalina.ha.tcp.SimpleTcpCluster”/>

–>

The className is the Java class responsible for providing Tomcat’s clustering capabilities, which is included with all versions of Tomcat 5.x and later.

In order to configure clustering, Tomcat uses a mixture of cluster-specific elements and standard Tomcat elements nested within a Cluster element. Let’s take a look at an example cluster configuration, and go through it element by element to learn how it works.

Note that as the goal of this article is simply to demonstrate an easy cluster configuration, we will not get into much depth as to way in which the various Java components that make up Tomcat’s clustering functionality work. However, as you become more familiar with clustering, this is recommended reading, and you can get started on the Apache project site.

An Example Clustering Configuration


<Engine name=”Catalina” defaultHost=”www.mysite.com” jvmRoute=”[worker name]”>

<Cluster className=”org.apache.catalina.ha.tcp.SimpleTcpCluster” channelSendOptions=”8″>

<Manager className=”org.apache.catalina.ha.session.DeltaManager”

expireSessionsOnShutdown=”false”

notifyListenersOnReplication=”true”/>

 

<Channel className=”org.apache.catalina.tribes.group.GroupChannel”>

<Membership className=”org.apache.catalina.tribes.membership.McastService”

address=”228.0.0.4″

port=”45564″ frequency=”500″

dropTime=”3000″/>

<Sender className=”org.apache.catalina.tribes.transport.ReplicationTransmitter”>

<Transport className=”org.apache.catalina.tribes.transport.nio.PooledParallelSender”/>

</Sender>

<Receiver className=”org.apache.catalina.tribes.transport.nio.NioReceiver”

address=”auto” port=”4000″ autoBind=”100″

selectorTimeout=”5000″ maxThreads=”6″/>

<Interceptor className=”org.apache.catalina.tribes.group.interceptors.TcpFailureDetector”/>

<Interceptor className=”org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor”/>

</Channel>

<Valve className=”org.apache.catalina.ha.tcp.ReplicationValve” filter=””/>

<Valve className=”org.apache.catalina.ha.session.JvmRouteBinderValve”/>

<ClusterListener className=”org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener”/>

<ClusterListener className=”org.apache.catalina.ha.session.ClusterSessionListener”/>

</Cluster>

Let’s go through this configuration one Element at a time.

Engine

This is the standard Engine element that defines Catalina as the component responsible for processing requests. As we mentioned in Step 5a, to enable session replication, you must set the “jvmRoute” attribute to match the corresponding worker you have configured in mod_jk’s workers.properties file. This value must be unique for every node included in the cluster.

Cluster

This is the main Cluster element, within which all other clustering elements are nested. It supports a variety of attributes, but in this simple example, we have only configured one, “channelSendOptions”. This attribute sets a flag within Tomcat’s clustering class that chooses between different methods of cluster communication. These options are outside the scope of this article, but a safe default setting is “8”, which enables asynchronous communication.

Manager

This is the standard element that Tomcat uses for session management. When nested inside the Cluster element, it is used to tell Tomcat which cluster-aware session manager should be used for session replication. In this example, we have used the DeltaManager, which provides basic cluster-aware session management, as well as additional capabilities you can use to divide your cluster into multiple groups in the future. The attributes we have configured, “expireSessionsOnShutdown” and “notifyListenersOnReplication”, have been configured to prevent a failing node from destroying sessions on other clustered nodes and explicitly notify the ClusterListeners when a session has been updated.

Channel

This element communicates with a component of Tomcat’s clustering solution called Tribes. This component handles all communication between the clustered nodes. In this example, we have configured Tribes to use multicast communication, although more complicated situations can be configured using single point broadcasting. The Channel element is used to contain a series of other elements that divide cluster communication into simple blocks.

Membership

This Tribes-related element defines the address all nodes will use to keep track of one another. The settings we have used here are the Tribes defaults.

Sender

This Tribes-related element, in conduction with the Transport element nested inside of it, is used to choose from and configure a number of different implementations of cluster communication. Here, we have used the NIO transport, which generally provides the best performance.

Receiver

This Tribes-related element configures a single Receiver component, which receives messages from other nodes’ Sender components. The attributes of the element allow you to specify addresses, buffer sizes, thread limits, and more. The settings we have used here allow the nodes to automatically discover one another via an address that Tribes will generate automatically.

Interceptor

Interceptor elements are used to make modifications to messages sent between nodes. For example, one of the Interceptor elements we have configured here detects delays that may be preventing a member from updating its table due to timeout, and provides an alternative TCP connection. Tribes includes a number of standard interceptors; to enable any of them, simply add an addition Interceptor element with the appropriate className. Here, we have included only interceptors useful in almost all clustering situations.

Valve

Tomcat’s standard Valve element can be nested within Cluster elements to provide filtering. The element includes a number of cluster-specific implementations. For example, one of the Valves we have included here can be used to restrict the kinds of files replicated across the cluster. For this example configuration, we have included the most commonly used Valves, with blank attribute values that you can configure as required.

ClusterListener

This element listens to all messages sent through by cluster workers, and intercepts those that match their respective implementation’s specifications. These elements operate in a very similar manner to Inteceptor elements, except that rather than modifying messages and passing them on to a Receiver, they are the intended recipient of the messages for which they are listening.

Once you have edited your server.xml file, simply restart the server, and you will have a cluster-enabled Tomcat instance up and running! Note that you will need to add this configuration to each Tomcat instance you wish to add to the cluster as a worker, and that each Engine element must have its own unique jvmRoute.

Resetting a forgotten MySQL root password and MySql phpmyadmin troubleshooting

1. If you failed to access your_ip/phpmyadmin then you just need to do the bellow-

You just need to make a symbolic link to the installation in your server root. Mine is in /var/www/ so:

sudo ln -s /usr/share/phpmyadmin/ /var/www/phpmyadmin

After that, you’ll be able to access trough localhost:

http://localhost/phpmyadmin

As for why is not installed by default in its right location, or the installer creates a symbolic link itself, I have no idea…

2.

Configure the .htaccess file

With the .htaccess file allowed, we can proceed to set up a native user whose login would be required to even access the phpmyadmin login page.

Start by creating the .htaccess page in the phpmyadmin directory:

sudo nano /usr/share/phpmyadmin/.htaccess

Follow up by setting up the user authorization within .htaccess file. Copy and paste the following text in:

AuthType Basic
AuthName "Restricted Files"
AuthUserFile /path/to/passwords/.htpasswd
Require valid-user

Below you’ll see a quick explanation of each line:

  • AuthType: This refers to the type of authentication that will be used to the check the passwords. The passwords are checked via HTTP and the keyword Basic should not be changed.
  • AuthName: This is text that will be displayed at the password prompt. You can put anything here.
  • AuthUserFile: This line designates the server path to the password file (which we will create in the next step.)
  • Require valid-user: This line tells the .htaccess file that only users defined in the password file can access the phpMyAdmin login screen.

3.

Resetting a forgotten MySQL root password

Posted by Steve on Thu 28 Sep 2006 at 09:12

Resetting the root password of a MySQL database is trivial if you know the current password if you don’t it is a little tricker. Thankfully it isn’t too difficult to fix, and here we’ll show one possible way of doing so.

If you’ve got access to the root account already, because you know the password, you can change it easily:

steve@steve:~$ mysql --user=root --pass mysql
Enter password:

mysql> update user set Password=PASSWORD('new-password-here') WHERE User='root';
Query OK, 2 rows affected (0.04 sec)
Rows matched: 2  Changed: 2  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

mysql> exit
Bye

However if you don’t know the current password this approach will not work – you need to login to run any commands and without the password you’ll not be able to login!

Thankfully there is a simple solution to this problem, we just need to start MySQL with a flag to tell it to ignore any username/password restrictions which might be in place. Once that is done you can successfully update the stored details.

First of all you will need to ensure that your database is stopped:

root@steve:~# /etc/init.d/mysql stop

Now you should start up the database in the background, via the mysqld_safe command:

root@steve:~# /usr/bin/mysqld_safe --skip-grant-tables &
[1] 6702
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6763]: started

Here you can see the new job (number “1”) has started and the server is running with the process ID (PID) of 6702.

Now that the server is running with the --skip-grant-tables flag you can connect to it without a password and complete the job:

root@steve:~$ mysql --user=root mysql
Enter password:

mysql> update user set Password=PASSWORD('new-password-here') WHERE User='root';
Query OK, 2 rows affected (0.04 sec)
Rows matched: 2  Changed: 2  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

mysql> exit
Bye

Now that you’ve done that you just need to stop the server, so that you can go back to running a secure MySQL server with password restrictions in place. First of all bring the server you started into the foreground by typing “fg“, then kill it by pressing “Ctrl+c” afterwards.

This will now allow you to start the server:

root@steve:~# /etc/init.d/mysql start
Starting MySQL database server: mysqld.
Checking for corrupt, not cleanly closed and upgrade needing tables..

Now everything should be done and you should have regained access to your MySQL database(s); you should verify this by connecting with your new password:

root@steve:~# mysql --user=root --pass=new-password-here
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5 to server version: 5.0.24a-Debian_4-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> exit
Bye

If you’d like to automate this process you could start by looking at this simple shell script which will allow you to reset a password with one command.

How can I configure Tomcat with multiple virtual hosts?

Original Post/ Curtsy: 

http://www.ramkitech.com/2012/03/virtual-host-apache-httpd-server-tomcat.html

Thanks to Mr. 

Understanding Virtual Host Concept in Tomcat

Hi in this post we will see how to setup virtual host in Apache Tomcat server. Virtual Host is in-built feature that allows to deploy multiple website(domains) in single instance of tomcat server. The main benefit in this way is its cost effective.

Scenario:

I am going to deploy 3 website with following domain names in single tomcat


http://www.ramki.com
http://www.krishnan.com
http://www.blog.ramki.com

The following diagram is my outline.

Outline structure of Virtual Host Concept in Tomcat

Here my tomcat IP address 192.168.1.15. or any IP address allocated my ISP. but it should be public IP address.

How all domain names are pointing to my Tomcat?
When we purchase the domain name we need to update the our tomcat IP address to it. like

or we can simulate same DNS Setup through hosts file in both Linux and Windows. In Linux tha file is located at /etc/hosts

Now How Setup Virtual Host Concept?

Before going to setup the virtual host. first take look at the server.xml file in conf folder in tomcat directory.

server.xml

  1. <server port=“8005” shutdown=“SHUTDOWN”>
  2.   <service name=“Catalina”>
  3.        <engine defaulthost=“localhost” name=“Catalina”>
  4.             <host appbase=“webapps” autodeploy=“true” name=“localhost” unpackwars=“true”>
  5.             </host>
  6.        </engine>
  7.    </service>
  8. </server>

here <Engine> tag specified which engine is responsible for executing servlet. Here Catalina is the Engine.
<Host> tag  specify the domain name and web apps base location. here default domain name is localhost and web apps base location is webapps folder in tomcat directory. here name attribute to specify the domain name and appbase attribute to specify the location of domain specific web apps folder path.

Now we need to add more <Host> tags to represent to our domains

<Host name=“www.ramki.com” appbase=“ramki_webapps”/>
<Host name=“www.krishnan.com” appbase=“krishnan_webapps” />
<Host name=“www.blog.ramki.com” appbase=“blog_webapps” />


Then we need to copy the webapps folder in tomcat and paste it anywhere and rename it to ramki_webapps, krishnan_webapps, blog_webapps and update the path in <Host> tag

Modifies server.xml file

  1. <server port=“8005” shutdown=“SHUTDOWN”>
  2.   <service name=“Catalina”>
  3.       <engine defaulthost=“localhost” name=“Catalina”>
  4.          <host appbase=“webapps” autodeploy=“true” name=“localhost” unpackwars=“true”></host>
  5.          <host appbase=“ramki_webapps” autodeploy=“true” name=“www.ramki.com” unpackwars=“true”></host>
  6.          <host appbase=“krishnan_webapps” autodeploy=“true” name=“www.krishnan.com” unpackwars=“true”></host>
  7.          <host appbase=“blog_webapps” autodeploy=“true” name=“www.blog.ramki.com” unpackwars=“true”></host>
  8.     </engine>
  9.   </service>
  10. </server>

Simulate the DNS
Open the /etc/hosts file through root privilege and add following entry

192.168.1.15       http://www.ramki.com
192.168.1.15       http://www.krishnan.com
192.168.1.15       http://www.blog.ramki.com

deploy the websites to respective web apps folder and start the tomcat.

Test:
now open the browser and type http://www.ramki.com then its shows the ramk website content. Other two sites http://www.krishnan.com and http://www.blog.ramki.com works respective webapps.

In above diagram represent when we access http://www.ramki.com the tomcat server consult with server.xml file and serves the files from ramki_webapps directory.

How is Virtual Host Works
Here big question all websites are pointed to same tomcat. How tomcat can distinguished the request. (i.e) how tomcat knows browser requested ramki.com or http://www.krishnan.com

The answer is based Host header field in HTTP request.
when we accssed http://www.ramki.com then browser make HTTP request. and the request look like this

GET / HTTP/1.1 
Host: http://www.ramki.com 
Proxy-Connection: keep-alive 
User-Agent: Mozilla/5.0 (Windows NT 6.2) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Encoding: gzip,deflate,sdch 
Accept-Language: en-US,en;q=0.8


here Host Field contain domain name
Host: http://www.ramki.com

when tomcat receive the request from any browser, it read the Host field and understand which domain we requested, then consult the server.xml file and delegate to appropriate Host process thread

check my screen cast for setup

How to setup virtualhost in Tomcat

I recently had to configure a couple of different tomcat web applications as virtual hosts each one with its own domain. I was accessing these applications using the URL http://localhost:8080/app1 and http://localhost:8080/app2. The basic intention behind the virtual host setup was to avoid the web application name from the url (app1/app2) and the applications to be accessed using http://www.domain1.com and http://www.domain2.com/ . If there was only one web application I could have achieved it by keeping the web application inside webapps/ROOT folder.

Though I am using Apache as front server which was used to forward the dynamic content request to tomcat, I am not describing the Apache-Tomcat configuration in this article. I have described the Apache-Virtualhost-Tomcat-configuration in another article.

Step 1: Configuring Tomcat server.xml

Add the following entry in server.xml (TOMCAT_HOME/conf/server.xml). This should be added below to <Host name=”localhost” ..>…….</Host>

<Host name="www.domain1.com" appBase="/opt/tomcat/www.domain1.com" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"/>

<Host name=”www.domain2.com” appBase=”/opt/tomcat/www.domain2.com” unpackWARs=”true” autoDeploy=”true” xmlValidation=”false” xmlNamespaceAware=”false”/>

Step 2: Deploying the applications

Create folders http://www.domain1.com and http://www.domain2.com inside TOMCAT_HOME. Copy the webapp1 to http://www.domain1.com and webapp2 to http://www.domain2.com. Rename both webapp1 and webapp2 to ROOT (ensure ROOT should be in uppercase).

The following should exist after the completion of step2.

TOMCAT_HOME/www.domain1.com/ROOT/webapp1_contents
TOMCAT_HOME/www.domain2.com/ROOT/webapp2_contents

Step 3: Enabling Tomcat Manager Console for the new hosts

The default tomcat manager console (http://localhost:8080/manager/html) will not be available for the new hosts. Manager Console needs to be enabled for the application deployed under each virtual host. This can be done by following the below steps.

Create folders http://www.domain1.com and http://www.domain2.com under TOMCAT_HOME/conf/Catalina/. Copy manager.xml from TOMCAT_HOME/conf/Catalina/localhost/ to TOMCAT_HOME/conf/Catalina/www.domain1.com/ and TOMCAT_HOME/conf/Catalina/www.domain1.com/.

The tomcat manager console for the hosts http://www.domain1.com and http://www.domain2.com can be accessed using the URLs http://www.domain1.com:8080/manager/html and http://www.domain2.com:8080/manager/html respectively.

Step 4: Adding host entry for each virtualhost

In production/staging environments normally the domain would be mapped to the IP of the machine. However in development environments we need to map the IP with the virtualhost. This can be done by adding a host entry in the host file. The ‘hosts’ file is typically located at C:\WINDOWS\system32\drivers\etc\hosts on windows and /etc/hosts on UNIX

Machine-IP http://www.domain1.com
Machine-IP http://www.domain2.com

Step 5: verifying the virtualhosts

Restart the Tomcat Server and check whether the webapp1 and webapp2 are accessible using the URLs http://www.domain1.com:8080 and http://www.domain2.com:8080 respectively.

If you are using Apache web server and Tomcat, you can leave Tomcat running on port 8080. Otherwise simply change the port of tomcat from 8080 to 80.

With Tomcat running on JVM Host dedicated JVM you have full control over configuration files. You may host multiple domains and map them to particular web applications. First step is to map a domain or a directory under it to the Tomcat (this is done with mod_jk or mod_proxy_ajp using our JVMCP control panel), second step is to add virtual host in server.xml. See the below example.

You have 2 domains: primary domain domain1.com and addon domain domain2.com. Your ~/appservers/apache-tomcat/webapps directory:

$ls -al
docs
domain1
domain2
examples
manager
host-manager
ROOT

Please put JSP files into domain1 and domain2 directories. Alternatively you can put domain1.war and domain2.war in webapps directory and Tomcat will deploy the wars.

  1. Domain1.com is the main domain (the main domain can point to different directory such as ROOT, anyway this is only example).
  2. Domain2.com is the domain that we want to add to Tomcat.
  3. You need create domain2.com as addon domain in cPanel.
  4. Please make sure you use correct nameservers for domain2.com.
  5. Create mappings – default mappings are enough. Use custom JVM control panel JVMCP for this.
  6. Configure $CATALINA_HOME/conf/server.xml file.

Please edit $CATALINA_HOME/conf/server.xml

 <Host name="domain1.com" autoDeploy="true" appBase="webapps" unpackWARs="true">
 <Alias>www.domain1.com</Alias>
 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"   
                prefix="localhost_access_log." suffix=".txt" 
                pattern="%h %l %u %t "%r" %s %b" resolveHosts="false"/>
 <Context path="" docBase="domain1" debug="0" reloadable="true"/> 
 </Host>

 <Host name="domain2.com" autoDeploy="true" appBase="webapps" unpackWARs="true">
 <Alias>www.domain2.com</Alias>
 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"   
                prefix="localhost_access_log." suffix=".txt" 
                pattern="%h %l %u %t "%r" %s %b" resolveHosts="false"/>
 <Context path="" docBase="domain2" debug="0" reloadable="true"/> 
 </Host>

Restart Tomcat using JVMCP or shell and your are done.

– See more at: http://www.jvmhost.com/articles/how-to-configure-tomcat-with-multiple-virtual-hosts#sthash.Yw1C4fx0.dpuf

With Tomcat running on JVM Host dedicated JVM you have full control over configuration files. You may host multiple domains and map them to particular web applications. First step is to map a domain or a directory under it to the Tomcat (this is done with mod_jk or mod_proxy_ajp using our JVMCP control panel), second step is to add virtual host in server.xml. See the below example.

You have 2 domains: primary domain domain1.com and addon domain domain2.com. Your ~/appservers/apache-tomcat/webapps directory:

$ls -al
docs
domain1
domain2
examples
manager
host-manager
ROOT

Please put JSP files into domain1 and domain2 directories. Alternatively you can put domain1.war and domain2.war in webapps directory and Tomcat will deploy the wars.

  1. Domain1.com is the main domain (the main domain can point to different directory such as ROOT, anyway this is only example).
  2. Domain2.com is the domain that we want to add to Tomcat.
  3. You need create domain2.com as addon domain in cPanel.
  4. Please make sure you use correct nameservers for domain2.com.
  5. Create mappings – default mappings are enough. Use custom JVM control panel JVMCP for this.
  6. Configure $CATALINA_HOME/conf/server.xml file.

Please edit $CATALINA_HOME/conf/server.xml

 <Host name="domain1.com" autoDeploy="true" appBase="webapps" unpackWARs="true">
 <Alias>www.domain1.com</Alias>
 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"   
                prefix="localhost_access_log." suffix=".txt" 
                pattern="%h %l %u %t "%r" %s %b" resolveHosts="false"/>
 <Context path="" docBase="domain1" debug="0" reloadable="true"/> 
 </Host>

 <Host name="domain2.com" autoDeploy="true" appBase="webapps" unpackWARs="true">
 <Alias>www.domain2.com</Alias>
 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"   
                prefix="localhost_access_log." suffix=".txt" 
                pattern="%h %l %u %t "%r" %s %b" resolveHosts="false"/>
 <Context path="" docBase="domain2" debug="0" reloadable="true"/> 
 </Host>

Restart Tomcat using JVMCP or shell and your are done.

– See more at: http://www.jvmhost.com/articles/how-to-configure-tomcat-with-multiple-virtual-hosts#sthash.Yw1C4fx0.dpuf

http://www.jvmhost.com/articles/how-to-configure-tomcat-with-multiple-virtual-hosts

How to create virtual host for app on Tomcat.

NB! I will say right away, that my Tomcat is running on Ubuntu Server 10.10 under VMWare Workstation 7.
So here it goes. Recently I installed YouTrack issue tracker on my local server, that runs on Tomcat. Very soon I got tired from typing every time (ip_address/webapp_name:port). So I looked up how to create a very simple VirtualHost for Tomcat.

To create Tomcat VirtualHost you just need to edit tomcat_dir/conf/server.xml and inside Engine tag place following code:

1
2
3
4
5
<Host name="virtual_host_name" appBase="webapps/your_app_name" unpackWars="false" autoDeploy="false">
    <Logger className="org.apache.catalina.logger.FileLogger" directory="logs" prefix="virtual_log." suffix=".txt" timestamp="true" />
    <Context path="" docBase="path_to_your_webapp_from_root" debug="0" reloadable="true" />
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="virtual_log." suffix=".txt" pattern="common" />
</Host>

So in the end you will have to add this virtual_host_name to your windows hosts file and link to your VM ip address. Then you will be abble to access your like: virtual_host_name:8080.

With Tomcat running on JVM Host dedicated JVM you have full control over configuration files. You may host multiple domains and map them to particular web applications. First step is to map a domain or a directory under it to the Tomcat (this is done with mod_jk or mod_proxy_ajp using our JVMCP control panel), second step is to add virtual host in server.xml. See the below example.

You have 2 domains: primary domain domain1.com and addon domain domain2.com. Your ~/appservers/apache-tomcat/webapps directory:

$ls -al
docs
domain1
domain2
examples
manager
host-manager
ROOT

Please put JSP files into domain1 and domain2 directories. Alternatively you can put domain1.war and domain2.war in webapps directory and Tomcat will deploy the wars.

  1. Domain1.com is the main domain (the main domain can point to different directory such as ROOT, anyway this is only example).
  2. Domain2.com is the domain that we want to add to Tomcat.
  3. You need create domain2.com as addon domain in cPanel.
  4. Please make sure you use correct nameservers for domain2.com.
  5. Create mappings – default mappings are enough. Use custom JVM control panel JVMCP for this.
  6. Configure $CATALINA_HOME/conf/server.xml file.

Please edit $CATALINA_HOME/conf/server.xml

 <Host name="domain1.com" autoDeploy="true" appBase="webapps" unpackWARs="true">
 <Alias>www.domain1.com</Alias>
 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"   
                prefix="localhost_access_log." suffix=".txt" 
                pattern="%h %l %u %t "%r" %s %b" resolveHosts="false"/>
 <Context path="" docBase="domain1" debug="0" reloadable="true"/> 
 </Host>

 <Host name="domain2.com" autoDeploy="true" appBase="webapps" unpackWARs="true">
 <Alias>www.domain2.com</Alias>
 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"   
                prefix="localhost_access_log." suffix=".txt" 
                pattern="%h %l %u %t "%r" %s %b" resolveHosts="false"/>
 <Context path="" docBase="domain2" debug="0" reloadable="true"/> 
 </Host>

Restart Tomcat using JVMCP or shell and your are done.

– See more at: http://www.jvmhost.com/articles/how-to-configure-tomcat-with-multiple-virtual-hosts#sthash.Yw1C4fx0.dpuf

How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Debian

About LAMP

LAMP stack is a group of open source software used to get web servers up and running. The acronym stands for Linux, Apache, MySQL, and PHP. Since the virtual private server is already running Debian, the linux part is taken care of. Here is how to install the rest.

Set Up

Before running through the steps of this tutorial, make sure that all of your repositories are up to date:

apt-get update

With that completed, go ahead and start installing the LAMP server.

Step One—Install Apache

Apache is a free open source software which runs over 50% of the world’s web servers.

To install apache, open terminal and type in these commands:

apt-get install apache2

That’s it. To check if Apache is installed on your VPS, direct your browser to your server’s IP address (eg. http://12.34.56.789). The page should display the words “It works!” like this.

How to Find your Server’s IP address

You can run the following command to reveal your VPS’s IP address.

ifconfig eth0 | grep inet | awk '{ print $2 }'

Step Two—Install MySQL

MySQL is a widely-deployed database management system used for organizing and retrieving data.

To install MySQL, open terminal and type in these commands:

apt-get install mysql-server

During the installation, MySQL will ask you to set a root password. If you miss the chance to set the password while the program is installing, it is very easy to set the password later from within the MySQL shell.

Finish up by running the MySQL set up script:

 mysql_secure_installation

The prompt will ask you for your current root password.

Type it in.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Then the prompt will ask you if you want to change the root password. Go ahead and choose N and move on to the next steps.

It’s easiest just to say Yes to all the options. At the end, MySQL will reload and implement the new changes.

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y                                            
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

Once you’re done with that you can finish up by installing PHP on your virtual server.

Step Three—Install PHP

PHP is an open source web scripting language that is widely use to build dynamic webpages.

To install PHP, open terminal and type in this command. UPDATE: If you are on Debian 7, exclude php5-suhosin from that list as it was removed.

 apt-get install php5 php-pear php5-suhosin php5-mysql

After you answer yes to the prompt twice, PHP will install itself.

Finish up by restarting apache:

service apache2 restart

Congratulations! You now have LAMP stack on your droplet!

Step Four—RESULTS: See PHP on your Server

Although LAMP is installed, we can still take a look and see the components online by creating a quick php info page

To set this up, first create a new file:

 nano /var/www/info.php

Add in the following line:

<?php
phpinfo();
?>

Then Save and Exit.

Finish up by visiting your php info page (make sure you replace the example ip address with your correct one): http://12.34.56.789/info.php

It should look something like this:

 

[MORE]

1 Preliminary Note

In this tutorial I use the hostname server1.example.com with the IP address 192.168.0.100. These settings might differ for you, so you have to replace them where appropriate.

2 Installing MySQL 5

First we install MySQL 5 like this:

apt-get install mysql-server mysql-client

You will be asked to provide a password for the MySQL root user – this password is valid for the user root@localhost as well as root@server1.example.com, so we don’t have to specify a MySQL root password manually later on:

New password for the MySQL “root” user: <– yourrootsqlpassword
Repeat password for the MySQL “root” user: <– yourrootsqlpassword

3 Installing Apache2

Apache2 is available as a Debian package, therefore we can install it like this:

apt-get install apache2

Now direct your browser to http://192.168.0.100, and you should see the Apache2 placeholder page (It works!):

Click to enlarge

Apache’s default document root is /var/www on Debian, and the configuration file is /etc/apache2/apache2.conf. Additional configurations are stored in subdirectories of the /etc/apache2 directory such as /etc/apache2/mods-enabled (for Apache modules),/etc/apache2/sites-enabled (for virtual hosts), and /etc/apache2/conf.d.

4 Installing PHP5

We can install PHP5 and the Apache PHP5 module as follows:

apt-get install php5 libapache2-mod-php5

We must restart Apache afterwards:

/etc/init.d/apache2 restart

5 Testing PHP5 / Getting Details About Your PHP5 Installation

The document root of the default web site is /var/www. We will now create a small PHP file (info.php) in that directory and call it in a browser. The file will display lots of useful details about our PHP installation, such as the installed PHP version.

vi /var/www/info.php

<?php
phpinfo();
?>

Now we call that file in a browser (e.g. http://192.168.0.100/info.php):

As you see, PHP5 is working, and it’s working through the Apache 2.0 Handler, as shown in the Server API line. If you scroll further down, you will see all modules that are already enabled in PHP5. MySQL is not listed there which means we don’t have MySQL support in PHP5 yet.

6 Getting MySQL Support In PHP5

To get MySQL support in PHP, we can install the php5-mysql package. It’s a good idea to install some other PHP5 modules as well as you might need them for your applications. You can search for available PHP5 modules like this:

apt-cache search php5

Pick the ones you need and install them like this:

apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

Now restart Apache2:

/etc/init.d/apache2 restart

APC is a free and open PHP opcode cacher for caching and optimizing PHP intermediate code. It’s similar to other PHP opcode cachers, such as eAccelerator and Xcache. It is strongly recommended to have one of these installed to speed up your PHP page.

APC can be installed as follows:

apt-get install php-apc

Now restart Apache:

/etc/init.d/apache2 restart

Now reload http://192.168.0.100/info.php in your browser and scroll down to the modules section again. You should now find lots of new modules there, including the MySQL module:

Click to enlarge

7 phpMyAdmin

phpMyAdmin is a web interface through which you can manage your MySQL databases. It’s a good idea to install it:

apt-get install phpmyadmin

You will see the following questions:

Web server to reconfigure automatically: <– apache2
Configure database for phpmyadmin with dbconfig-common? <– No

Afterwards, you can access phpMyAdmin under http://192.168.0.100/phpmyadmin/: