FreeBSD平台安装配置web服务器


注意:在进行这步操作前建议把squid关掉,因为在进行主页更新测试时squid的cache会使更新后的主页不能及时反映出来

  为了不使用squid,除了关掉squid外,还要删除ipfw的透明代理端口转发语句:

  # cd /usr/local/etc/rc.d

  # ./squid.sh stop

  # mv squid.sh squid.sh.bak

  # ipfw del 500 fwd 127.0.0.1,3128 tcp from 192.168.0.0/24 to any 80

  本web服务器的其本组成为:

  Apache 1.3.27

  modssl

  mod_php4

  mod_gzip

  mod_fastcgi

  mod_perl

  mysql3.23

  为了简化安装过程并发挥FreeBSD安装软件的优势,本文后续部分将采用ports安装。Ports 使在FreeBSD下安装各种软件变得很轻松。

  首先安装ports:(如果已经有/usr/ports目录则证明已经安装过了)

  # /stand/sysinstall

  选Configure—Distributions—ports,ports将被安装在/usr/ports目录中。

  下面安装apache1.3.27 + modssl :

  # cd /usr/ports/www/apache13-modssl

  # make install

  系统会自动下载安装包并安装完毕。

  安装后系统会自动产生启动脚本apache.sh,在/usr/local/etc/rc.d目录中。可以通过运行

  apache.sh start|stop来启动或停止apache。

  安装mysql3.23:

  # cd /usr/ports/databases/mysql323-server

  # make install

  安装后产生启动脚本/usr/local/etc/rc.d/mysql-server.sh

  安装apache模块mod_php4:

  # cd /usr/ports/www/mod_php4

  首先编辑scripts目录下的configure.php文件,加入对OpenSSL的支持

  # vi scripts/configure.php

  找到下面一句

OpenSSL "OpenSSL support" ON

  改成

  OpenSSL "OpenSSL support" YES

  # make install

  出现对话框时直接选ok继续

  安装完成后编辑apache的配制文件/usr/local/etc/apache/httpd.conf ,添加如下内容:

  # 设置默认可以使用的主页名称,这句系统一般已经有了,不用添加了

  DirectoryIndex index.php index.html

  # 这2句需要手工添加

  AddType application/x-httpd-php .php

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

  安装其他Apache常用模块 mod_gzip + mod_fastcgi + mod_perl:

  # cd /usr/ports/www/mod_gzip

  # make install

  # cd /usr/ports/www/mod_fastcgi

  # make install

  编辑/usr/local/etc/apache/httpd.conf文件

  添加下面一句

  AddHandler fastcgi-script fcgi fcgi fpl

  # cd /usr/ports/www/mod_perl

  # make install

  重新启动让所有软件自动运行。

  测试:

  首先以root身份执行线程察看命令top,列表中应该有下面几个线程正在运行:

  PID USERNAME PRI NICE SIZE RES STATE COMMAND

  69 root 2 0 440K 296K select natd     # 网络地址转换进程

  132 root 2 0 3692K 3052K select httpd   # apache进程

  166 mysql 2 0 27480K 4824K poll mysqld  # mysql进程

  在浏览器地址栏输入http://192.168.0.1 ,如果显示apache的欢迎页面,证明web服务器安装成功!web页面文件存放在/usr/local/www/data目录中,你可以把自己的网页拷贝到这个目录,就可以访问自己的主页了!

  键入命令:

  # mysql

 出现下面显示证明mysql安装成功!

  Welcome to the MySQL monitor. Commands end with ; or g.

  Your MySQL connection id is 2 to server version: 3.23.52

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

  mysql>

  键入exit退出mysql。

  为mysql的root用户设置一个口令123456

  # mysqladmin -u root password '123456'

  现在我们来安装一个支持php+mysql的论坛。到 http://www.faeryboard.com/showthread.php?s=&threadid=2429 去下载完美版的仙境论坛程序。将下载的rar压缩包解开,然后使用ftp上传到/home/ylf/app目录。

  事先备份web服务器演示页面

  # cd /usr/local/www/data

  # mkdir backup

  # mv * backup

  将论坛程序拷贝到/usr/local/www/data目录

  # cd /home/ylf/app/vbb2.3.0final

  # cp –r * /usr/local/www/data

  编辑论坛配置文件:

  # vi /usr/local/www/data/admin/config.php

  内容如下:

  ^M

  /////////////////////////////////////////////////////////////^M

  // Please note that if you get any errors when connecting, //^M

  // that you will need to email your host as we cannot tell //^M

  // you what your specific values are supposed to be     //^M

  /////////////////////////////////////////////////////////////^M

  ^M

  // type of database running^M

  // (only mysql is supported at the moment)^M

  $dbservertype='mysql';^M               
 ^M

  // hostname or ip of server^M

  $servername='localhost';^M              #主机名

  ^M

  // username and password to log onto db server^M

  $dbusername='root';^M                #登录数据库用户

  $dbpassword='123456';^M               #密码

  ^M

  // name of database^M

  $dbname='fin230';^M                 #论坛所使用的数据库名称

  ^M

  // technical email address - any error messages will be emailed here^M

  $technicalemail='webmaster@yoursite.com';^M    #管理信息

  ^M

  // use persistant connections to the database^M

  // 0 = don't use^M

  // 1 = use^M

  $usepconnect=1;^M

  ^M

  ?>

  除了root用户的密码需要添入外,其他部分可以不改。

  保存后,在浏览器地址栏输入http://192.168.0.1/admin/install.php ,根据提示一步步安装即可。

  安装成功后,在在浏览器地址栏输入http://192.168.0.1 ,就可以看到论坛了!怎么样,挺漂亮吧!关于论坛的其他问题,请仔细看论坛安装包里面的说明文档,或者到仙境论坛的主页,那里有仙境论坛的一切!

  下一节,我们要讨论关于虚拟主机的问题。

  配制虚拟主机:

  Apache的虚拟主机支持有两种方式,一是基于用户访问Apache主机时所使用的域名,另一种是通过指定IP地址来提供。这里我们只介绍如何通过不同的域名来实现虚拟主机的支持。

  要实现基于域名的虚拟主机的前提条件是必须有两个域名同时指向Apache主机的IP地址,这里我们假设这两个域名分别是www01.3322.org 和www02.3322.org ,这两个域名的文档都分别放置于 /home/www01 和 /home/www02这两个目录内,同时这两个目录已经设置好权限,对于目录让所有的人都可以读取、运行,对于文件,让所有的人都可以读取
  以下是具体的配置过程:

  首先到希网去注册2个域名。然后为这2个域名分别建立文档目录

  # mkdir /home/www01

  # mkdir /home/www02

  编辑apache的配制文件httpd.conf

  # vi /usr/local/etc/apache/httpd.conf

  在文件最后找到下面2行

  在2行中间添加如下内容:

  NameVirtualHost *                 # 指定运行虚拟主机服务的主机ip地址

  # 静态ip方式可以将*替换为你的ip地址,动态ip直接用*即可

  ServerAdmin webmaster@www01.3322.org          #指定WEB管理员的邮箱

  DocumentRoot /home/www01 #指定本虚拟主机的文档目录

  ServerName www01.3322.org #指定本虚拟主机的域名

  ErrorLog /var/wwwlogs/www01.3322.org.error.log     #指定错误记录应该存放于那里

  CustomLog /var/wwwlogs/www01.3322.org.log common    #指定常规记录应该存放于那里

  ServerAdmin webmaster@www02.3322.org

  DocumentRoot /home/www02

  ServerName www02.3322.org

  ErrorLog /var/wwwlogs/www02.3322.org.error.log

  CustomLog /var/wwwlogs/www02.3322.org.log common

  创建/var/wwwlogs目录

  # mkdir /var/wwwlogs

  重新启动apache

  # /usr/local/etc/rc.d/apache.sh stop

  # /usr/local/etc/rc.d/apache.sh start

  分别在/home/www01和/home/www02目录拷入不同的网页文件进行测试,注意主页名称必须是index.html或index.php

  测试

  确认注册的2个域名已经指向了你的主机ip。

  在浏览器地址栏输入域

本文作者:
« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3