OSX: Apache & Tomcat Auto Start Port 80 thru AJP
- Configure Apache
- Auto Start Apache on Boot
- Install Tomcat
- Configure Tomcat
- Auto Start Tomcat on Boot
- Connect Tomcat to Apache
- Backup original httpd.conf
cp /etc/apache2/httpd.conf /etc/apache2/httpd.bkp.conf
- Create your own apache dir
mkdir ~/{PATH}/apache/ ~/{PATH}/apache/conf ~/{PATH}/apache/htdocs ~/{PATH}/apache/logs
- Copy httpd.conf to your apache conf dir
cp /etc/apache2/httpd.conf ~/{PATH}/apache/conf/
- Copy http-vhost.conf to your apache conf dir
cp /etc/apache2/extra/httpd-vhost.conf ~/{PATH}/apache/conf/
- Edit your new ~/{PATH}/apache/conf/httpd.conf file
- Enable (uncomment) the
php5_module
- Change ServerAdmin to your email
- Change DocumentRoot to
~/{PATH}/apache/htdocs
- Change the root Directive to
<Directory "~/{PATH}/apache/htdocs">
- Add
index.php
to DirectoryIndex - Enable (uncomment) the Virtual hosts config include and change the path to your conf file at
~/{PATH}/apache/conf/httpd-vhost.conf
- Enable (uncomment) the
- Make apache's main conf file do nothing other than include your conf file
echo -n "Include ~/{PATH}/apache/conf/httpd.conf" > /etc/apache2/httpd.conf
- Restart Apache:
sudo apachectl restart
- You should see an empty directory listing at http://localhost
- Auto Start Permanently (-w):
sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist
- Remove Auto Start
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
cp /etc/apache2/httpd.conf /etc/apache2/httpd.bkp.conf
mkdir ~/{PATH}/apache/ ~/{PATH}/apache/conf ~/{PATH}/apache/htdocs ~/{PATH}/apache/logs
cp /etc/apache2/httpd.conf ~/{PATH}/apache/conf/
cp /etc/apache2/extra/httpd-vhost.conf ~/{PATH}/apache/conf/
echo -n "Include ~/{PATH}/apache/conf/httpd.conf" > /etc/apache2/httpd.conf
sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist
sudo vi ~/{PATH}/apache/conf/httpd.conf
Edit your custom http.conf file (#5)
sudo apachectl restart
- Install the Homebrew Package Manager http://brew.sh/#install
- Install tomcat via Homebrew:
brew install tomcat
-
Create your own tomcat dir
mkdir ~/{PATH}/tomcat/ ~/{PATH}/tomcat/conf ~/{PATH}/tomcat/bin ~/{PATH}/tomcat/logs
-
Allow group write on logs & files inherit directory permissions
sudo chmod 775 ~/{PATH}/tomcat/logs
sudo chmod +a "admin allow list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity,file_inherit,directory_inherit" ~/{PATH}/tomcat/logs
-
Edit webapps directory to Catalina Home in server.xml
sudo vi ~/{PATH}/tomcat/conf/server.xml
This Line
<Host name="localhost" appBase="${catalina.home}/webapps"
-
Create global CATALINA environment variables at startup
sudo touch /etc/launchd.conf sudo vi /etc/launchd.conf
Add These lines:
setenv CATALINA_HOME /{original tomcat install dir i.e. which catalina} setenv CATALINA_BASE ~/{PATH}/tomcat
-
Create tomcat Launch Daemon script
sudo touch ~/{PATH}/tomcat/bin/tomcat-launchd.sh sudo chown root:admin ~/{PATH}/tomcat/bin/tomcat-launchd.sh sudo chmod a+x ~/{PATH}/tomcat/bin/tomcat-launchd.sh sudo vi ~/{PATH}/tomcat/bin/tomcat-launchd.sh
Content:
#!/bin/bash # NOTE: this is an OSX launchd wrapper shell script for Tomcat (to be placed in $CATALINA_HOME/bin) function shutdown() { date echo "Shutting down Tomcat" $CATALINA_HOME/bin/catalina.sh stop } date echo "Starting Tomcat" export CATALINA_PID=/tmp/$$ # Uncomment to increase Tomcat's maximum heap allocation # export JAVA_OPTS=-Xmx512M $JAVA_OPTS . $CATALINA_HOME/bin/catalina.sh start # Allow any signal which would kill a process to stop Tomcat trap shutdown HUP INT QUIT ABRT KILL ALRM TERM TSTP echo "Waiting for `cat $CATALINA_PID`" wait `cat $CATALINA_PID`
-
Create property list file for tomcat
sudo touch /Library/LaunchDaemons/org.apache.tomcat.plist sudo vi /Library/LaunchDaemons/org.apache.tomcat.plist
Content:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>org.apache.tomcat</string> <key>OnDemand</key> <false/> <key>RunAtLoad</key> <true/> <key>ProgramArguments</key> <array> <string>~/{PATH}/tomcat/bin/tomcat-launchd.sh</string> </array> <key>ServiceDescription</key> <string>Tomcat</string> <key>StandardErrorPath</key> <string>~/{PATH}/tomcat/logs/tomcat-launchd-errors.log</string> <key>StandardOutPath</key> <string>~/{PATH}/tomcat/logs/tomcat-launchd-output.log</string> <key>UserName</key> <string>root</string> </dict> </plist>
-
Load the property list file as a Launch Daemon at startup
- Auto Start Permanently (-w):
sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.tomcat.plist
- Remove Auto Start
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.tomcat.plist
- Auto Start Permanently (-w):
mkdir ~/{PATH}/tomcat/ ~/{PATH}/tomcat/conf ~/{PATH}/tomcat/bin ~/{PATH}/tomcat/logs
sudo chmod 775 ~/{PATH}/tomcat/logs
sudo chmod +a "admin allow list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity,file_inherit,directory_inherit" ~/{PATH}/tomcat/logs
sudo vi ~/{PATH}/tomcat/conf/server.xml
Edit your custom server.xml file (#3)
sudo touch /etc/launchd.conf
sudo vi /etc/launchd.conf
Edit launchd.conf (#4)
sudo touch ~/{PATH}/tomcat/bin/tomcat-launchd.sh
sudo chown root:admin ~/{PATH}/tomcat/bin/tomcat-launchd.sh
sudo chmod a+x ~/{PATH}/tomcat/bin/tomcat-launchd.sh
sudo vi ~/{PATH}/tomcat/bin/tomcat-launchd.sh
Create tomcat-launchd.sh (#1)
sudo touch /Library/LaunchDaemons/org.apache.tomcat.plist
sudo vi /Library/LaunchDaemons/org.apache.tomcat.plist
Create launch deamon (#2)
sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.tomcat.plist
-
Add an entry to your hosts file for tomcat
sudo vi /etc/hosts
Add line:127.0.0.1 tomcat
-
Edit your http-vhosts.conf file
sudo vi ~/{PATH}/apache/conf/http-vhosts.conf
Content:NameVirtualHost *:80 # Default <VirtualHost _default_:80> ServerName localhost </VirtualHost> # TOMCAT <VirtualHost *:80> ServerName tomcat ProxyPass / ajp://localhost:8009/ ErrorLog "~/{PATH}/apache/log/tomcat-error_log" CustomLog "~/{PATH}/apache/log/tomcat-access_log" common </VirtualHost>
-
Restart apache
sudo apachectl restart
-
Verify that http://tomcat loads the Tomcat management screens