最後更
新日:2009/01/09
MySQL51 + Apache22 + PHP5 + phpMyAdmin

Description :
今天把我的
FreeBSD 升級到 7.1 R 版,順便升級 Apache 重 Apache20 升級到 Apache22,因為發現 FreeBSD
中新版 Apache22 的目錄變動很大因此順便再做個記錄,新版的 Apache22 把原本在 httpd.conf
中的設定獨立出來對應到 /usr/local/etc/apache22/extra 目錄中的獨立設定檔,好處是
httpd.conf 不再那麼肥大且分類之後設定更清楚了。
Environment :
硬體:i386 PC
Intel P4 1.5G
記憶體網卡:512M RAM +
Intel 網卡
作業系統:FreeBSD 7.2
Release
Setp
1.
安裝 MySQL51 及設置 MySQL51
# cd
/usr/ports/database/mysql51-server
#
make
WITH_CHARSET=utf8
install clean
#vi
/etc/rc.conf # 設定
MySQL 開機自動啟動
mysql_enable="YES"
# cp
/usr/local/share/mysql/my-medium.cnf /etc/my.cnf
#
vi /etc/my.cnf
# 依喜好自行修改
my.cnf
[mysqld]
default-character-set
= utf8
[client]
default-character-set
= utf8
#
/usr/local/etc/rc.d/mysql-server start
#
啟動 mysql
#
mysqladmin -u root -p password 新密碼
#
修改 root 密碼
Enter password:
#
直接 Enter 裝完時 root 預設是空密碼
# mysql -p
#
測試進入 mysql
Enter
password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.1.30-log FreeBSD port: mysql-server-5.1.30
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
Setp 2.
安裝 Apache22 及 設置 Apache22
#
cd
/usr/ports/www/apache22
# make install clean
#vi
/etc/rc.conf # 設定
Apache22 開機自動啟動
apache22_enable="YES"
#
vi /usr/local/etc/apache22/httpd.conf
# 編輯 Apache
的設定檔加入下列幾行
ServerAdmin admin@Domain
ServerName 127.0.0.1
DocumentRoot "/usr/local/www/apache22/data"
Include etc/apache22/extra/httpd-mpm.conf
Include etc/apache22/extra/httpd-languages.conf
Include etc/apache22/extra/httpd-userdir.conf
Include etc/apache22/extra/httpd-vhosts.conf
Include
etc/apache22/extra/httpd-default.conf
#
vi /usr/local/etc/apache22/extra/httpd-vhosts.conf
# 設定虛擬主機
NameVirtualHost 192.168.1.10
<VirtualHost 192.168.1.10>
ServerAdmin admin@Domain
DocumentRoot /usr/local/www/apache22/data/freebsd.ntut.idv.tw/www
ServerName freebsd.ntut.idv.tw
ErrorLog /var/log/httpd-error.log
CustomLog /var/log/httpd-access.log common
</VirtualHost>
# apachectl start # 出現錯誤訊息
[Fri Jan
09 02:27:34 2009] [warn] (2)No such file or directory: Failed to enable
the 'httpready' Accept Filter
# kldload accf_http # 修正錯誤訊息手動載入 accf_http
# vi
/boot/loader.conf # 讓開機時預先載入
accf_http_load="yes"
#
apachectl restart # 重新啟動 apache
Setp 3.
安裝 PHP5 及
phpMyAdmin
#
cd
/usr/ports/lang/php5 #
安裝 PHP5
# make
config #
會跳出所有的延伸套件供你選擇,依個人需求選擇自己所需要的
#
make
install clean
# cd
/usr/ports/lang/php5-extensions #
安裝 PHP5-extensions 延伸套件
# make
config #
會跳出所有的延伸套件供你選擇,依個人需求選擇自己所需要的
# make
config clean
# cd
/usr/ports/databases/phpmyadmin
# 安裝 phpMyAdmin
# make
install clean
#
vi /usr/local/etc/apache22/httpd.conf
# 編輯 Apache
的設定檔加入下列幾行
LoadModule
php5_module
libexec/apache22/libphp5.so
# 取消 Mark 把 php5 Module 載入
DirectoryIndex index.php index.html
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
# cp
/usr/local/etc/php.ini-dist
/usr/local/etc/php.ini
# 複製 php.ini-dist 到 php.ini
# vi
/usr/local/www/apache22/data/index.php # 編輯一個 phpinfo 檔
<?php
phpinfo();
?>
#
apachectl restart # 重新啟動 apache
開
個 Browse 查看 http://HostName/index.php PHP
有無啟動。
#
cd /usr/local/www/phpMyAdmin/libraries
# 切換目錄
#
cp config.default.php config.inc.php
#
vi config.inc.php
# 修改為 http
認證
$cfg['Servers'][$i]['auth_type']
= 'http';
#
vi /usr/local/etc/apache22/httpd.conf
# 編輯 Apache
的設定檔加入下列幾行
Alias /phpmyadmin/
"/usr/local/www/phpMyAdmin/"
<Directory "/usr/local/www/phpMyAdmin/">
Options none
AllowOverride Limit
Order Deny,Allow
Deny from all
Allow from 127.0.0.1 192.168.1.0/24
</Directory>
#
apachectl restart # 重新啟動 apache
開個
http://IP/phpmyadmin/ 查看 phpMyAdmin 可否連線。
Reference.
http://www.cyberciti.biz/faq/freebsd-apache22-fastcgi-php-configuration/