{"id":201,"date":"2006-01-26T22:10:54","date_gmt":"2006-01-26T22:10:54","guid":{"rendered":"http:\/\/www.bartbusschots.ie\/blog\/?p=201"},"modified":"2014-08-04T20:30:15","modified_gmt":"2014-08-04T20:30:15","slug":"guide-for-installing-tomcat-50-on-os-x-104-tiger","status":"publish","type":"post","link":"https:\/\/www.bartbusschots.ie\/s\/2006\/01\/26\/guide-for-installing-tomcat-50-on-os-x-104-tiger\/","title":{"rendered":"Guide for Installing Tomcat 5.0 on OS X 10.4 Tiger"},"content":{"rendered":"<p>This is a step-by-step guide to installing Tomcat 5.0.x onto OS X 1.4.x. Note that this is the Tomcat branch for the 1.4 JDK and not for the 1.5 JDK. I know the latest versions of OS X now have Java 5 as part of the OS but my work is not yet ready to migrate to Java 5 so I&#8217;m staying with Tomcat 5.0 for now. The chances are that these instructions with only tiny and obvious alterations will work for Tomcat 5.5 with Java 5 but I&#8217;m not making any promises.<!--more--><\/p>\n<p>These instructions result in a Tomcat install that does things the <em>RightWay<sub>(tm)<\/sub><\/em> and results in a Tomcat service that does not run as root, starts on boot, can be turned on and off with <code>\/etc\/hostconfig<\/code>, runs headless to allow your web apps to use AWT classes and provides you with nice aliases for starting and stopping Tomcat as well as getting at the main log file.<\/p>\n<h2>Step 1 &#8211; Install the Files<\/h2>\n<p>Download and extract the core package in latest stable binary distribution in the 5.0 branch of Tomcat from <a title=\"Tomcat Home Page\" href=\"http:\/\/tomcat.apache.org\/\">http:\/\/tomcat.apache.org\/<\/a> (currently 5.0.28). Then fire-up a terminal with root privileges (you can get to root with <strong><code>sudo bash<\/code><\/strong>) and move the folder you extracted (<code>jakarta-tomcat-5.0.28<\/code>) to <code>\/usr\/local\/<\/code> with <strong><code>mv jakarta-tomcat-5.0.28 \/usr\/local\/<\/code><\/strong>. Then, to make things easier in the future when upgrading tomcat and to make things easier in general you should create a simlink called <code>tomcat<\/code> to the full name of the tomcat folder with <strong><code>ln -s \/usr\/local\/jakarta-tomcat-5.0.28 \/usr\/local\/tomcat<\/code><\/strong>.<\/p>\n<h2>Step 2 &#8211; Set the Needed Environment Variables<\/h2>\n<p>Still with your root terminal open <code>\/etc\/profile<\/code> with your favorite editor (for me that would be vi). We now need to add two environment variables, <code>JAVA_HOME<\/code> to tell Tomcat what JVM to use and <code>CATALINA_HOME<\/code> to tell Tomcat where to find itself. Because we are installing Tomcat 5.0 and not 5.5 we need to make <code>JAVA_HOME<\/code> point at the 1.4 JDK and not the 1.5 JDK. To set these variables add the following to the bottom of <code>\/etc\/profile<\/code>:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n#For Tomcat\r\nexport JAVA_HOME=\/System\/Library\/Frameworks\/JavaVM.framework\/Versions\/1.4.2\/Home\r\nexport CATALINA_HOME=\/usr\/local\/tomcat\r\n<\/pre>\n<p>Then re-start your terminal for those changes to be noticable. You should now be able to start Tomcat with <strong><code>sudo \/usr\/local\/tomcat\/bin\/startup.sh<\/code><\/strong> and stop it with <strong><code>sudo \/usr\/local\/tomcat\/bin\/shutdown.sh<\/code><\/strong>.<\/p>\n<h2>Step 3 &#8211; Creat a Tomcat User and Group<\/h2>\n<p>You should create the user using the Accounts pane in the System Preferences App. Since this user will never need to log in you should set the password to something very long and very secure and don&#8217;t worry if you won&#8217;t remember it! The simplest thing is to call the user tomcat. When you create a user a group with the same name is automatically created as well so we don&#8217;t have to do that explicitly.<\/p>\n<p>You now need to set this new user and group to own the Tomcat folder with <strong><code>chown -R tomcat:tomcat \/usr\/local\/jakarta-tomcat-5.0.28<\/code><\/strong>.<\/p>\n<h2>Step 4 &#8211; Create a Startup Item<\/h2>\n<p>Again, get yourself a root terminal and go to the folder <code>\/Library\/StartupItems\/<\/code>. Then create a new folder for the Tomcat startup item with <strong><code>mkdir Tomcat<\/code><\/strong> and change into that folder with <strong><code>cd Tomcat<\/code><\/strong>. Then, with your favorite editor create a file called <code>Tomcat<\/code> and add the following content to it:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n#!\/bin\/sh\r\n\r\n. \/etc\/rc.common\r\nexport JAVA_HOME=&quot;\/System\/Library\/Frameworks\/JavaVM.framework\/Versions\/1.4.2\/Home&quot;\r\nexport CATALINA_HOME=&quot;\/usr\/local\/tomcat&quot;\r\nexport JAVA_OPTS=&quot;-Djava.awt.headless=true&quot;\r\n\r\nif &#x5B; &quot;${TOMCAT}&quot; = &quot;-YES-&quot; ]; then\r\n  ConsoleMessage &quot;Starting Tomcat&quot;\r\n  su tomcat - \/usr\/local\/tomcat\/bin\/startup.sh\r\nfi\r\n<\/pre>\n<p>Note that this version of the file runs Tomcat in so called Headless mode to allow you to play with cool graphics stuff from within your Servlets etc. For more see <a title=\"Decapitating java.awt!\" href=\"\/blog\/?p=136\">Decapitating java.awt!<\/a>.<\/p>\n<p>Next using your favorite editor again create another file called <code>StartupParameters.plist<\/code> and add the following content to it:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n{\r\n    Description     = &quot;Tomcat&quot;;\r\n    Provides        = (&quot;Tomcat&quot;);\r\n    Requires        = (&quot;Resolver&quot;);\r\n    OrderPreference = &quot;None&quot;;\r\n    Messages =\r\n    {\r\n        start = &quot;Starting Tomcat&quot;;\r\n        stop  = &quot;Stopping Tomcat&quot;;\r\n    };\r\n}\r\n<\/pre>\n<p>Before we leave this folder we need to ensure that all the permissions are right. The <code>Tomcat<\/code> folder and both files in it should be owned by <code>root:wheel<\/code>, the folder should have permissions <code>drwxr-xr-x<\/code> as should the file <code>Tomcat<\/code>. <code>StartupParameters.plist<\/code> should have permissions <code>-rw-r--r--<\/code>.<\/p>\n<p>Next you need to edit <code>\/etc\/hostconfig<\/code> to add the line below to the end of the file:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nTOMCAT=-YES-\r\n<\/pre>\n<h2>Step 5 &#8211; Create a Controller Script<\/h2>\n<p>To easily stop and start tomcat running as our non-root user and headless we need a script. Tomcat often gets very grumpy when running as a non-root user if it does not own everything in it&#8217;s folders so my script also sets the ownership of the tomcat folders correctly before starting Tomcat. I called this script <code>tomcatCtrl.pl<\/code> and put it in <code>\/Library\/StartupItems\/Tomcat\/<\/code>. The script should contain the following:<\/p>\n<pre class=\"brush: perl; title: ; notranslate\" title=\"\">\r\n#!\/usr\/bin\/perl\r\nuse strict;\r\n$|++;\r\n\r\n\r\n#\r\n# Tomcat Controler\r\n#\r\n\r\n#\r\n# Define constants\r\n#\r\n\r\nmy $tomcatStartupItem = &#039;\/Library\/StartupItems\/Tomcat\/Tomcat&#039;;\r\nmy $tomcatHome = &#039;\/usr\/local\/tomcat&#039;;\r\nmy $tomcatUser = &#039;tomcat&#039;;\r\nmy $tomcatGroup = &#039;tomcat&#039;;\r\n\r\n#\r\n# Don&#039;t edit any lines below here\r\n#\r\n\r\n# first ensure we are root\r\nmy $uname = `whoami`;\r\nunless($uname =~ m\/root\/){\r\n  print &quot;\\nERROR - tomcatCtrl.pl must be run as root. Please use sudo.\\n\\n&quot;;\r\n  exit;\r\n}\r\n\r\n# then ensure we have one argument and that it is either &#039;start&#039; or &#039;stop&#039;\r\nunless(scalar(@ARGV) == 1){\r\n  print &quot;\\nERROR - tomcatCtrl.pl takes 1 argument, either &#039;start&#039; or &#039;stop&#039;\\n\\n&quot;;\r\n  exit;\r\n}\r\nmy $act = $ARGV&#x5B;0];\r\nunless($act eq &#039;start&#039; || $act eq &#039;stop&#039;){\r\n  print &quot;\\nERROR - the argument to tomcatctrl must be either &#039;start&#039; or &#039;stop&#039;\\n\\n&quot;;\r\n  exit;\r\n}\r\n\r\n# then chown the web-apps folder to the right user to ensure we don&#039;t have any funny business\r\nmy $execString = &quot;chown -R $tomcatUser:$tomcatGroup $tomcatHome\/webapps&quot;;\r\nprint &quot;\\nEnsuring the tomcat user owns all the files in the webapps folder:\\n   $execString&quot;;\r\nprint `$execString`.&quot;\\n&quot;;\r\n\r\n# if we&#039;re bringing tomcat up, do so\r\nif($act eq &#039;start&#039;){\r\n  $execString = &quot;cd \/;$tomcatStartupItem start&quot;;\r\n  print &quot;\\n\\nBringing up Tomcat - $execString\\n&quot;;\r\n  print `$execString`;\r\n}\r\n\r\n# if we&#039;re bring tomcat down, do so\r\nif($act eq &#039;stop&#039;){\r\n  $execString = &quot;$tomcatHome\/bin\/shutdown.sh stop&quot;;\r\n  print &quot;\\n\\nBringing down Tomcat - $execString\\n&quot;;\r\n  print `$execString`;\r\n}\r\n<\/pre>\n<p>Before this script will work you will have to make it executable with: <strong><code>sudo chmod 755 \/Library\/StartupItems\/Tomcat\/tomcatCtrl.pl<\/code><\/strong>.<\/p>\n<h2>Step 6 &#8211; (Optional) Add Aliases<\/h2>\n<p>Rather than adding these aliases globally I think it&#8217;s better to just put them into your own account so open up a terminal as yourself. Then use your favorite editor to edit <code>~\/.bash_profile<\/code> and add the following lines to the end:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# Tomcat Aliases\r\nalias tomcatup=&quot;sudo \/Library\/StartupItems\/Tomcat\/tomcatCtrl.pl start&quot;\r\nalias tomcatdown=&quot;sudo \/Library\/StartupItems\/Tomcat\/tomcatCtrl.pl stop&quot;\r\nalias tomcatlog=&quot;tail -f \/usr\/local\/tomcat\/logs\/catalina.out&quot;\r\n<\/pre>\n<p>And that&#8217;s it! You now have a tomcat install that starts on boot, runs as a non-privileges user and can be easily started and stopped.<\/p>\n<h2 style=\"color: red\">Note (added 06 July 2006):<\/h2>\n<p style=\"color: red\">Depending on how you extract the tomcat files from the archive you download from their web page you may have to manually edit the permissions of some files in Tomcat&#8217;s <code>bin<\/code> directory. If you get an error saying something like <em>&#8220;startup.sh not found&#8221;<\/em> then change into the <code>bin<\/code> directory and set the permissions to 755:<\/p>\n<p style=\"color:red\"><strong><code>cd \/usr\/local\/tomcat\/bin<br \/>sudo chmod 755 *.sh<\/code><\/strong><\/p>\n<p>[tags]Tomcat, OS X[\/tags]<\/p>\n<h3><em>Note<\/em><\/h3>\n<p><em>This post was initially posted to my old blog <a href=\"http:\/\/www.minds.nuim.ie\/~voyager\/blog\/index.php?\/archives\/73-Guide-for-Installing-Tomcat-5.0-on-OS-X-10.4-Tiger.html\" title=\"Original post\">here<\/a> . Comments may no longer be posted there and should be posted here but there are still old comments there that people may be interested in.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a step-by-step guide to installing Tomcat 5.0.x onto OS X 1.4.x. Note that this is the Tomcat branch for the 1.4 JDK and not for the 1.5 JDK. I know the latest versions of OS X now have Java 5 as part of the OS but my work is not yet ready to [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[12,16],"tags":[422,5,408,26,458,421],"series":[],"class_list":["post-201","post","type-post","status-publish","format-standard","hentry","category-computers-tech","category-programming","tag-apache-tomcat","tag-java","tag-open-source","tag-os-x","tag-tutorial","tag-web-server"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p7t9xK-3f","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/posts\/201","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/comments?post=201"}],"version-history":[{"count":1,"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/posts\/201\/revisions"}],"predecessor-version":[{"id":7421,"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/posts\/201\/revisions\/7421"}],"wp:attachment":[{"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/media?parent=201"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/categories?post=201"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/tags?post=201"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/series?post=201"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}