详解在Linux上架设支持JSP+PHP的Web服务器-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

详解在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> <br> 标题名称:详解在Linux上架设支持JSP+PHP的Web服务器 <br> 本文网址:<a href="http://kswsj.cn/article/cdgdcio.html">http://kswsj.cn/article/cdgdcio.html</a> </div> </div> <div class="other"> <h3>其他资讯</h3> <ul> <li> <a href="/article/djhijig.html">SQLServer中通过设置SETNOCOUNT来优化存储过程</a> </li><li> <a href="/article/djhigch.html">快速高效的织梦数据库替换方法(织梦数据库替换)</a> </li><li> <a href="/article/djhijgd.html">文件夹无法删除怎么办?windows不能删除文件夹</a> </li><li> <a href="/article/djhijcj.html">我们为什么会删除不了集群的Namespace?</a> </li><li> <a href="/article/djhijgo.html">主机购买需要注意哪些问题,如何选择适合自己的主机</a> </li> </ul> </div> </div> <div class="line"></div> <!--底部--> <footer id="5"> <div class="foot1 container"> <div class="list"> <div class="item"> <a href="javascript:;"> <span class="ico1"><i class="iconfont"></i><img src="/Public/Home/img/ewm.png" alt=""></span> <strong>关注我们</strong> </a> </div> <div class="item"> <a href="" target="_blank"> <span><i class="iconfont"></i></span> <strong>索要报价</strong> </a> </div> <div class="item"> <a href="" target="_blank"> <span><i class="iconfont"></i></span> <strong>我要咨询</strong> </a> </div> <div class="item"> <a href="" target="_blank"> <span><i class="iconfont"></i></span> <strong>找到我们</strong> </a> </div> <div class="item"> <a href="" target="_blank"> <span><i class="iconfont"></i></span> <strong>投诉建议</strong> </a> </div> </div> <div class="tel"> <dl> <tel><a href="tel:400-028-6601" target="_blank">400-028-6601</a></tel><br> <span>也许您需要专业的服务,欢迎来电咨询</span> </dl> <dl> <tel><a href="tel:18980820575" target="_blank">18980820575</a></tel><br> <span>您的需求,是我们前进的动力</span> </dl> </div> </div> <div class="friend"> <div class="container"> <span class="tit">友情链接:</span> <div class="inner"> <a href="https://www.cdcxhl.com/shoulu/" target="_blank">网站快速收录</a><a href="https://www.cdcxhl.com/google.html" target="_blank">Google优化</a><a href="https://www.cdxwcx.com/jifang/xiyun.html" target="_blank">西云移动机房</a><a href="https://www.cdcxhl.com/yingxiao.html" target="_blank">成都营销网站建设公司</a><a href="https://www.cdcxhl.com/xiangyingshi.html" target="_blank">响应式网站设计公司</a><a href="https://www.cdcxhl.com/gaofang/" target="_blank">高防主机租用</a><a href="https://www.cdcxhl.com/link/" target="_blank">友情链接</a><a href="https://www.cdcxhl.com/jigui/" target="_blank">机柜租用</a><a href="https://www.cdcxhl.com/shoulu/" target="_blank">分类目录网站</a><a href="https://www.cdcxhl.com/weihu/" target="_blank">网站维护</a><a href="https://www.cdcxhl.com/link/" target="_blank">买卖链接</a><a href="https://www.cdcxhl.com/ruanwen/" target="_blank">发布软文</a><a href="https://www.cdcxhl.com/google.html" target="_blank">成都谷歌推广公司</a><a href="https://www.cdcxhl.com/jigui/" target="_blank">服务器机柜租赁</a><a href="https://www.cdcxhl.com/yingxiao.html" target="_blank">营销型网站建设</a><a href="https://www.cdcxhl.com/app.html" target="_blank">成都app软件开发公司</a><a href="https://www.cdcxhl.com/yunying.html" target="_blank">网站运营</a><a href="https://www.cdcxhl.com/" target="_blank">成都建站公司</a> </div> </div> </div> <div class="foot"> <div class="container"> <div class="footNav"> <h3>网站建设</h3> <a href="https://www.cdxwcx.com/wangzhan/pinpai.html" target="_blank">品牌网站建设</a><a href="http://www.cdkjz.cn/wangzhan/waimao/" target="_blank">成都外贸网站建设</a><a href="http://www.myzwz.com/" target="_blank">绵阳网站建设</a> </div> <div class="footNav"> <h3>服务器托管</h3> <a href="https://www.cdcxhl.com/idc/cqstsx.html" target="_blank">重庆水土双线托管</a><a href="https://www.xwcx.net/" target="_blank">成都机柜租用</a><a href="https://www.cdcxhl.com/idc/meishan.html" target="_blank">眉山服务器托管</a> </div> <div class="footNav"> <h3>网站制作</h3> <a href="http://m.cdcxhl.com/" target="_blank">成都网站制作</a><a href="https://www.cdxwcx.com/" target="_blank">网站制作</a><a href="http://chengdu.cdcxhl.com/" target="_blank">成都营销网站制作</a> </div> <div class="footNav"> <h3>企业服务</h3> <a href="https://www.cdcxhl.com/service/ssl.html" target="_blank">ssl证书</a><a href="https://www.cdcxhl.com/ruanwen/yingxiao/" target="_blank">软文平台</a><a href="https://www.cdcxhl.com/service/zzgj.html" target="_blank">备案资质管家服务</a> </div> <div class="fr ecode"> <div class="fl"> <img src="/Public/Home/img/ewm.jpg"> <p>关注企业微信</p> </div> <div class="fr slogan"> <p class="icon"> <a class="ph" href=""><i class="iconfont"></i></a> <a class="qq" href="tencent://message/?uin=1683211881&Site=&Menu=yes"><i class="iconfont"></i></a> </p> <p> <i>想要找 </i> <a href="">小程序开发</a>、<a href="">APP开发</a>、 <a href="">营销型网站建设</a>、<a href="">网站建设</a>、 <i><a href="">网站定制开发</a></i> ,就选<a href="">创新互联</a> </p> </div> </div> </div> <div class="bottom container"> <p class="fl"> 版权所有:成都创新互联科技有限公司 备案号:<a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow">蜀ICP备19037934号</a> 服务热线:028-86922220 </p> <p class="fr"> <a href="https://www.cdxwcx.com/" target="_blank">成都网站建设</a>: <a href="https://www.cdcxhl.com/" target="_blank">创新互联</a> </p> </div> </div> </footer> <!--在线咨询--> <div class="fot"> <ul> <li> <a href="https://p.qiao.baidu.com/cps/mobileChat?siteId=11284691&userId=6256368&type=1&reqParam=%20{%22from%22:0,%22sessionid%22:%22%22,%22siteId%22:%2211284691%22,%22tid%22:%22-1%22,%22userId%22:%226256368%22,%22ttype%22:1,%22siteConfig%22:%20{%22eid%22:%226256368%22,%22queuing%22:%22%22,%22siteToken%22:%226ce441ff9e2d6bedbdfc2a4138de449e%22,%22userId%22:%226256368%22,%22isGray%22:%22false%22,%22wsUrl%22:%22wss://p.qiao.baidu.com/cps3/websocket%22,%22likeVersion%22:%22generic%22,%22siteId%22:%2211284691%22,%22online%22:%22true%22,%22webRoot%22:%22//p.qiao.baidu.com/cps3/%22,%22bid%22:%22160142915792139572%22,%22isSmallFlow%22:0,%22isPreonline%22:0,%22invited%22:0%20},%22config%22:%20{%22themeColor%22:%224d74fa%22%20}%20}&appId=&referer=&iswechat=0&expectWaiter=-1&openid=null&otherParam=null&telephone=null&speedLogId=null&eid=null&siteToken=6ce441ff9e2d6bedbdfc2a4138de449e" target="_blank"> <img src="/Public/Home/img/fot1.png" alt=""> <p>在线咨询</p> </a> </li> <li> <a href="tel:18980820575" target="_blank"> <img src="/Public/Home/img/fot2.png" alt=""> <p>拨打电话</p> </a> </li> </ul> </div> </body> </html> <script> $(".con img").each(function(){ var src = $(this).attr("src"); //获取图片地址 var str=new RegExp("http"); var result=str.test(src); if(result==false){ var url = "https://www.cdcxhl.com"+src; //绝对路径 $(this).attr("src",url); } }); window.onload=function(){ document.oncontextmenu=function(){ return false; } } </script>