歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Unix知識 >> BSD >> Freebsd 6.0安裝配置Apache+MySQL+PHP+Myphpadmin+Webmin

Freebsd 6.0安裝配置Apache+MySQL+PHP+Myphpadmin+Webmin

日期:2017/3/1 18:14:19   编辑:BSD

一、安裝Freebsd

A、系統分區

很多人在使用自己的作業系統時,不知道如何對系統分區,對於分區方案沒有最好的,只是跟據自己的情況去分。
下面是我的分區方案。

硬盤為120G ,/(根)1G 左右就差不多了,但考濾到/root 工作目錄也在這裡,所以分大一點。

/home/data 主要是用來存放Email /ftp用戶的數據

/tmp 1G 也是考慮到臨時文件多,所以給大也點。

/usr/ 10G 因為要安裝軟件,還有下載的軟件,我沒有裝GUI 所以只分了10G我認為足夠了。

/var 3G這個目錄存放的東西比較多,如日志、郵件的臨時目錄,如果空間不夠amavisd-new 無法解開郵件進行殺毒。

 %df -h
  Filesystem   Size    Used    Avail   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 。

下載BSD時,只需要下載DISK 1 就行了,缺少的軟件包可以通過網絡安裝。

C、配置系統

如果你在安裝後期沒有配置系統,在系統啟動完成後以root的身份登陸系統,運行sysinstall 進行設置,

或通過ee編輯器編輯/etc/rc.conf文件,在這裡提醒各位,一會大多數服務都需要在/etc/rc.conf加入啟動內容才能正常啟動。

設置好固定IP,或通過DHCP 自動分配置機器IP。使用SSH 客戶端進行管理服務器將會為你的工作提供方便。

使用SSH 要注意:

啟用 sshd

  sshd 的啟用是作為 FreeBSD 安裝中 Standard 安裝過程中的一步來進行的。 要查看 sshd 是否已被啟用, 請檢查 rc.conf 文件中的:

sshd_enable="YES"
 

  這表示在下次系統啟動時加載 OpenSSH 的服務程序 sshd(8)。 此外,也可以手動使用 rc(8) 腳本 /etc/rc.d/sshd 來啟動 OpenSSH

/etc/rc.d/sshd start

允許用戶登錄 AllowUsers 選項

  通常限制哪些用戶能夠登錄, 以及從何處登錄會是好主意。 采用 AllowUsers 選項能夠方便地達到這一目的。 例如, 想要只允許 root 用戶從 192.168.1.32 登錄, 就可以在 /etc/ssh/sshd_config 文件中加入下述設置:

AllowUsers [email protected]

  要允許用戶 admin 從任何地方登錄, 則只需列出用戶名:

AllowUsers admin

  可以在同一行指定多個用戶, 例如:

AllowUsers [email protected] admin

注意: 列出需要登錄機器的用戶很重要; 否則他們將被鎖在外面。

  在完成對 /etc/ssh/sshd_config 的修改之後您必須告訴 sshd(8) 重新加載其配置文件, 方法是執行:

#
				/etc/rc.d/sshd reload

a、不能用root直接登陸,需要添加一個新用戶,指定到wheel 組,用此用戶登陸後用使用 su - 提升到管理員。

b、 以我的SecureCRT 為例,Session options ->Authentication ->Primary 選擇keyboard Interactive

c、如果你要使用像LINUX 一樣的彩色顯示,需要把 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 最好的地方就是安裝軟件方便,還可以裝到最新的軟件包,這就是強大的posts 系統。如果你的系統在安裝時沒有選擇posts ,具休如何操作看BSD 的handbook.

對ports 進行更新,首先修改系統默認下載的FTP地址:

#vi /etc/make.conf

添加下列四個連接地址,第一個為HTTP連接其余都是FTP.

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 的站點很多,你可以選擇離你最快的站點去更新posts ,具體查看 freebsd.org /freebsdchina.org.cn

在使用cvsup之前你必須連接到互聯網,並需要安裝cvsup 這個軟件

a、安裝cvsup-without-gui

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

b、更新ports
安裝完cvsup軟件後,

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

三、安裝數據庫 MySQL

MySQL 版本很多,大家可以據自己需要自行安裝。

%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

在此說明:

1、如果不在/etc/rc.conf 加入以上內容,手工是無法啟動MySQL的。
2、如果你想知道這個軟件應該在/etc/rc.conf加入什麼內容,

打開/usr/local/etc/rc.d 目錄,找到此軟件的啟動腳本。然後打開文件,如果有詳細的說明。

%/usr/local/etc/rc.d/mysql-server.sh start
 Starting mysql.

如何去檢查一個服務是否正常啟動:1、通過ps查看進程,2、檢查所打開的端口。

%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安裝時,服務器的密碼為空,建議你裝好系統後,第一時間去更改密碼。

% /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服務器已經是街知港聞了。
% cd /usr/ports/www/apache22/
% make install clean
 
     │                     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"

如果啟動時出現httpd: Could not reliably determine the

server's fully qualified domain name, using mail.sharesky.cn for ServerName 的錯誤,

在/usr/local/etc/apache22/httpd.conf 約第144行的位置加入下面的內容。

ServerName mail.extmail.org

啟動apahce

% /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                    x  
               x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x  
               x x         [ ] DEBUG      Enable debug                            x x  
               x x         [X] MULTIBYTE  Enable zend multibyte support           x x  
               x x         [ ] IPV6       Enable ipv6 support                     x x  
               x x         [X] OPENSSL    Build static OpenSSL extension       

在/usr/local/etc/apache22/httpd.conf 裡加入

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

加入目錄索引 index.php,約在httpd.conf 的212行

 DirectoryIndex index.html index.php

restart或reload 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庫免得浪費時間,大家可據自己需要選擇安裝模塊
               lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
               x                 Options for php4-extensions 1.0                    x  
               x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x  
               x x  [ ] BCMATH       bc style precision math functions            x x  
               x x  [X] BZ2          bzip2 library support                        x x  
               x x  [ ] CALENDAR     calendar conversion support                  x x  
               x x  [ ] CRACK        crack support                                x x  
               x x  [X] CTYPE        ctype functions                              x x  
               x x  [X] CURL         CURL support                                 x x  
               x x  [ ] DBA          dba support                                  x x  
               x x  [ ] DBASE        dBase library support                        x x  
               x x  [ ] DBX          dbx support                                  x x  
               x x  [ ] DIO          Direct I/O support                           x x  
               x x  [ ] DOMXML       DOM support                                  x x  
               x x  [ ] EXIF         EXIF support                                 x x  
               x x  [ ] FILEINFO     fileinfo support                             x x  
               x x  [ ] FILEPRO      filePro support                              x x  
               x x  [ ] FRIBIDI      FriBidi support     
			     x x  [X] FTP          FTP support                                  x x  
               x x  [ ] GD           GD library support                           x x  
               x x  [X] GETTEXT      gettext library support                      x x  
               x x  [ ] GMP          GNU MP support                               x x  
               x x  [X] ICONV        iconv support                                x x  
               x x  [ ] IMAGICK      ImageMagick support                          x x  
               x x  [X] IMAP         IMAP support                                 x x  
               x x  [ ] INTERBASE    Interbase 6 database support (Firebird)      x x  
               x x  [ ] LDAP         OpenLDAP support                             x x  
               x x  [X] MBSTRING     multibyte string support                     x x  
               x x  [ ] MCAL         Modular Calendar Access Library support      x x  
               x x  [X] MCRYPT       Encryption support                           x x  
               x x  [ ] MCVE         MCVE support                                 x x  
               x x  [ ] MHASH        Crypto-hashing support                       x x  
			     x x  [ ] MING         ming shockwave flash support                 x x  
               x x  [ ] MNOGOSEARCH  mnoGoSearch support                          x x  
               x x  [ ] MSSQL        MS-SQL database support                      x x  
               x x  [X] MYSQL        MySQL database support                       x x  
               x x  [ ] NCURSES      ncurses support (CLI only)                   x x  
               x x  [ ] ODBC         unixODBC support                             x x  
               x x  [X] OPENSSL      OpenSSL support                              x x  
               x x  [ ] ORACLE       Oracle support                               x x  
               x x  [X] OVERLOAD     user-space object overloading support        x x  
               x x  [ ] PANDA        panda support                                x x  
               x x  [ ] PCNTL        pcntl support (CLI only)                     x x  
               x x  [X] PCRE         Perl Compatible Regular Expression support   x x  
               x x  [ ] PDF          PDFlib support (implies GD)                  x x  
               x x  [ ] PFPRO        PayFlow Pro support                          x x  
			     x x  [ ] PGSQL        PostgreSQL database support                  x x  
               x x  [X] POSIX        POSIX-like functions                         x x  
               x x  [ ] PSPELL       pspell support                               x x  
               x x  [ ] READLINE     readline support (CLI only)                  x x  
               x x  [ ] RECODE       recode support                               x x  
               x x  [X] SESSION      session support                              x x  
               x x  [ ] SHMOP        shmop support                                x x  
               x x  [ ] SNMP         SNMP support                                 x x  
               x x  [ ] SOCKETS      sockets support                              x x  
               x x  [ ] SYBASE_CT    Sybase database support                      x x  
               x x  [ ] SYSVMSG      System V message support                     x x  
               x x  [ ] SYSVSEM      System V semaphore support                   x x  
               x x  [ ] SYSVSHM      System V shared memory support               x x  
               x x  [X] TOKENIZER    tokenizer support                            x x  
			     x x  [ ] WDDX         WDDX support (implies XML)                   x x  
               x x  [X] XML          XML support                                  x x  
               x x  [ ] XMLRPC       XMLRPC-EPI support                           x x  
               x x  [ ] XSLT         XSLT Sablotron support                       x x  
               x x  [ ] YAZ          YAZ support (ANSI/NISO Z39.50)               x x  
               x x  [ ] YP           YP/NIS support                               x x  
               x x  [ ] ZIP          ZIP support                                  x x  
               x x  [X] ZLIB         ZLIB support                                 x x  
 
 
# vi /usr/local/www/apache22/data/test.php 
輸入:
<?php phpinfo(); ?>

4、安裝phpmyadmin 管理數據庫

為了去除無聊的安裝過程,這裡選擇手工安裝,先下載軟件包,然後解壓,再復制到/usr/local/www/apache22/data 下面

%cd /usr/ports/databases/phpmyadmin/
%make fetch
%cd /usr/ports/distfile
%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
%cd /usr/local/www/apache22/data/phpmyadmin/
%ee config.default.php 

將$cfg['Servers'][$i]['auth_type'] = 'config'; 改為

$cfg['Servers'][$i]['auth_type']     = 'http'; 
打開頁面彈出驗證窗口。

打開http://ip/phpmyadmin 就可以管理你的mysql 數據庫了

推出保存 #chmod 755 test.php
大家注意,可能你下載的版本與我下載的不一樣,不能照搬。 設置phpmyadmin phpMyAdmin-2.8.1 版的Port 安裝方法. # whereis phpmyadmin
phpmyadmin: /usr/ports/databases/phpmyadmin
cd /usr/ports/databases/phpmyadmin make install clean #cd /usr/local/www/phpMyAdmin/ 進入phpmyadmin下的libraries 目錄! 修改 config.default.php #vi libraries/config.default.php
找到$cfg['PmaAbsoluteUri'] = '';
修改成 $cfg['PmaAbsoluteUri'] = 'http://你的IP/phpmyadmin';
找到
$cfg['Servers'][$i]['auth_type'] = 'config'; // Authentication method (config, http or cookie based)?
$cfg['Servers'][$i]['user'] = 'root'; // MySQL user
$cfg['Servers'][$i]['password'] = '';
寫上你的Mysql用戶名and密碼!保存退出!
因為phpmyadmin的PATH 是:/usr/local/www/phpmyadmin 所以我們需要在APACHE裡面建立一個Alias: #vi /usr/local/etc/apache22/httpd.conf 在Alias 組加入下列內容: *************************************************** Alias /phpmyadmin "/usr/local/www/phpMyAdmin/"
<Directory /usr/local/www/phpMyAdmin/>
Order allow,deny
Allow from all
</Directory> ***************************************************
保存退出.
彈出驗證窗口。 修改/usr/local/www/phpMyAdmin/libraries/config.default.php 中的:$cfg['Servers'][$i]['auth_type'] = "config" 改成: $cfg['Servers'][$i]['auth_type'] = 'http'; # /usr/local/etc/rc.d/apache22.sh reload 然後用http://your IP/phpmyadmin訪問!

5 使用同一個IP的虛擬主機設置方法:

取消中心主機,在ServerName 前面加井號屏蔽.

添加虛擬主機設置,比如說,假設你正在為域名www.domain.tld提供服務, 而你又想在同一個IP地址上加一個名叫www.otherdomain.tld的虛擬主機, 你只需在httpd.conf中加入以下內容:

NameVirtualHost *

<VirtualHost *>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain
</VirtualHost>

<VirtualHost *>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>

和添加別名是雷同的.

6 安裝WEBMIN

mail# 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

Copyright © Linux教程網 All Rights Reserved