apache+tomcat整合的理解: 網站通常分爲前臺和後臺,前臺的頁面放到一個目錄裏好比:web。後臺的程序放到一個目錄裏:admin。 apache虛擬主機的文檔根目錄指向tomcat的項目目錄,這個目錄下有2個目錄:root,admin root下面存放這網站的全部前臺頁面,admin裏面存放這全部的後臺程序。 所須要的軟件: wget http://mirror.esocc.com/apache/tomcat/tomcat-7/v7.0.52/bin/apache-tomcat-7.0.52.tar.gz wget http://lnamp-web-server.googlecode.com/files/httpd-2.2.21.tar.gz wget http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.32-src.tar.gz wget http://oracleotn.rd.llnwd.net/otn-pub/java/jdk/6u26-b03/jdk-6u26-linux-i586-rpm.bin (1)配置DNS [root@nan87 /]# vim /etc/named.conf zone "." IN { type hint; file "named.ca"; }; zone "dog.com" IN { type master; file "named.dog.com"; }; [root@nan87 /]# vim /var/named/named.dog.com $TTL 600 @ IN SOA dog.com. root (2014030401 1H 15M 1W 1D); @ IN NS dog.com. dog.com. IN A 10.10.54.87 www.dog.com. IN A 10.10.54.87 bbs.dog.com. IN A 10.10.54.87 hr.dog.com. IN A 10.10.54.87 (2)安裝apache [root@nan87 softs]# tar xvf httpd-2.2.21.tar.gz [root@nan87 softs]# cd httpd-2.2.21 [root@nan87 httpd-2.2.21]# ./configure --prefix=/usr/local/apache --enable-modules=most --enable-mods-shared=all --enable-so --with-included-apr [root@nan87 httpd-2.2.21]# make [root@nan87 httpd-2.2.21]# make install //把apache的bin目錄加入到PATH變量中去,在文件加入一下面的行,這樣就能夠直接使用apachectl start/stop/restart [root@nan87 httpd-2.2.21]# vim /etc/profile export PATH=$PATH:/usr/local/apache/bin [root@nan87 httpd-2.2.21]# source /etc/profile //或者把/usr/local/apache/bin/apachectl啓動文件放到/etc/init.d下 [root@nan87 httpd-2.2.21]# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd [root@nan87 httpd-2.2.21]# vim /usr/local/apache/conf/httpd.conf ServerName www.dog.com:80 [root@nan87 httpd-2.2.21]# /etc/init.d/httpd restart (3)安裝JDK環境 JDK下載 x64表明64位 http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html tomcat運行環境下,JDK是必不可少的軟件,由於tomcat是一個Servlet/JSP容器,底層的操做都須要JDK來完成。 [root@nan87 softs]# rpm -ivh jdk-7u51-linux-x64.rpm //查看jdk的安裝路徑 [root@nan87 softs]# rpm -qa|grep jdk jdk-1.7.0_51-fcs.x86_64 [root@nan87 softs]# rpm -ql jdk-1.7.0_51-fcs.x86_64 安裝在/usr/java下 //查看版本 [root@nan87 softs]# java -version java version "1.7.0_51" Java(TM) SE Runtime Environment (build 1.7.0_51-b13) Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode) (4)安裝PHP 安裝libmcrypt,若是不安裝編譯時會出錯 [root@nan87 softs]# tar xvf libmcrypt-2.5.7.tar.gz [root@nan87 libmcrypt-2.5.7]# cd libmcrypt-2.5.7 [root@nan87 libmcrypt-2.5.7]# mkdir -p /usr/local/libmcrypt --libmcrypt的安裝目錄 [root@nan87 libmcrypt-2.5.7]# ./configure prefix=/usr/local/libmcrypt/ [root@nan87 libmcrypt-2.5.7]# make [root@nan87 libmcrypt-2.5.7]# make install //正式安裝PHP [root@nan87 softs]# tar xvf php-5.4.25.tar.gz [root@nan87 softs]# cd php-5.4.25 ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --with-freetype-dir --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --enable-session --with-gettext --with-mcrypt=/usr/local/libmcrypt 注意一下這些的地址: --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 出現錯誤及解決方法以下: configure: error: xml2-config not found. Please check your libxml2 installation. [root@nan87 php-5.4.25]# yum install libxml2-devel.x86_64 configure: error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/sss [root@nan87 php-5.4.25]# yum install libcurl-devel.x86_64 configure: error: jpeglib.h not found. [root@nan87 php-5.4.25]# yum install libjpeg-turbo-devel.x86_64 configure: error: png.h not found. [root@nan87 php-5.4.25]# yum install libpng-devel.x86_64 configure: error: freetype-config not found. [root@nan87 php-5.4.25]# yum install freetype-devel.x86_64 configure: error: Cannot find ldap.h [root@nan87 php-5.4.25]# yum install openldap-devel.x86_64 configure: error: Cannot find ldap libraries in /usr/lib. [root@nan87 php-5.4.25]# cp -frp /usr/lib64/libldap* /usr/lib/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 接着編譯 [root@nan87 php-5.4.25]# make ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 出現錯誤: 找不到libmysqlclient.so.18 softs/php-5.4.25/sapi/cli/php: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory make: *** [ext/phar/phar.php] Error 127 解決方法: --創建軟連接 [root@nan87 lib]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib [root@nan87 lib]# ldconfig ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [root@nan87 php-5.4.25]# make clean [root@nan87 php-5.4.25]# make [root@nan87 php-5.4.25]# make test [root@nan87 php-5.4.25]# make install ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 出現錯誤: --2014-03-09 21:24:55-- http://pear.php.net/install-pear-nozlib.phar Resolving pear.php.net... failed: Name or service not known. wget: unable to resolve host address 「pear.php.net」 make: *** [install-pear] Error 4 解決方法: [root@nan87 php-5.4.25]# cp /softs/go-pear.php /softs/php-5.4.25/pear/install-pear-nozlib.phar ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ make clean 再make install (5)修改apache配置文件,讓apache支持php [root@nan87 ~]# vim /usr/local/apache/conf/httpd.conf LoadModule php5_module modules/libphp5.so --看到上面一句代表apache如今已經集成了對php的支持,不過目前,apache還不「認識」.php擴展名的文件,若是經過瀏覽器請求.php擴展名的文件,那麼apache會返回該文件的源代碼。解決方法是在Load php Module這一行的下面 <IfModule !mod_php5.c> LoadModule php5_module lib/modules/libphp5.so </IfModule> <IfModule mod_php5.c> AddType application/x-httpd-php .php --注意若是你的文件的擴展名是.php必定要加這句 AddType application/x-httpd-php .php5 --同上,若是你的文件擴展名是.php5必定要加這句 AddType application/x-httpd-php-source .phps AddType application/x-httpd-php-source .php5s DirectoryIndex index.php DirectoryIndex index.php5 </IfModule> [root@nan87 ~]# cd /usr/local/apache/htdocs/ [root@nan87 htdocs]# vim index.php <?php phpinfo(); ?> [root@nan87 htdocs]# /etc/init.d/httpd restart (6)配置tomcat [root@nan87 softs]# tar xvf apache-tomcat-7.0.52.tar.gz [root@nan87 softs]# mv apache-tomcat-7.0.52 /usr/local/tomcat //給tomcat添加JAVA主目錄,在96行添加 [root@nan87 softs]# vim /usr/local/tomcat/bin/catalina.sh JAVA_HOME=/usr/java/jdk1.7.0_51 CATALINA_HOME=/usr/local/tomcat //作啓動腳本 [root@nan87 softs]# cd /usr/local/tomcat/bin [root@nan87 bin]# cp catalina.sh /etc/init.d/tomcat [root@nan87 bin]# vim /etc/init.d/tomcat #chkconfig: 2375 74 76 #description:tomcat start stop [root@nan87 bin]# chmod +x /etc/init.d/tomcat //配置用戶管理 [root@nan87 bin]# cd /usr/local/tomcat/conf/ [root@nan87 conf]# vim tomcat-users.xml --去掉註釋 <role rolename="manager-gui"/> <role rolename="admin-gui"/> <user username="tomcat" password="tomcat" roles="admin-gui,manager-gui"/> (7)重啓 [root@nan87 named]# /etc/init.d/httpd restart [root@nan87 named]# /etc/init.d/named restart (8)測試 在客戶端瀏覽器中輸入「http://www.dogs.com/」 點擊頁面任意內容,輸入用戶名和密碼,注意第7步 用戶名:tomcat 密碼:tomcat