How to Install Tomcat on Ubuntu and Enable HTTPS / SSL
Posted: Wed Dec 01, 2010 12:22 pm
Update
12-9-2010 - Added some extra notes + how to fix transcoding with Ubuntu
12-10-2010 - Added code to copy ffmpeg and lame to transcoding folder + improved look
1-1-2010 - Updated some links to run as user instead of root and also a better init file.
1-31-2010 - Fixed some Typos
Well after creating this walk-though for windows i've seen a few people asking how to do this for Ubuntu so here it is. I hope it works
The same walk through for windows. http://forum.subsonic.org/forum/viewtopic.php?t=4247
I've been doing my best to keep this simple but it keeps growing as people suggest more. In the end all we are doing is installing java + tomcat and then copying the subsonic.war file to a folder.
Ok lets start out by opening a terminal and type in the following commands.
-------------------------------------------------------------------------------------------------------------------------------------
Optional Additions to Tomcat If you want your http port to auto forward to https then add the following to /usr/local/tomcat6/conf/web.xml and from now on when you browse to your website http://whatever/subsonic it will forward to https://whatever/subsonic
Put this code in between <web-app> code below </web-app>
-------------------------------------------------------------------------------------------------------------------------------------
Mapping a drive to windows
If you want to keep this share on reboot.
Then enter the following code in fstab
-------------------------------------------------------------------------------------------------------------------------------------
How Run Tomcat without Root Privileges.
Here are a couple other links but this is my own modification so feel free to let me know if i need to change anything.Site 1Site 2
1st. Create a limited user. Example: subsonicuser
2nd. Create a limted group. Example: subsonicgroup < don't forget to link the usernames to the group.
Don't forget to set TOMCAT_HOME - JAVA_HOME - USERNAME
[*]Then press shift+Q and a colen will pop up. type w and enter to save.
[*]Then type q! and enter to quit.
[*]If you want to verify the file then type the following and it will allow you to read the file you just created.
[*]Next change the security permissions required to execute the file.
You will need to do the following command on any folder that you would like to share with the subsonicgroup
Then do a reboot.
To verify this try the top command or install htop sudo apt-get install htop then use the command htop
-------------------------------------------------------------------------------------------------------------------------------------
Note: Problems that might crop up.
Problems with subsonic page loading or being slow
-------------------------------------------------------------------------------------------------------------------------------------
Problems with slowness or Jukebox mode not playing music.
-------------------------------------------------------------------------------------------------------------------------------------
Subsonic won't play WMA files. Well then give this a shot. Thanks drifter
-------------------------------------------------------------------------------------------------------------------------------------
Well it's not the prettiest walk though but it should work.. Let me know if there is anything that i need to change.
Enjoy,
Sean K
12-9-2010 - Added some extra notes + how to fix transcoding with Ubuntu
12-10-2010 - Added code to copy ffmpeg and lame to transcoding folder + improved look
1-1-2010 - Updated some links to run as user instead of root and also a better init file.
1-31-2010 - Fixed some Typos
Well after creating this walk-though for windows i've seen a few people asking how to do this for Ubuntu so here it is. I hope it works
The same walk through for windows. http://forum.subsonic.org/forum/viewtopic.php?t=4247
I've been doing my best to keep this simple but it keeps growing as people suggest more. In the end all we are doing is installing java + tomcat and then copying the subsonic.war file to a folder.
Ok lets start out by opening a terminal and type in the following commands.
- First we'll need to install Java.
- Code: Select all
sudo apt-get install openjdk-6-jre
- Next we'll need to install tomcat so lets change to the download directory.
- Code: Select all
cd /home/username/Downloads
- Then Download Tomcat
- Code: Select all
wget http://apache.deathculture.net//tomcat/tomcat-6/v6.0.29/bin/apache-tomcat-6.0.29.tar.gz
- Next Uzip the tar file.
- Code: Select all
tar xvzf apache-tomcat-6.0.29.tar.gz
- Then move the tomcat folder.
- Code: Select all
sudo mv apache-tomcat-6.0.29 /usr/local/tomcat6
- Next we are going to setup tomcat to show it where the java directory is and the startup.
- Code: Select all
sudo vi /etc/init.d/tomcat6
- Then press i to insert and type the following.
- Code: Select all
# Tomcat auto-start
#
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
case $1 in
start)
sh /usr/local/tomcat6/bin/startup.sh
;;
stop)
sh /usr/local/tomcat6/bin/shutdown.sh
;;
restart)
sh /usr/local/tomcat6/bin/shutdown.sh
sh /usr/local/tomcat6/bin/startup.sh
;;
esac
exit 0
- Then press shift+Q and a colen will pop up. type w and enter to save.
- Then type q! and enter to quit.
- If you want to verify the file then type the following and it will allow you to read the file you just created.
- Code: Select all
cat /etc/init.d/tomcat6
- Next change the security permissions required to execute the file.
- Code: Select all
sudo chmod 755 /etc/init.d/tomcat6
- Then Link the startup and shutdown.
- Code: Select all
sudo ln -s /etc/init.d/tomcat6 /etc/rc1.d/K99tomcat
- Code: Select all
sudo ln -s /etc/init.d/tomcat6 /etc/rc2.d/S99tomcat
- Code: Select all
sudo ln -s /etc/init.d/tomcat6 /etc/rc0.d/K99tomcat
- Code: Select all
sudo ln -s /etc/init.d/tomcat6 /etc/rc6.d/K99tomcat
- To restart tomcat type the following
- Code: Select all
sudo /etc/init.d/tomcat6 restart
- Then browse to http://127.0.0.1:8080 from ubuntu or http://x.x.x.x:8080 from another computer. The tomcat page should now show up. If it doesn't then try a reboot.
- Next, time to install Subsonic.
- Make sure that you're still in the download directory.
- Code: Select all
cd /home/username/Downloads
- Then download Subsonic.
- Code: Select all
wget http://sourceforge.net/projects/subsonic/files/subsonic/4.2/subsonic-4.2-war.zip/download
- Lets then unzip subsonic.war
- Code: Select all
unzip subsonic-4.2-war.zip
- Next Move subsonic.war to webapps.
- Code: Select all
sudo mv subsonic.war /usr/local/tomcat6/webapps
- Next Stop the tomcat Service
- Code: Select all
sudo /etc/init.d/tomcat6 stop
- Wait a couple seconds then start the tomcat service.
- Code: Select all
sudo /etc/init.d/tomcat6 start
- you should now be able to browse to
then browse to http://127.0.0.1:8080/subsonic from ubuntu or http://x.x.x.x:8080/subsonic from another computer. - don't forget transcoding.
- Code: Select all
sudo apt-get install lame flac faad vorbis-tools ffmpeg
- Code: Select all
sudo cp /usr/bin/ffmpeg /var/subsonic/transcode
- Code: Select all
sudo cp /usr/bin/lame /var/subsonic/transcode
- Next Lets setup the Encryption. First you will need to change the values in red and possibly your java location if you have a different version installed.
>>sudo /usr/lib/jvm/java-6-openjdk/bin/keytool -genkey -alias tomcat -keyalg RSA -dname "CN=domainname, OU=Subsonic, O=Loving Music Inc, L=City, S=State, C=US" -validity 3650 -keystore /usr/local/tomcat6/tomcat.ks -storepass secretpassword -keypass secretpassword<< Code is in between the arrows.
Code Meaning
CN=commonName "Domain Name"
OU=organizationUnit "Department or Division"
O=organizationName "Company Inc"
L=localityName "City Name"
S=stateName "State Name"
C=country "Country Code i.e US" - Next lets configure tomcat to enable SSL
- Code: Select all
sudo vi /usr/local/tomcat6/conf/server.xml
- Then press i to insert and type the following and use the delete key to delete text.
- First find and remove the <!-- and --> from the code.
- Code: Select all
<!--
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->
- And then add the following two lines keystoreFile="tomcat.ks", keystorePass="secretpassword" and modify the protocol="org.apache.coyote.http11.Http11Protocol" to the code making it look like the example below. Don't forget to put your secret password that you used keystorePass="secretpassword".
- The Connector Port is the port that you will be logging into. Example https://localhost:8443/subsonic non-encrypted it will be on http://localhost:8080/subsonic by default
- Code: Select all
<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
keystoreFile="tomcat.ks"
keystorePass="secretpassword"
clientAuth="false" sslProtocol="TLS" />
- Then press shift+Q and a colen will pop up. type w and enter to save.
- Then type q! and enter to quit.
- To view the file after you are done type the following.
- Code: Select all
cat /usr/local/tomcat6/conf/server.xml
- Then stop tomcat.
- Code: Select all
sudo /etc/init.d/tomcat6 stop
- Wait and then start tomcat back up.
- Code: Select all
sudo /etc/init.d/tomcat6 start
-------------------------------------------------------------------------------------------------------------------------------------
Optional Additions to Tomcat If you want your http port to auto forward to https then add the following to /usr/local/tomcat6/conf/web.xml and from now on when you browse to your website http://whatever/subsonic it will forward to https://whatever/subsonic
Put this code in between <web-app> code below </web-app>
- Code: Select all
<security-constraint>
<web-resource-collection>
<web-resource-name>Protected Context</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<!-- auth-constraint goes here if you require authentication -->
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
-------------------------------------------------------------------------------------------------------------------------------------
Mapping a drive to windows
- Code: Select all
sudo mkdir -p /mnt/music
- Code: Select all
sudo mount -t cifs //serverip/sharename -o username=johndoe,password=johnspassword /mnt/music
If you want to keep this share on reboot.
- Code: Select all
sudo vi /etc/fstab
Then enter the following code in fstab
- Code: Select all
//serverip/sharename /mnt/music cifs username=johndoe,password=johnspassword 0 0
-------------------------------------------------------------------------------------------------------------------------------------
How Run Tomcat without Root Privileges.
Here are a couple other links but this is my own modification so feel free to let me know if i need to change anything.Site 1Site 2
1st. Create a limited user. Example: subsonicuser
2nd. Create a limted group. Example: subsonicgroup < don't forget to link the usernames to the group.
- Code: Select all
sudo vi /etc/init.d/tomcat6
Don't forget to set TOMCAT_HOME - JAVA_HOME - USERNAME
- Code: Select all
#!/bin/bash
# Tomcat auto-start
#
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid
RETVAL=$?
TOMCAT_HOME=/usr/local/tomcat6
export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.22
USERNAME=subsonicuser
case $1 in
start)
if [ -f $TOMCAT_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
/bin/su $USERNAME $TOMCAT_HOME/bin/startup.sh
fi
;;
stop)
if [ -f $TOMCAT_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
/bin/su $USERNAME $TOMCAT_HOME/bin/shutdown.sh
fi
;;
restart)
echo $"Restarting Tomcat"
/bin/su $USERNAME $TOMCAT_HOME/bin/shutdown.sh
/bin/su $USERNAME $TOMCAT_HOME/bin/startup.sh
;;
esac
exit $RETVAL
[*]Then press shift+Q and a colen will pop up. type w and enter to save.
[*]Then type q! and enter to quit.
[*]If you want to verify the file then type the following and it will allow you to read the file you just created.
- Code: Select all
cat /etc/init.d/tomcat6
[*]Next change the security permissions required to execute the file.
- Code: Select all
sudo chmod 755 /etc/init.d/tomcat6
- Code: Select all
sudo chown yourusername:subsonicgroup -R /usr/local/tomcat6
- Code: Select all
sudo chmod -R 775 /usr/local/tomcat6
- Code: Select all
sudo chown yourusername:subsonicgroup -R /var/subsonic
- Code: Select all
sudo chmod -R 775 /var/subsonic
You will need to do the following command on any folder that you would like to share with the subsonicgroup
Then do a reboot.
To verify this try the top command or install htop sudo apt-get install htop then use the command htop
-------------------------------------------------------------------------------------------------------------------------------------
Note: Problems that might crop up.
Problems with subsonic page loading or being slow
- First try a reboot.
-------------------------------------------------------------------------------------------------------------------------------------
Problems with slowness or Jukebox mode not playing music.
- Try installing sun-java6-jdk vs the java-6-openjdk Thanks gygys
- Code: Select all
sudo update-alternatives --config java
- Code: Select all
sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
- Code: Select all
sudo apt-get update
- Code: Select all
sudo apt-get install sun-java6-jdk
- Code: Select all
sudo update-alternatives --config java
- Code: Select all
sudo vi /etc/init.d/tomcat6
- Code: Select all
export JAVA_HOME=/usr/lib/jvm/java-6-sun
Ubuntu 10.03 or below try
Ubuntu 10.04 or above the Sun JDK is hidden away.
Then select java-6-sun
Next we'll need to fix the Java location in the following file.
Then press i and change the JAVA_HOME.
Then press shift+Q and a colen will pop up. type w and enter to save.
Then type q! and enter to quit.
Then do a reboot.
-------------------------------------------------------------------------------------------------------------------------------------
Subsonic won't play WMA files. Well then give this a shot. Thanks drifter
- I hope that you already installed lame and ffmpeg which is explained above in the walkthrough.
- Code: Select all
cd /home/username/Downloads
- Code: Select all
sudo vi wma2mp3
- Code: Select all
#!/bin/bash
ffmpeg -i "$1" -f wav -ab "$2" - 2>/dev/null | /var/subsonic/transcode/lame -b "$2" - -
#- Code: Select all
sudo mv wma2mp3 /var/subsonic/transcode
- Code: Select all
sudo chmod 755 /var/subsonic/transcode/wma2mp3
1st.) Change to the downloads directory
2nd.) create a script called wma2mp3
3rd.) Then Enter the following code you will need to press i to insert the code.
Then press shift+Q and a colen will pop up. type w and enter to save.
Then type q! and enter to quit.
4th.) move the wma2pm3 script to the transcode folder
5th.) convert the script to an executable
6th.) log into subsonic > Settings > Transcoding
Name = wma > mp3
Convert From = wma
Convert to = mp3
Step 1 = wma2mp3 %s %b
-------------------------------------------------------------------------------------------------------------------------------------
Well it's not the prettiest walk though but it should work.. Let me know if there is anything that i need to change.
Enjoy,
Sean K