Apache Tomcat is an open-source implementation of the Java Servlet, JavaServer Pages, Java Expression Language, and Java WebSocket technologies. It is one of the most widely adopted application and web servers in the world today. Tomcat is simple to use and has a robust ecosystem of add-ons.
This tutorial explains how to install and configure Tomcat 9 on Ubuntu 18.04. The same instructions apply for Ubuntu 16.04 and any Ubuntu-based distribution, including Linux Mint and Elementary OS.
Prerequisites
To be able to install packages on your Ubuntu system, you must be logged in as a user with sudo privileges .
Step 1: Install OpenJDK
Tomcat requires Java to be installed. We’ll install OpenJDK , which is the default Java development and runtime in Ubuntu 18.04.
The installation of Java is pretty simple. Begin by updating the package index:
sudo apt update
Install the OpenJDK package by running:
sudo apt install default-jdk
Step 2: Create Tomcat User
For security purposes, Tomcat should not be run under the root user. We will create a new system user and group with home directory /opt/tomcat that will run the Tomcat service:
At the time of writing, the latest version is 9.0.27. Before continuing with the next step, you should check the download page for a new version. If there is a new version, copy the link to the Core tar.gz file, which is under the Binary Distributions section.
Start by download the Tomcat archive in the /tmp directory using the following wget command:
CopyModify the value of JAVA_HOME if the path to your Java installation is different.
Save and close the file and notify systemd that we created a new unit file:
sudo systemctl daemon-reload
Start the Tomcat service by executing:
sudo systemctl start tomcat
Check the service status with the following command:
sudo systemctl status tomcat
* tomcat.service - Tomcat 9 servlet container
Loaded: loaded (/etc/systemd/system/tomcat.service; disabled; vendor preset: enabled)
Active: active (running) since Wed 2018-09-05 15:45:28 PDT; 20s ago
Process: 1582 ExecStart=/opt/tomcat/latest/bin/startup.sh (code=exited, status=0/SUCCESS)
Main PID: 1604 (java)
Tasks: 47 (limit: 2319)
CGroup: /system.slice/tomcat.service
If there are no errors enable the Tomcat service to be automatically started at boot time:
sudo systemctl enable tomcat
Step 5: Adjust the Firewall
If your server is protected by a firewall and you want to access Tomcat from the outside of your local network, you need to open port 8080.
To allow traffic on port 8080 type the following command:
sudo ufw allow 8080/tcp
Usually when running a Tomcat application in a production environment you will have a load balancer or reverse proxy . It’s a best practice to restrict access to port 8080 only to your internal network.
Step 6: Configure Tomcat Web Management Interface
Now that Tomcat is installed and running, the next step is to create a user with access the web management interface.
Tomcat users and roles are defined in the tomcat-users.xml file. This file is a template with comments and examples describing how to configure user or role.
To add a new user with access to the Tomcat web interface (manager-gui and admin-gui) we need to define the user in the tomcat-users.xml file, as shown below. Make sure you change the username and password to something more secure:/opt/tomcat/latest/conf/tomcat-users.xml
By default Tomcat web management interface is configured to restrict access to the Manager and Host Manager apps only from the localhost.
If you want to be able to access the web interface from a remote IP, you will have to remove these restrictions. This may have various security implications, and it is not recommended for production systems.
To enable access to the web interface from anywhere open the following two files and comment or remove the lines highlighted in yellow.
Another option is to allow access to the to the Manager and Host Manager apps only from a specific IP. Instead of commenting the blocks you can simply add your IP address to the list.
For example if your public IP is 45.45.45.45 you would make the following change:context.xml
The list of allowed IP addresses is a list separated with vertical bar |. You can add single IP addresses or use a regular expressions.
Remember to restart the Tomcat service each time you edit Tomcat configuration files for changes to take effect:
sudo systemctl restart tomcat
Step 6: Test the Tomcat Installation
Open your browser and type: http://<your_domain_or_IP_address>:8080
Assuming the installation is successful, a screen similar to the following should appear:
Tomcat web application manager dashboard is available at http://<your_domain_or_IP_address>:8080/manager/html. From here, you can deploy, undeploy, start, stop, and reload your applications.
You can sign in with the user you have created in Step 6.
Tomcat virtual host manager dashboard is available at http://<your_domain_or_IP_address>:8080/host-manager/html. From here, you can create, delete and manage Tomcat virtual hosts.
Conclusion
You have successfully installed Tomcat 9 on your Ubuntu 18.04 system. You can now visit the official Apache Tomcat 9 Documentation and learn more about the Apache Tomcat features.
Virtualbox ubuntu copy and paste problem Oracle’s VirtualBox allows you copy and paste from the host machine to the guest virtual machine and vice versa. Unfortunately, this feature sometimes does not work properly.
Firstly, be sure you have install the Guest Addition
If it still does not work, you may restart the vboxclient by following commands in terminal
Right click on Certificates and click on All Tasks -> Import …
A new window will be popped up. Select Local Machine if required
Select the CA certificate just downloaded
Once the CA certificate is added, it will appear under Trusted Root Certification Authorities
Close mmc window without save
Done
Adding VPN
Open VPN setting by entering “vpn settings” start
Click on “Add a VPN connection”
Enter the form – Connection name is the name for you to identify the VPN – Server name or address: enter the domain or IP of the VPN server – VPN type: select IKEv2 – Type of sign-in info: Select the appropriate sign in info – User name: VPN account name – Password: VPN account password
Then back to VPN setting windows, click on “Change adapter options”
On the new window, right click on the newly created VPN icon. Then click on “Properties”
On security tab, config as following
The other settings can be kept untouched
Click Ok to close the window
Done
Connect to VPN
On VPN settings page, select the VPN
Click on the Connect button
Common problems
parameter is incorrect
Solution: Reset and clear networking caches Run windows cmd window (click windows start menu, type ‘cmd’, right click on ‘Command Prompt’ and select “Run as Administrator”).
type command below netsh int ip reset netsh int ipv6 reset netsh winsock reset
Restart your computer.
Reset Device Manager adaptors 1. Open Device Manager 2. Find Network Adapters 3. Uninstall WAN Miniport drivers (IKEv2, IP, IPv6, etc) 4. Click Action > Scan for hardware changes 5. The adapters you just uninstalled should come back
Angular adds the word unsafe in front of an iOS app download link. ie the link turns from itms-services://?action=download-manifest&url=https://…manifest.plist into unsafe:itms-services://?action=download-manifest&url=https://...manifest.plist
As a result, the download link does not work. To solve it, we have to use DomSanitizer either in html or in .ts
Be reminded to user attr.href instead of href=..., using href will throw a warning WARNING: sanitizing unsafe URL value SafeValue must use [property]=binding: itms-services://?action=download....
safe.pip.ts
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer, SafeHtml, SafeStyle, SafeScript, SafeUrl, SafeResourceUrl } from '@angular/platform-browser';
@Pipe({
name: 'safe'
})
export class SafePipe implements PipeTransform {
constructor(protected sanitizer: DomSanitizer) {}
public transform(value: any, type: string): SafeHtml | SafeStyle | SafeScript | SafeUrl | SafeResourceUrl {
switch (type) {
case 'html': return this.sanitizer.bypassSecurityTrustHtml(value);
case 'style': return this.sanitizer.bypassSecurityTrustStyle(value);
case 'script': return this.sanitizer.bypassSecurityTrustScript(value);
case 'url': return this.sanitizer.bypassSecurityTrustUrl(value);
case 'resourceUrl': return this.sanitizer.bypassSecurityTrustResourceUrl(value);
default: throw new Error(`Invalid safe type specified: ${type}`);
}
}
}
因為疫情,同事都係一齊訂外賣,之後係公司食,之前大家都係用Whatsapp group 到send 出黎,但成日出事,互overwrite 大家d 野。
所以之前有同事就google sheet 去入data,但我今日竟然無聊到去整靚佢…
有好多無聊functionsssss,睇黎我真係悶到傻了。
function sheetName() {
return SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getName();
}
// update the title
function onOpen() {
setTitle();
}
// reload the whatsapp message when any cell was updated
function onEdit(e) {
var outputRange = SpreadsheetApp.getActiveSpreadsheet().getRange('B21');
outputRange.setValue(generateWhatsappMsg('A3:D17', 'B21'));
}
function setTitle() {
var titleRange = SpreadsheetApp.getActiveSpreadsheet().getRange('A1');
var date = Utilities.formatDate(new Date(), "GMT+8:00", "yyyyMMdd");
titleRange.setValue("今日終於食日本野 " + date);
}
function generateNewSheet() {
var date = Utilities.formatDate(new Date(), "GMT+8:00", "yyyyMMdd");
var todaySheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(date);
if (!todaySheet) {
SpreadsheetApp.getActiveSpreadsheet().duplicateActiveSheet();
SpreadsheetApp.getActiveSpreadsheet().renameActiveSheet(date);
todaySheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(date);
}
SpreadsheetApp.setActiveSheet(todaySheet);
setTitle();
}
function generateWhatsappMsg(range, outRange) {
var inputRange = SpreadsheetApp.getActiveSpreadsheet().getRange(range);
var rangeValues = inputRange.getValues();
var lastRow = inputRange.getLastRow() - 3;
var tel = SpreadsheetApp.getActiveSpreadsheet().getRange('B19').getValue();
var msg = '送餐地點:XXXX\n送餐時間:12:00\n電話:'+tel+'\n\n';
var errorMsg = '';
var foodDict = {}; // key: set (sideDish); val: order count
var drinkDict = {}; // key: drinkId; val: order count
for ( i = 0; i < lastRow; i++){
let name = rangeValues[i][0];
let set = rangeValues[i][1];
let sideDish = rangeValues[i][2];
let drink = rangeValues[i][3];
if (set) {
var foodKey = sideDish? set + '(' + sideDish + ')': set;
if (foodKey in foodDict) {
foodDict[foodKey] = foodDict[foodKey] + 1;
} else {
foodDict[foodKey] = 1;
}
if (!drink) {
errorMsg += name + ' 未選揀飲品\n';
}
}
if (drink) { // if selected drink
if (drink in drinkDict) {
drinkDict[drink] = drinkDict[drink] + 1;
} else {
drinkDict[drink] = 1;
}
if (!set) {
errorMsg += name + ' 未選揀飯餐\n';
}
}
};
// no one eat :(
if (Object.keys(foodDict).length == 0) {
errorMsg = "今日無人食 :(";
}
// looped all people, now generate the message
for ( var foodKey in foodDict) {
msg += foodKey + ": " + foodDict[foodKey] + "\n";
}
msg += '\n';
for ( var drinkKey in drinkDict) {
msg += drinkKey + ": " + drinkDict[drinkKey] + "\n";
}
msg += '\n唔要餐具/糖,謝謝';
if (errorMsg.length>0) {
SpreadsheetApp.getActiveSpreadsheet().getRange(outRange).setBackground('#E6B8AF');
return errorMsg;
} else {
SpreadsheetApp.getActiveSpreadsheet().getRange(outRange).setBackground('white');
return msg;
}
}
iBus binds ctrl + alt + e to enter emoji, but it is quite annoying actually. I did not enter emoji on Ubuntu. More importantly, it collides with the vscode shortcut.
So, how to disable it.
Method 1
In terminal type ibus-setup, go to the emoji tab, and delete the keybindings.