在CentOS下安裝apche+tomcat+mysql+php

科技小能手發表於2017-11-12

 

在CentOS下安裝apche+tomcat+mysql+php
 
本例中所用到的軟體
Apache 2.2
Sun的JDK-1_5_0_12-linux-i586
MySQL: mysql-5.0.41-linux-i686
PHP 5.2.3
Tomcat 5.028

 

tomcat-connectors-1.2.23

 

本例中將所有軟體裝入/home/www資料夾中

 

 

 

安裝apache

 

進入原始碼包所在的資料夾(本例中為/home/install)

 

#cd /home/install

 

#tar zxvf httpd-2.2.4.tar.gz

 

#cd httpd-2.2.4

 

#./configure --prefix=/home/www/apache --enable-module=most --enable-shared=max --enable-so

 

#make && make install
建立一個啟動指令碼:

 

#vi /etc/rc.d/init.d/httpd

# 獲取網路配置
#!/bin/bash
# Startup script for the Apache Web Server
# 包含函式庫
. /etc/rc.d/init.d/functions
# 獲取網路配置
. /etc/sysconfig/network
# 檢測 NETWORKING 是否為 "yes"
[ "${NETWORKING}" = "no" ] && exit 0
# apache安裝目錄
APACHE=/home/www/apache
# 啟動服務函式
start() {
echo $"Starting httpd service: "
$APACHE/bin/apachectl start
RETVAL=$?
echo
}
# 關閉服務函式
stop() {
echo $"Stopping httpd service: "
$APACHE/bin/apachectl stop
RETVAL=$?
echo
}
# 根據引數選擇呼叫
case "$1" in
 start)
start
;
 stop)
stop
;;
 restart)
stop
start
;;
 *)
echo $"Usage: $0 start|stop|restart"
exit 1
esac
exit 0
#chkconfig: 2345 10 90
# description: Activates/Deactivates Apache Web Server
 

 

 

#chmod 755 httpd
將其新增為系統服務。

 

#chkconfig –level 345 httpd on
重啟apache服務.

 

#service httpd restart

 

 
安裝Mysql.
解壓、進入原始碼目錄

 

#groupadd mysql

 

#useradd –g mysql mysql
移動目錄至/home/www下

 

#cd /home/www/mysql

 

#scripts/mysql_install_db –user=mysql

 

#chown –R root .

 

#chown –R myssql data

 

#chgrp –R mysql .

 

#bin/mysqld_safe –user=mysql &
這樣Mysql 就已經成功啟動,下面為root使用者設定密碼

 

#./bin/mysqladmin –u root password
新增mysql為系統服務.

 

#cp support-files/mysql.server /etc/init.d/mysql

 

#vi /etc/init.d/mysql
修改其內容

basedir=/home/www/mysql

datadir=/home/www/mysql/data

 

 

#chkconfig –level 345 mysql on
#service mysql restart
 
安裝php
解壓、進入php原始碼目錄
#cd php 5.2.3
#./configure–prefix=/home/www/php –with-mysql=/home/www/mysql –with-apxs2=/home/www/apache/bin/apxs
#make && make install
#cp php.ini-dist /usr/local/lib/php.ini
#vi /home/www/apache/conf/httpd.conf
新增

AddType application/x-httpd-php .php 

AddType application/x-httpd-php .php3

 
重啟apache.寫入一test.php

<?
Phpinfo()
?>

 
測試php模組是否正常
 
安裝JDK
進入下載目錄
#chmod +x jdk-1_5_0_12-linux-i586-rpm.bin
#./jdk-1_5_0_12-linux-i586-rpm.bin
按空格鍵,閱讀使用許可,然後輸入yes
安裝完成後,J2DK的預設安裝目錄是/usr/java/jdk-1_5_0_12,為了方便操作,建立一個符號連結。
#ln –s /usr/java/jdk-1_5_0_12 /usr/jdk
安裝tomcat
解壓tomcat
# tar jakarta-tomcat-5.0.28.tar.gz –C /home/www
#cd /home/www
#mv jakarta-tomcat-5.0.28 tomcat
#cd tomcat
#chmod +x bin/*.sh
修改bin目錄下的startup.sh和shutdown.sh。新增以下內容
 

export JAVA_HOME=/usr/jdk
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=$JAVA_HOME/lib

 
新增以下內容至/etc/rc.d/rc.local
#vi /etc/rc.d/rc.local

/home/www/tomcat/bin/startup.sh

 
整合apache和tomcat
#cp mod_jk-1.2.21-apache-2.2.x-linux-i686.so /home/www/apache/modules/mod_jk.so
解壓tomcat-connectors-1.2.23-src.tar.gz
#tar zxvf tomcat-connectors-1.2.23-src.tar.gz
#cd tomcat-connectors-1.2.23/native
# ./configure –with-apxs=/home/www/apache/bin/apxs
#make && make install
完成後,在httpd.conf下新增如下內容

#add mod_jk module

LoadModule jk_module modules/mod_jk.so

# Update this path to match your modules location

# Where to find workers.properties

# Update this path to match your conf directory location (put workers.properties next to #httpd.conf)

  JkWorkersFile /home/www/apache/conf/workers.properties

# Where to put jk logs

# Update this path to match your logs directory location (put mod_jk.log next to access_log)

  JkLogFile     /home/www/apache/logs/mod_jk.log

# Set the jk log level [debug/error/info]

  JkLogLevel    info

# Select the log format

  JkLogStampFormat “[%a %b %d %H:%M:%S %Y] “

# JkOptions indicate to send SSL KEY SIZE,

  JkOptions     +ForwardKeySize +ForwardURICompat -ForwardDirectories

# JkRequestLogFormat set the request format

  JkRequestLogFormat     “%w %V %T”

# Send everything for context /examples to worker named worker1 (ajp13)

  JkMount  /*.jsp worker1

 
在到conf目錄下新建一個workers.properties檔案。內容如下:

# Define 1 real worker using ajp13

  worker.list=worker1

# Set properties for worker1 (ajp13)

  worker.worker1.type=ajp13

  worker.worker1.host=localhost

  worker.worker1.port=8009

  worker.worker1.lbfactor=50

  worker.worker1.cachesize=10

  worker.worker1.cache_timeout=600

  worker.worker1.socket_keepalive=1

  worker.worker1.reclycle_timeout=300
 

 
修改tomcat的配置檔案server.xml與apache的路徑整合
在  <Host name=”localhost” appBase=”webapps”

       unpackWARs=”true” autoDeploy=”true”

       xmlValidation=”false” xmlNamespaceAware=”false”>
這樣的語句下新增:
        <Context path=”” docBase=”/home/www/apache/htdocs” debug=”0″/>
這樣就完成了所有的安裝
本文轉自holy2009 51CTO部落格,原文連結:http://blog.51cto.com/holy2010/386069


相關文章