Announce

PukiWiki contents have been moved into SONOTS Plugin (20070703)

LAMP

LAMPセットアップメモ(2004)

CGI,SSI,JSP(&Servlet),PHP,SQL + αが動くようにする。(2004)

必要なもの

  • Apache
  • Java
  • Tomcat
  • mod_webapp.so (Apache と Tomcat の連携用のコネクタ)
  • PHP
  • PostgreSQL
  • Ant (ServletからPostgreSQLへアクセスするための JDBC ドライバ)
  • Cocoon (XML を HTML に変換して表示する、サーブレット。いらない。)

Apache

% tar zxvf httpd-2.0.43.tar.gz
% cd httpd-2.0.43
% ./configure --prefix=/usr/local/apache2 --enable-so
#--enable-shared=max  # if =max, all shared object are installed.
% make
% make install
% vi /usr/local/apache2/conf/httpd.conf
Group #-1 
Group nobody
#ServerName 
ServerName localhost:80 
/usr/local/apache2/bin/apachectl start
http://localhost:80/

ServerAdmin [mail address] 
Listen 80 -> Listen 8080
ServerName [address]:80 -> ServerName [address]:8080
DocumentRoot  
AddHandler cgi-script .cgi  # enable cgi
AddOutputFilter INCLUDES .shtml # enable .shtml
AddType text/html .shtml # enable .shtml 
UserDir disble -> public_html 
#+Include -> enable .shtml (SSI)
<Directory /home/*/public_html>
    AllowOverride FileInfo AuthConfig Limit
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec +Includes
    <Limit GET POST OPTIONS>
        Order allow,deny
        Allow from all
    </Limit>
    <LimitExcept GET POST OPTIONS>
        Order deny,allow
        Deny from all
    </LimitExcept>
</Directory>
#ExecCGI -> enable cgi
#Order allow,deny means that set policy, first allow, and then deny
<Directory /home/*/public_html/cgi-bin>
    AllowOverride FileInfo AuthConfig Limit
    Options MultiViews Indexes SymLinksIfOwnerMatch ExecCGI
    <Limit GET POST OPTIONS>
        Order allow,deny
        Allow from all
    </Limit>
    <LimitExcept GET POST OPTIONS>
        Order deny,allow
        Deny from all
    </LimitExcept>
</Directory>
DirectoryIndex index.html index.html.var -> index.cgi index.shtml 
#But Options None, can exec cgi. Why?
<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>
#pre(end)

#pre
 % /usr/local/apache2/bin/apachectl configtest 
 Syntax OK 
 % w3m http://localhost:8080
% cat > index.html
test
[Ctrl-d]
% w3m http://localhost:8080/~[userid]
% cat > index.cgi
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "tests";
[Ctrl-d]
% chmod 755 index.cgi
% w3m http://localhost:8080/~[userid]/cgi-bin/index.cgi
% cat > index.shtml
<HTML>
This file was modified in
<!--#config timefmt="%Y/%m/%d %X" -->
<!--#echo var="LAST_MODIFIED" -->
</HTML>
[Ctrl-d]
% w3m http://localhost:8080/~[userid]/index.shtml

ブートしたときにシステムが自動実行するように。

% vi /etc/rc.d/init.d/httpd
#!/bin/sh
#
# Startup script for the Apache 2.0 Web Server
#
# chkconfig: 345 85 15
# description: Starts and Stops the Apache 2.0 Web server. 
# processname: httpd
# pidfile: /var/run/httpd.pid
# config: /usr/local/apache2/conf/httpd.conf

# Source function library.
. /etc/rc.d/init.d/functions

# See how we were called.
case "$1" in
  start)
	if [ -f /usr/local/apache2/bin/apachectl ]; then
		echo -n "Starting httpd: "
		daemon "/usr/local/apache2/bin/apachectl start"
		echo
		touch /var/lock/subsys/httpd
	fi
	;;
  stop)
	if [ -f /usr/local/apache2/bin/apachectl ]; then
		echo -n "Shutting down httpd: "
		daemon "/usr/local/apache2/bin/apachectl stop"
		echo
		rm -f /var/lock/subsys/httpd
		rm -f /var/run/httpd.pid
	fi
	;;
  status)
	status httpd
	;;
  restart)
	if [ -f /usr/local/apache2/bin/apachectl ]; then
		echo -n "Restarting httpd: "
		daemon "/usr/local/apache2/bin/apachectl restart"
		echo
	fi
	;;
  *)
	echo "Usage: $0 {start|stop|restart|status}"
	exit 1
esac

exit 0
% chmod 755 /etc/rc.d/init.d/httpd
% /sbin/chkconfig --add httpd
% /sbin/chkconfig --list httpd
httpd   0:off	1:off	2:off	3:on	4:on	5:on	6:off 、ハ、餔K

Java

chmod 755 j2sdk-1_4_1_01-linux-i586-rpm.bin
./j2sdk-1_4_1_01-linux-i586-rpm.bin
yes
rpm -Uhv j2sdk-1_4_1_01-fcs-linux-i586.rpm
vi /etc/profile 
export JAVA_HOME=/usr/java/j2sdk1.4.1_02
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile
#Tomcat use $JAVA_HOME

!!!!!!! Tomcat /etc/tomcat4/conf/tomcat4.conf JAVA_HOME=/usr/java/j2sdk1.4.1_02 !!!!!!!

Tomcat

http://www.apache.inetcosmos.org/dist/jakarta/tomcat-4/binaries/ (tomcat-4.1.18.tar.gz)

tar zxvf tomcat-4.1.18.tar.gz
mkdir /usr/local/tomcat
cp -r jakarta-tomcat-4.1.18/* /usr/local/tomcat
Default port is 8080, Modify the port to 8180. 
When PRM package, default port is 8180.
    <!-- Define a non-SSL Coyote HTTP/1.1 Connector on port 8080 -->
    <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
               port="8080" minProcessors="5" maxProcessors="75"
               enableLookups="true" redirectPort="8443"
               acceptCount="100" debug="0" connectionTimeout="20000"
               useURIValidationHack="false" disableUploadTimeout="true" />
    <!-- Note : To disable connection timeouts, set connectionTimeout value 
     to -1 -->
        <Context path="/~s1080134" 
	docBase="/home/s1080134/public_html" debug="0"
	reloadable="true" crossContext="true">
	</Context>

WebAppDeploy	 /home/s1080134/public_html warpConn /s1080134
# maybe can not use * 

WebAppDeploy	/home/s1080134/public_html/jsp warpConn /~s1080134/jsp/
# /home/s1080134/public_html is Apache's directry, so can not warp the sub-directry. 
# Shit!!

/usr/local/tomcat/bin/catalina.sh start
http://localhost:8180
/usr/local/tomcat/webapps/ROOT/index.jsp

/etc/rc.d/init.d/tomcat 
#!/bin/sh
#
# Startup script for Tomcat, the Apache Servlet Engine
#
# chkconfig: 345 80 20
# description: Tomcat is the Apache Servlet Engine
# processname: tomcat
# pidfile: /var/run/tomcat.pid

# Source function library.
. /etc/rc.d/init.d/functions

# See how we were called.
case "$1" in
  start)
	if [ -f /usr/local/tomcat/bin/catalina.sh ]; then
		echo -n "Starting tomcat: "
		export JAVA_HOME=/usr/java/j2sdk1.4.1_01
		export LANG=ja_JP.eucJP
		daemon --user "nobody" "/usr/local/tomcat/bin/catalina.sh start"
		echo
		touch /var/lock/subsys/tomcat
	fi
	;;
  stop)
	if [ -f /usr/local/tomcat/bin/catalina.sh ]; then
		echo -n "Shutting down tomcat: "
		daemon --user "nobody" "/usr/local/tomcat/bin/catalina.sh stop"
		echo
		rm -f /var/lock/subsys/tomcat
		rm -f /var/run/tomcat.pid
	fi
	;;
  restart)
	$0 stop
	sleep 2
	$0 start
	;;
  *)
	echo "Usage: $0 {start|stop|restart}"
	exit 1
esac

exit 0
chmod 755 /etc/rc.d/init.d/tomcat
/sbin/chkconfig --add tomcat
/sbin/chkconfig --list tomcat
cd /usr/local/tomcat
chown -R nobody.nobody conf
chown -R nobody.nobody work
chown -R nobody.nobody logs
chown -R nobody.nobody temp
!!!!!!!!!!!!!!
       <Context path="/~s1080134" 
	docBase="/home/s1080134/public_html" debug="0"
	reloadable="true" crossContext="true">
	</Context>
!!!!!!!!!!!!!

ANT

Connector (mode_webapp.so) needs ANT before. Why?

http://ant.apache.org/bindownload.cgi (apache-ant-1.5.3-1-bin.tar.gz)

mkdir /usr/local/ant
tar zxvf apache-ant-1.5.3-1-bin.tar.gz
cp -R jakarta-ant-1.5.1/* /usr/local/ant

Connector (mod_webapp.so )

http://jakarta.apache.org/builds/jakarta-tomcat-4.0/archives/v4.1.18/src/jakarta-tomcat-connectors-4.1.18-src.tar.gz

tar zxvf jakarta-tomcat-connectors-4.1.18-src.tar.gz
cd jakarta-tomcat-connectors-4.1.18-src
cd webapp
./support/buildconf.sh
./configure --with-apxs=/usr/local/apache2/bin/apxs --enable-java=/usr/local/tomcat --with-ant=/usr/local/ant/bin/ant

    * --with-apxs : use apache's apxs. 
    * --enable-java : 
    * --with-ant  : Why need it?
    ./configure --help 

make
cp apache-2.0/mod_webapp.so /usr/local/apache2/lib
% vi /usr/local/apache2/conf/httpd.conf

LoadModule webapp_module lib/mod_webapp.so

WebAppConnection warpConn warp     localhost:8008
WebAppDeploy     examples warpConn /examples
WebAppInfo                         /webapp-info
% vi /usr/local/tomcat/conf/server.xml
<!--
  <Service name="Tomcat-Apache">

    <Connector className="org.apache.catalina.connector.warp.WarpConnector"
     port="8008" minProcessors="5" maxProcessors="75"
     enableLookups="true" appBase="webapps"
     acceptCount="10" debug="0"/>

    <Engine className="org.apache.catalina.connector.warp.WarpEngine"
     name="Apache" debug="0">

      <Logger className="org.apache.catalina.logger.FileLogger"
              prefix="apache_log." suffix=".txt"
              timestamp="true"/>

      <Realm className="org.apache.catalina.realm.MemoryRealm" />

    </Engine>

  </Service>
-->

Tomcat must start first, and then apache start.

/usr/local/tomcat/bin/catalina.sh start
/usr/local/apache2/bin/apachectl start
http://localhost:8080/
http://localhost:8180/ #Tomcat own port
http://localhost:8080/examples/ #Apache -> Tomcat 
http://localhost:8080/examples/servlets/index.html
http://localhost:8080/examples/jsp/index.html

Cocoon

http://xml.apache.org/cocoon/mirror.cgi (cocoon-latest-vm14-bin.tar.gz)

cd cocoon-2.0.4/
cp cocoon.war /usr/local/tomcat/webapps

/usr/local/tomcat/bin/catalina.sh stop
/usr/local/tomcat/bin/catalina.sh start

http://localhost:8180/cocoon (8180 is Tomcat port)
/usr/local/tomcat/webapps/cocoon/welcome/welcome.xhtml

Apache-Tomcat-Cocoon 
/usr/local/apache2/conf/httpd.conf 
WebAppDeploy     cocoon   warpConn /cocoon


/usr/local/tomcat/bin/catalina.sh stop
/usr/local/apache2/bin/apachectl stop
/usr/local/tomcat/bin/catalina.sh start
/usr/local/apache2/bin/apachectl start
http://localhost:8080/cocoon

PHP

http://www.php.net/downloads.php (php-4.3.1.tar.gz)

tar zxvf php-4.3.1.tar.gz
cd php-4.3.1
./configure --with-apx2=/usr/local/apache2/bin/apxs --enable-mbstring
--with-apx2  (apache2.X.X  libphp4.so 
--enable-mbstring  (enable multibyte string i.e. Japanese)
--with-pgsql (enable pgsql)--help
make
make install
cp php.ini-dist /usr/local/lib/php.ini #PHP ini 
vi /etc/httpd/conf/httpd.conf 

LoadModule php4_module  modules/libphp4.so

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

DirectoryIndex  index.php (add)

test code

<?php
phpinfo();
?>