详解在Linux上架设支持JSP+PHP的Web服务器

近年来Linux在Web服务器市场占有比例日渐攀升,除了缘于Linux的免费和安全性之外,还因为Linux上的应用服务日益丰富。大部分常见的服务都在Linux上有了较好的解决方案。而对于Intenet上应用最广泛的Web服务来说,Linux的表现就更为出色。谁也无法说清Internet上究竟有多少个网站,但在众多网站中,采用PHP和支持JSP的网站无疑占居了极大的市场份额。下面就介绍一下如何在Linux上架设支持JSP PHP MySQL的Web服务器。 

创新互联是一家专业的成都网站建设公司,我们专注网站制作、成都网站设计、网络营销、企业网站建设,买链接一元广告为企业客户提供一站式建站解决方案,能带给客户新的互联网理念。从网站结构的规划UI设计到用户体验提高,创新互联力求做到尽善尽美。

对于Web服务,Apache无疑是首选。数据库方面选用MySQL,这对于一般应用也够了,当然Linux下也可以安装oracle、DB2等大型数据库,可是它们费用昂贵。至于对于开发语言的支持,支持JSP和PHP无疑是当前最主流和应用最广泛的web开发语言了。所有这些软件我们可以从以下网站上找到: 

Resin:http://www.caucho.com/ 
JDK:http://java.sun.com/ 
Apache:http://www.apache.org 
MySQL:http://www.mysql.com 
PHP:http://www.php.net 
MM.MySQL:http://mmmysql.sourceforge.net/ 

从以上网站下载对应的软件,笔者下载的软件如下: 

mysql-4.0.15.tar.gz 
apache_1.3.28.tar.gz 
php-4.3.3.tar.gz 
resin-3.0.3.tar.gz 
mysql-connector-java-3.1.0-alpha.tar.gz 
j2sdk-1_4_2_01-linux-i586.bin 

一、安装MySQL 

MySQL的安装比较简单,但是编译过程可能有点长,具体步骤如下: 

  
 
 
 
  1. # tar -xzpvf mysql-4.0.15.tar.gz    
  2. # adduser -s /bin/false mysql    
  3. # ./configure --prefix=/usr/local/terry_yu/mysql --enable-assembler    
  4. --with-innodb --with-charset=gb2312    
  5. # make    
  6. # make install    
  7. # /usr/local/terry_yu/mysql/bin/mysql_install_db    
  8. # chown -R root /usr/local/terry_yu/mysql/    
  9. # chown -R mysql /usr/local/terry_yu/mysql/var    
  10. # chgrp -R mysql /usr/local/terry_yu/mysql/    
  11. # /usr/local/terry_yu/mysql/bin/mysql_install_db   

修改/etc/ld.so.conf,在最后加入以下一行: 

  
 
 
 
  1. /usr/local/terry_yu/mysql/lib/mysql/lib   

然后执行以下命令: 

  
 
 
 
  1. # ldconfig   

用以下命令启动MySQL 

  
 
 
 
  1. /usr/local/terry_yu/mysql/bin/mysqld_safe &   

用以下命令修改MySQL的root密码: 

/usr/local/terry_yu/mysql/bin/mysqladmin -uroot password abcdefg 

用以下命令可以进入MySQL的命令行方式: 

  
 
 
 
  1. [root@terry root]# /usr/local/terry_yu/mysql/bin/mysql -uroot -p    
  2. Enter password:    
  3. Welcome to the MySQL monitor. Commands end with ; or \g.    
  4. Your MySQL connection id is 1 to server version: 4.0.15 

Type 'help;' or '\h' for help. Type '\c' to clear the buffer. 

mysql> quit 
Bye 

出现以上信息表示MySQL已经成功运行了。 

二、安装JDK 

  
 
 
 
  1. # chmod 755 j2sdk-1_4_2_01-linux-i586.bin    
  2. # ./j2sdk-1_4_2_01-linux-i586.bin    
  3. # mv j2sdk1.4.2_01/ /usr/local/terry_yu/    
  4. # cd /usr/local/terry_yu/    
  5. # ln -s j2sdk1.4.2_01/ jdk    
  6. # ln -s jdk/jre/ jre    
  7.  
  8. # vi /etc/profile    
  9. JAVA_HOME=/usr/local/terry_yu/jdk    
  10. RESIN_HOME=/usr/local/terry_yu/resin    
  11. CLASSPATH=.:../$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$RESIN_HOME/lib:/usr/local/terry_yu/jdbc    
  12. PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin   

退出当前登录的环境,重新登录,这样刚刚设定的环境变量就会生效,然后用如下命令测试: 

  
 
 
 
  1. [root@terry root]# java -version    
  2. java version "1.4.2_01"    
  3. Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)    
  4. Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode) 

看到类似信息就表示JDK环境已经好了。其实在上面的/etc/profile中,我们不仅仅设置了JDK的环境变量,还一并设置了Resin和JDBC的环境变量,这些都是后面安装Resin所必需的设定。 

三、安装MySQL的JDBC 

MySQL的JDBC的相关环境变量已经在前面设置好了,所以余下的只是按以下命令安装: 

  
 
 
 
  1. # tar -xzpvf mysql-connector-java-3.1.0-alpha.tar.gz    
  2. # mv mysql-connector-java-3.1.0-alpha /usr/local/terry_yu/    
  3. # cd /usr/local/terry_yu/    
  4. # ln -s mysql-connector-java-3.1.0-alpha/ jdbc   

四、安装Apache 

http://apache.linuxforum.net/dist/httpd/apache_1.3.28.tar.gz 

需要注意的是,编译apache时候必须加入了DSO支持,如果没有,请加入 --enable-module=so 选项重新编译apache 

  
 
 
 
  1. # tar -xzpvf apache_1.3.28.tar.gz    
  2. # cd apache_1.3.28/    
  3. # ./configure --prefix=/usr/local/terry_yu/apache --enable-module=most    
  4. --enable-shared=max    
  5. # make    
  6. # make install   

察看编译进apache的模块: 

  
 
 
 
  1. #/usr/local/terry_yu/apache/bin/httpd -l    
  2. Compiled-in modules:    
  3. http_core.c    
  4. mod_so.c   

看到以上的信息表明apache支持DSO方式了。这样就可以用DSO的方式把php和resin的模块加进来。 

五、安装PHP 

安装PHP比较简单,我们先装PHP。 

  
 
 
 
  1. # tar -xzpvf php-4.3.3.tar.gz    
  2. # cd php-4.3.3/    
  3. # ./configure --with-mysql=/usr/local/terry_yu/mysql    
  4. --with-apxs=/usr/local/terry_yu/apache/bin/apxs    
  5. # make    
  6. # make install    
  7. # cp php.ini-dist /usr/local/lib/php.ini   

编辑PHP的配置文件是/usr/local/lib/php.ini,将其中的register_globals变量修改成On,默认是Off的。需要将它改成On。否则会出现php不能直接读不到post或get的数据的现象。 

编辑Apache的配置文件/usr/local/terry_yu/apache/conf/httpd.conf,在文件结尾加上以下一行: 

AddType application/x-httpd-php .php .php3 

启动apache:  

# /usr/local/terry_yu/apache/bin/apachectl start 

然后可以用一个简单的php文件来测试PHP的安装,这个简单的PHP文件包含下列一行: 

  
 
 
 
  1.  phpinfo();?>   

将其保存为/usr/local/terry_yu/apache/htdocs/info.php,然后在浏览器中浏览,如果观看到以显示有“PHP Version4.3.3”标题的页面就表示整合PHP与Apache成功了。而且在这个页面中可以看到与PHP相关的选项,其中应该有关于MySQL的子项,这表明PHP已经内置了对MySQL的支持了。这样就表示PHP MySQL Apache的环境已经成功了,接下来是安装Resin来支持JSP环境。 

六.安装Resin 

http://www.caucho.com/download/resin-3.0.3.tar.gz 

(7296篇文章)FTP服务器  
(8638篇文章)双核服务器技术  
(10077篇文章)网站服务器的选型  
(7743篇文章)网吧流媒体服务器  
(6817篇文章)刀片服务器专题  

下载的resin的安装包解开后应该可以直接单独运行的。笔者将其解开后放到/usr/local/terry_yu目录下

   
  
  
  
  1. # tar -xzpvf resin-3.0.3.tar.gz  
  2. # mv resin-3.0.3 /usr/local/terry_yu/  
  3. # cd /usr/local/terry_yu/  
  4. # ln -s resin-3.0.3/ resin 

启动resin

# /usr/local/terry_yu/resin/bin/httpd.sh start

如果之前安装JDK时设置好了相关的环境变量,就能够从http://localhost:8080/上能看到resin的页面,这也就表示单独的resin运行成功了。然后,为了整合resin和apache,我们需要重新编译一下,以生成mod_caucho给Apache调用。

  
 
 
 
  1. # cd /usr/local/terry_yu/resin  
  2. # ./configure --with-apache=/usr/local/terry_yu/apache   
  3. # make  
  4. # make install 

修改/usr/local/terry_yu/resin/conf/resin.conf,大约在第159行(安装的resin版本不同, 配置文件的内容可能有所不同),将 修改成自己的apache的DocumentRoot的值。

  
 
 
 
  1.  xmlns=http://caucho.com/ns/resin> 
  2.   
  3.  id=""> 
  4.  
  5. /usr/local/terry_yu/apache/htdocs document-directory> ##这里修改成/usr/local/terry_yu/apache/htdocs  
  6.  
  7.  ...  
  8. host> 
  9.   server> 
  10. resin> 

修改/usr/local/terry_yu/apache/conf/httpd.conf,在编译resin时,安装程序已经修改过httpd.conf,不过还不完全正确,应该改成类似以下的配置,如果你完全按本文进行的安装可以直接复制这些内容:

  
 
 
 
  1. LoadModule caucho_module libexec/mod_caucho.so  
  2. AddModule mod_caucho.c  
  3.  
  4.  mod_caucho.c> 
  5.  ResinConfigServer localhost 6802  
  6.  /caucho-status> 
  7.  SetHandler caucho-status  
  8. Location> 
  9.   IfModule> 

修改完后,重新启动resin后生效:

  
 
 
 
  1. /usr/local/terry_yu/resin/bin/httpd.sh restart  
  2. /usr/local/terry_yu/apache/bin/apachectl restart 

通过浏览器去访问http://localhost/caucho-status/,如果出现以下页面刚表示resin和apache已经成功整合了。

然后再测试一下JSP对数据库的访问,在/usr/local/apache/htdocs/下面用jsp写一个简单的jsp文件来连接本机的MySQL数据库:

vi /usr/local/terry_yu/apache/htdocs/testdb.jsp

输入以下内容,可以直接粘贴:

  
 
 
 
  1.  
  2.  
  3. </font></strong>Test JDBC For MySQL<strong><font> title></font></strong> </li> <li><strong><font> head></font></strong> </li> <li><strong><font><body></font></strong> </li> <li><strong><font><</font></strong>%@ page <font>contentType</font>=<font>"text/html;charset=gb2312"</font> %<strong><font>></font></strong> </li> <li><strong><font><</font></strong>%  </li> <li>Class.forName("com.mysql.jdbc.Driver").newInstance();  </li> <li>java.sql.Connection conn;  </li> <li><font>conn</font> =  </li> <li><font>java</font>.sql.DriverManager.getConnection("jdbc:mysql://localhost/mysql?<font>user</font>=<font>root</font>&<font>password</font>=<font>abcdefg</font>");  </li> <li>%<strong><font>></font></strong> </li> <li><strong><font> body></font></strong> </li> <li><strong><font> html></font></strong> </li> </ol></pre><p>通过浏览器去访问http://localhost/testdb,如果看到了一个没有任何错误信息的空白页面,就表示jsp连接本机的MySQL数据库成功了,至此我们就完成了一个支持JSP PHP MySQL的Web服务器。</p><p>注:以上所有安装都是在Red Hat Linux9.0上完成的,所使用软件也均为目前(2003年9月)最新的版本。</p><p>本文介绍了如何在Linux上架设同时支持JSP和PHP的Web Server,演示了MySQL、JDK、JDBC、Apache、PHP、Resin的安装和简单测试过程。</p> <p> 网站题目:<a href="http://www.shufengxianlan.com/qtweb/news47/202997.html">详解在Linux上架设支持JSP+PHP的Web服务器</a> <br> 当前地址:<a href="http://www.shufengxianlan.com/qtweb/news47/202997.html">http://www.shufengxianlan.com/qtweb/news47/202997.html</a> </p> <p> 网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等 </p> <p class="adpic"> <a href="https://www.cdcxhl.com/service/ad.html" target="_blank" class="ad">广告</a> <a href="" target="_blank" class="adimg"><img src=""></a> </p> <p class="copy"> 声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: <a href="https://www.cdcxhl.com/" target="_blank">创新互联</a> </p> </div> <div class="newsmorelb"> <p>猜你还喜欢下面的内容</p> <ul> <li> <a href="/qtweb/news46/202996.html">教育网网站挂马监测分析</a> </li><li> <a href="/qtweb/news45/202995.html">异地备案记录怎么查询?(麻烦帮忙核查域名是否备案成功)</a> </li><li> <a href="/qtweb/news44/202994.html">手机安装包格式?windowsphone支持视频格式</a> </li><li> <a href="/qtweb/news43/202993.html">Redis集群搭建轻松实现高可用性(redis组建集群)</a> </li><li> <a href="/qtweb/news42/202992.html">Docker容器中怎么访问数据库?</a> </li><li> <a href="/qtweb/news41/202991.html">sqlserver如何往表里插数据</a> </li><li> <a href="/qtweb/news40/202990.html">使用Linux中的文件大小判断函数进行精准操作 (linux判断文件大小函数)</a> </li><li> <a href="/qtweb/news39/202989.html">PDF怎么看文件大小?(pdf怎么看)</a> </li><li> <a href="/qtweb/news38/202988.html">word文档中如何给文字加粗一点</a> </li> </ul> </div> </div> <div class="col-lg-3 noneb"> <div class="bkright" style="margin-top: 0"> <p><a href="https://www.cdcxhl.com/news/ued/">用户体验知识</a></p> <ul> <li> <a class="text_overflow" href="/qtweb/news5/359355.html">MySQL数据处理将数组转化为列</a> </li><li> <a class="text_overflow" href="/qtweb/news41/453941.html">如何解决Redis的并发问题(处理redis并发问题)</a> </li><li> <a class="text_overflow" href="/qtweb/news21/198121.html">创新互联Python教程:python配置文件报错怎么解决</a> </li><li> <a class="text_overflow" href="/qtweb/news33/283833.html">如何将word文档转html格式</a> </li><li> <a class="text_overflow" href="/qtweb/news31/372431.html">服务器续费成本是什么?(服务器续费成本是什么意思)</a> </li><li> <a class="text_overflow" href="/qtweb/news36/503336.html">浅读种种Python性能使用问题</a> </li><li> <a class="text_overflow" href="/qtweb/news28/272328.html">linux部署docker环境怎么操作</a> </li><li> <a class="text_overflow" href="/qtweb/news2/158402.html">windowsserver2022优缺点?(国外服务器测评,美国服务器评测2022年更新(国外服务器测评,美国服务器评测2022年更新))</a> </li><li> <a class="text_overflow" href="/qtweb/news37/405687.html">android开发怎么学</a> </li><li> <a class="text_overflow" href="/qtweb/news4/58404.html">怎样把表格放大或缩小</a> </li><li> <a class="text_overflow" href="/qtweb/news27/409877.html">损坏的映像该怎么解决?windows8损坏的映像</a> </li><li> <a class="text_overflow" href="/qtweb/news24/43774.html">使用海外服务器如何避免被墙?</a> </li><li> <a class="text_overflow" href="/qtweb/news38/494438.html">本马哥Linux:掌握笔记本的强大力量(马哥linux笔记)</a> </li><li> <a class="text_overflow" href="/qtweb/news49/462199.html">服务器显示服务器繁忙:了解服务器负载和性能</a> </li><li> <a class="text_overflow" href="/qtweb/news25/118725.html">云服务器大概多少钱一台(云服务器大概多少钱一台啊)</a> </li> </ul> </div> <div class="bkright tag"> <p><a href="https://www.cdcxhl.com/hangye/link.html" target="_blank">各行业网站</a></p> <ul> <li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/bdfhw/" target="_blank">被动防护网</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/zkj/" target="_blank">公路钻孔机</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/fadianji/" target="_blank">柴油发电机</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/jianzhudonghua/" target="_blank">建筑动画</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/chalousj/" target="_blank">茶楼设计</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/pvc/" target="_blank">PVC花箱</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/zdfhw/" target="_blank">主动防护网</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/muwu/" target="_blank">木屋</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/huisuosj/" target="_blank">会所设计</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/jiudiansj/" target="_blank">酒店设计</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/mutuopan/" target="_blank">木托盘</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/fwqzy/" target="_blank">服务器租用</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/gsdb/" target="_blank">工商代办</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/ggtg/" target="_blank">广告推广</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/shidiao/" target="_blank">石雕</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/wsjgd/" target="_blank">卫生间隔断</a> </li> </ul> </div> </div> </div> <div class="carousel-inner linkbg" style="background: #fff"> <div class="container"> <a href="https://www.cdxwcx.com/jifang/yaan.html" target="_blank">雅安电信机房</a>    <a href="http://chengdu.cdcxhl.com/" target="_blank">成都网站设计</a>    <a href="https://www.cdxwcx.com/wangzhan/applet.html" target="_blank">成都小程序开发</a>    <a href="https://www.cdcxhl.com/shop.html" target="_blank">成都做商城网站</a>    <a href="https://www.cdxwcx.com/city/wenjiang/" target="_blank">温江做网站</a>    <a href="http://www.4006tel.net/vision/" target="_blank">UI设计</a>    <a href="https://www.cdcxhl.com/weihu/safeguard/" target="_blank">网站维护报价</a>    <a href="https://www.cdcxhl.cn/ " target="_blank">云主机</a>    <a href="http://chengdu.cdcxhl.cn/shop/ " target="_blank">成都商城开发</a>    <a href="https://www.cdxwcx.com/" target="_blank">成都网站建设</a>    <a href="https://www.scvps.cn/" target="_blank">网站空间</a>    <a href="https://www.cdxwcx.com/tuiguang/ruanwen.html" target="_blank">软文推广</a>    <a href="https://www.xwcx.net/" target="_blank">托管服务器</a>    <a href="https://www.cdcxhl.cn/ " target="_blank">香港虚拟主机</a>    <a href="http://www.bzwzjz.com/serve/" target="_blank">高端网站设计</a>    <a href="http://www.njjbc.cn/" target="_blank">南京护栏钻孔机</a>    <a href="https://www.cdxwcx.com/city/shuangliu/" target="_blank">双流网站建设</a>    <a href="http://www.msbanjia.cn/" target="_blank">美美搬家</a>    <a href="http://www.zjjierui.cn/" target="_blank">广元双南建站</a>    <a href="http://www.cdfuwuqi.com/host/mianbeian/" target="_blank">免备案虚拟主机</a>     </div> </div> <footer> <div class="carousel-inner footjz"> <div class="container"> <i class="icon iconfont zbw"></i> 高品质定制 <i class="icon iconfont"></i> 跨终端自动兼容 <i class="icon iconfont"></i> 节约开发成本 <i class="icon iconfont"></i> 开发周期短 <i class="icon iconfont"></i> 一体化服务 <button type="button" class="btn btn-default btn-lg" onClick="window.location.href='tencent://message/?uin=631063699&Site=&Menu=yes'"> 立即开始2800定制网站建设</button> <button type="button" class="btn btn-default btn-xs" onClick="window.location.href='tencent://message/?uin=631063699&Site=&Menu=yes'"> 2800定制网站建设</button> </div> </div> <div class="carousel-inner bqsy"> <div class="container"> <div class="lxfs"> <h4 class="yutelnone">028-86922220 13518219792</h4> <h4 class="yutelblock"><a href="tel:02886922220">028-86922220</a> <a href="tel:13518219792">13518219792</a></h4> <a class="btn btn-default" href="tencent://message/?uin=532337155&Site=&Menu=yes" role="button">网站建设<span>QQ</span>:532337155</a> <a class="btn btn-default" href="tencent://message/?uin=631063699&Site=&Menu=yes" role="button">营销推广<span>QQ</span>:631063699</a> <a class="btn btn1 btn-default" href="mqqwpa://im/chat?chat_type=wpa&uin=532337155&version=1&src_type=web&web_src=oicqzone.com" role="button">网站制作<span>QQ</span>:532337155</a> <a class="btn btn1 btn-default" href="mqqwpa://im/chat?chat_type=wpa&uin=631063699&version=1&src_type=web&web_src=oicqzone.com" role="button">营销推广<span>QQ</span>:631063699</a> <a class="btn btn-default nonea" href="tencent://message/?uin=1683211881&Site=&Menu=yes" role="button">售后QQ:1683211881</a> <div class="dz">创新互联建站专注: <a href="https://www.cdcxhl.com/" target="_blank">网站设计</a> <a href="https://www.cdcxhl.com/" target="_blank">网站制作</a> <a href="https://www.cdcxhl.com/" target="_blank">网站建设</a> <address>地址:成都太升南路288号锦天国际A幢10楼</address> </div> </div> <div class="bzdh dz"><img src="https://www.cdcxhl.com/imges/bottom_logo.png" alt="创新互联"> <p><a href="https://www.cdcxhl.com/menu.html" target="_blank">成都创新互联科技有限公司</a><br> Tel:400-028-6601(7x24h)</p></div> </div> </div> </footer> </body> </html> <script> $.getJSON ("../../qtwebpic.txt", function (data) { var jsonContent = { "featured":data } var random = jsonContent.featured[Math.floor(Math.random() * jsonContent.featured.length)]; $(".adpic .adimg").attr("href",random.link) $(".adpic img").attr("src",random.pic); }) </script>