首页 > 操作系统 >FreeBSD 6.0 安装配置 Apache+MySQL+PHP+phpMyAdmin+Webmin

FreeBSD 6.0 安装配置 Apache+MySQL+PHP+phpMyAdmin+Webmin

来源:互联网 2026-07-31 12:11:15

一、安装 FreeBSD A、系统分区 很多新手面对分区时往往不知所措。其实分区方案没有绝对的标准,完全取决于你的实际需求。这里给出一个针对 120G 硬盘的常见分配思路,供大家参考。 根分区(/)留 1G 左右看起来够用,但考虑到 /root 工作目录也在这里,建议稍微分大一点。/home/dat

一、安装 FreeBSD

A、系统分区

很多新手面对分区时往往不知所措。其实分区方案没有绝对的标准,完全取决于你的实际需求。这里给出一个针对 120G 硬盘的常见分配思路,供大家参考。

根分区(/)留 1G 左右看起来够用,但考虑到 /root 工作目录也在这里,建议稍微分大一点。/home/data 用来存放 Email 和 FTP 用户的数据。/tmp 给了 1G,临时文件多的时候不会捉襟见肘。/usr 分配 10G——不装 GUI 的话,这个空间足够安装软件和下载包了。/var 给了 3G,日志、邮件临时目录都往这里写,如果空间不够,像 ama vis-new 这样的杀毒工具就没法正常解包处理邮件。

长期稳定更新的攒劲资源: >>>点此立即查看<<<

%df -h
Filesystem    Size    Used    A vail   Capacity   Mounted on
/dev/ad0s1a   1.9G    481M    1.3G    26%        /
devfs         1.0K    1.0K    0B      100%       /dev
/dev/ad0s1g   92G     353M    84G     0%         /home/data
/dev/ad0s1e   989M    224K    910M    0%         /tmp
/dev/ad0s1f   9.7G    1.8G    7.1G    20%        /usr
/dev/ad0s1d   2.9G    105M    2.6G    4%         /var

B、安装基本系统

系统安装时建议选择 minimal(最小系统)加上 ports。不必要的包一个都不装,既减少系统体积,也降低攻击面。作为服务器,GUI 从来都不是必要的。

下载 FreeBSD 镜像时,只下载 Disc 1 就足够了,缺少的软件包完全可以通过网络安装。

C、配置系统

如果在安装后期没有完成系统配置,启动后用 root 登录,运行 sysinstall 或者用 ee 编辑器直接修改 /etc/rc.conf。这里提醒一下:大部分服务都需要在 /etc/rc.conf 中加入相应的启动项才能正常自启。

设置好固定 IP(或者用 DHCP 自动分配),然后通过 SSH 客户端来管理服务器,效率会高很多。

SSH 配置要点

启用 sshd 通常是在安装过程中作为标准步骤完成的。检查 /etc/rc.conf 中是否有 sshd_enable="YES",这表示下次系统启动时会自动加载 OpenSSH 服务。当然也可以手动启动:

/etc/rc.d/sshd start

限制登录用户:在 /etc/ssh/sshd_config 中使用 AllowUsers 选项,可以精确控制哪些用户从哪些 IP 登录。例如只允许 root 从 192.168.1.32 登录:

AllowUsers root@192.168.1.32

要允许 admin 从任意地方登录,直接写用户名:AllowUsers admin。多个用户用空格隔开。

注意:一定要把需要登录的用户全部列进去,否则他们会被锁在外面。

修改配置文件后,执行 /etc/rc.d/sshd reload 使其生效。

安全建议:不要直接用 root 远程登录。应添加一个新用户,将其加入 wheel 组,然后用该用户登录,再通过 su - 切换到 root。

SecureCRT 下的配置(以个人习惯为例):Session Options → Authentication → Primary 选择 Keyboard Interactive。如果想要彩色终端显示,在 Emulation → Terminal → Xterm 中选中 ANSI Color,然后在 /etc/csh.cshrc 中加入:

setenv LSCOLORS ExGxFxdxCxegedabagExEx
setenv CLICOLOR yes
set autolist

执行以下命令让配置生效:

sed -i.bak -E s/set\ prompt/#set\ prompt/g /root/.cshrc

退出重新登录,就能看到彩色目录了。

二、更新软件包

FreeBSD 最方便的地方之一就是强大的 ports 系统,可以轻松安装最新软件。如果安装时没有选择 ports,请参考 Handbook 补装。

更新 ports 前,建议先修改系统默认的下载地址,提高速度。编辑 /etc/make.conf,添加以下镜像:

MASTER_SITE_OVERRIDE= \
http://ports.hshh.org/${DIST_SUBDIR}/ \
ftp://ftp.freebsdchina.org/pub/FreeBSD/ports/distfiles/${DIST_SUBDIR}/ \
ftp://ftp.tw.freebsd.org/pub/ports/distfiles/${DIST_SUBDIR}/ \
ftp://freebsd.csie.nctu.edu.tw/pub/ports/distfiles/${DIST_SUBDIR}/

CVSup 的站点有很多,选择离你最近的能加快更新速度。具体站点列表可以查看 freebsd.org 或 freebsdchina.org.cn。

安装 cvsup-without-gui

% cd /usr/ports/net/cvsup-without-gui/
% make install clean

更新 ports

% /usr/local/bin/cvsup -gL 2 -h cvsup4.freebsdchina.org /usr/share/examples/cvsup/ports-supfile

三、安装 MySQL

MySQL 版本众多,根据需求自行选择。这里以 mysql41-server 为例:

% cd /usr/ports/databases/mysql41-server/
% make install clean

/etc/rc.conf 中加入:

mysql_enable="YES"

复制配置文件(非必需):

cp /usr/local/share/mysql/my-small.cnf /usr/local/etc/my.cnf

说明:

  • 如果不加 mysql_enable="YES",手工是无法启动 MySQL 的。
  • 想知道某软件在 /etc/rc.conf 中应该加什么内容,可以查看 /usr/local/etc/rc.d/ 下对应的启动脚本,通常里面都有详细说明。
% /usr/local/etc/rc.d/mysql-server.sh start
Starting mysql.

检查服务是否正常启动,可以使用 ps 看进程,或者用 netstat 看端口:

% ps aux|grep mysql
mysql 94899  0.2  0.5  1644  1240  p0  S     3:52PM   0:00.07 /bin/sh /usr/local/bin/mysqld_safe --
mysql 94919  0.0 10.8 55564 27428  p0  S     3:52PM   0:01.54 /usr/local/libexec/mysqld --defaults-
% netstat -an|grep 3306
tcp4       0      0  *.3306                 *.*                    LISTEN

MySQL 安装后 root 密码为空,强烈建议立即修改:

% /usr/local/bin/mysqladmin -u-root -p password 你的新密码
Enter password:

如果服务器仅供内部使用,可以在 my.cnf 中加入以下内容限制本地访问,提升安全性:

[mysqld]
bind_address=127.0.0.1

四、安装 Apache

1. 安装 Apache Server

Apache 在 Web 服务器领域的地位无需多言。通过 ports 安装:

% cd /usr/ports/www/apache22/
% make install clean

安装过程中会出现选项菜单(比如 Python 的线程支持等),根据需求勾选即可。典型的选项界面如下(以 Python 2.4.3 为例):

                    Options for python 2.4.3
│ [X] THREADS        Enable thread support
│ [ ] HUGE_STACK_SIZE Use a larger thread stack
│ [X] UCS4           Use UCS4 for unicode support
│ [X] PYMALLOC       Use python's internal malloc
│ [ ] IPV6           Enable IPv6 support
│ [ ] FPECTL         Enable floating point exception handling

/etc/rc.conf 中加入:

apache22_enable="YES"

启动时如果遇到“Could not reliably determine the server's fully qualified domain name”错误,在 /usr/local/etc/apache22/httpd.conf 约第 144 行位置添加:

ServerName mail.extmail.org

启动 Apache:

% /usr/local/etc/rc.d/apache22.sh start
Performing sanity check on apache22 configuration:
Syntax OK
Starting apache22.

2. 安装 PHP

% cd /usr/ports/www/mod_php4/
% make install clean

同样会出现选项窗口,例如:

                  Options for mod_php4 4.4.2_1,1
│ [ ] DEBUG      Enable debug
│ [X] MULTIBYTE  Enable zend multibyte support
│ [ ] IPV6       Enable ipv6 support
│ [X] OPENSSL    Build static OpenSSL extension

httpd.conf 中添加以下两行,让 Apache 能够解析 PHP 文件:

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

index.php 加入目录索引,约在 httpd.conf 的 212 行:

DirectoryIndex index.html index.php

重启或重载 Apache 使其生效:

% /usr/local/etc/rc.d/apache22.sh reload
Performing sanity check on apache22 configuration:
Syntax OK
Performing a graceful restart

3. 安装 PHP 扩展

% cd /usr/ports/lang/php4-extensions/
% make install clean

这里建议:如果没有特殊需要,尽量不装 GD 库以节省编译时间。根据实际需求勾选需要的模块,常见的选项包括:

                 Options for php4-extensions 1.0
│ [ ] BCMATH       bc style precision math functions
│ [X] BZ2          bzip2 library support
│ [X] CTYPE        ctype functions
│ [X] CURL         CURL support
│ [X] FTP          FTP support
│ [X] GETTEXT      gettext library support
│ [X] ICONV        iconv support
│ [X] IMAP         IMAP support
│ [X] MBSTRING     multibyte string support
│ [X] MCRYPT       Encryption support
│ [X] MYSQL        MySQL database support
│ [X] OPENSSL      OpenSSL support
│ [X] OVERLOAD     user-space object overloading support
│ [X] PCRE         Perl Compatible Regular Expression support
│ [X] POSIX        POSIX-like functions
│ [X] SESSION      session support
│ [X] TOKENIZER    tokenizer support
│ [X] XML          XML support
│ ... 等等

安装完成后,可以在 /usr/local/www/apache22/data/ 下创建一个测试文件 test.php

4. 安装 phpMyAdmin 管理数据库

为了省去繁琐的安装过程,这里推荐手工安装。先下载软件包,解压后复制到 Web 目录下。

% cd /usr/ports/databases/phpmyadmin/
% make fetch
% cd /usr/ports/distfiles
% tar jxvf phpMyAdmin-2.7.0-pl2.tar.bz2
% cp -r /usr/ports/distfiles/phpMyAdmin-2.7.0-pl2 /usr/local/www/apache22/data/phpmyadmin

然后修改配置文件 config.default.php

% cd /usr/local/www/apache22/data/phpmyadmin/
% ee config.default.php

$cfg['Servers'][$i]['auth_type'] = 'config'; 改为:

$cfg['Servers'][$i]['auth_type'] = 'http';

这样打开页面时就会弹出用户名密码验证窗口。最后设置权限:

#chmod 755 test.php

访问 http://IP/phpmyadmin 即可管理 MySQL 数据库。

注意: 你下载的 phpMyAdmin 版本可能与我示例的不同,请根据实际情况调整。

另一种常见方法——通过 Port 安装 phpMyAdmin-2.8.1:

# whereis phpmyadmin
phpmyadmin: /usr/ports/databases/phpmyadmin
# cd /usr/ports/databases/phpmyadmin
# make install clean

安装后,进入 /usr/local/www/phpMyAdmin/,修改 libraries/config.default.php

# vi libraries/config.default.php
找到 $cfg['PmaAbsoluteUri'] = '';
修改成 $cfg['PmaAbsoluteUri'] = 'http://你的IP/phpmyadmin';
找到
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
写上自己的 MySQL 用户名和密码,保存退出。

由于 phpMyAdmin 的默认路径是 /usr/local/www/phpmyadmin,需要在 Apache 中建立别名。编辑 /usr/local/etc/apache22/httpd.conf,在 Alias 组中加入:

Alias /phpmyadmin "/usr/local/www/phpMyAdmin/"

    Order allow,deny
    Allow from all

保存后重启 Apache:

# /usr/local/etc/rc.d/apache22.sh reload

然后访问 http://your IP/phpmyadmin。如果想用 HTTP 验证方式,同样修改 config.default.php 中的 auth_type'http'

5. 使用同一个 IP 的虚拟主机设置

首先取消中心主机,在 httpd.confServerName 前面加 # 注释掉。然后添加虚拟主机配置。假设你为域名 domain.tld 提供服务,还想在同一个 IP 上加一个 otherdomain.tld

NameVirtualHost *

    ServerName domain.tld
    ServerAlias domain.tld *.domain.tld
    DocumentRoot /www/domain


    ServerName otherdomain.tld
    DocumentRoot /www/otherdomain

和添加别名的思路是一样的。

6. 安装 Webmin

# whereis webmin
webmin: /usr/ports/sysutils/webmin
# cd /usr/ports/sysutils/webmin
# make install clean
# cd /usr/local/etc/webmin
# sh start

然后访问 http://IP:10000 即可通过 Web 界面管理服务器。

侠游戏发布此文仅为了传递信息,不代表侠游戏网站认同其观点或证实其描述

热游推荐

更多
湘ICP备14008430号-1 湘公网安备 43070302000280号
All Rights Reserved
本站为非盈利网站,不接受任何广告。本站所有软件,都由网友
上传,如有侵犯你的版权,请发邮件给xiayx666@163.com
抵制不良色情、反动、暴力游戏。注意自我保护,谨防受骗上当。
适度游戏益脑,沉迷游戏伤身。合理安排时间,享受健康生活。