2007年4月24日 星期二

Fedora-Mysql+Apache+PHP4+PhpMyAdmin+phpSysInfo+Awstats

Fedora-Mysql+Apache+PHP4+PhpMyAdmin+phpSysInfo+Awstats開始用於1/2005 fedora 的版本core 3來安裝(目前已經出到core 5,視情況自己決定更新),系統預設除了sendmail / dns / develop tools 之外就不再安裝其他檔案,有需要後期再手動更新。會安裝的服務-- -- -- -- -- -- 灌好Fedora 後下載需要檔案 -- 放在(/usr/local/src/)1.httpd-2.0.53.tar.gz -- http://apache.cdpa.nsysu.edu.tw/httpd/2.php-4.3.9.tar.gz -- http://ftp.nsysu.edu.tw/Unix/Web/php/3.mysql-standard-4.0.23-pc-linux-i686.tar.gz -- http://mysql.isu.edu.tw/(由於4.1版更新了fulltext search/多國語系等功能的改進,導致要在舊code 作指定utf-8,所以自行決定用不用)4.phpMyAdmin-2.6.0-pl3.tar.gz -- http://www.phpmyadmin.net/5.phpsysinfo-2.3.tar.gz -- http://phpsysinfo.sourceforge.net/6.awstats-6.2.tgz -- http://awstats.sourceforge.net/Mysql---------------------------------------------------------------------------]# groupadd -g 315 mysql //開一個mysql account]# useradd -u 315 -g mysql -d /usr/local/mysql/data -M mysql//建立家目錄在 /usr/local/mysql/data 裡面]# cd /usr/local]# tar -zxvf /usr/local/src/mysql-standard-4.0.23-pc-linux-i686.tar.gz//會產生目錄mysql-standard-4.0.23-pc-linux-i686]# ln -s mysql-standard-4.0.23-pc-linux-i686 mysql//將 MySQL 安裝在 /usr/local/mysql//為了升級版本的確認,建議使用連結的方式來進行 MySQL 的使用]# mkdir -p /var/lib/mysql]# chown -R mysql:mysql /var/lib/mysql]# chown -R root:mysql /usr/local/mysql-standard-4.0.23-pc-linux-i686]# chown -R mysql:mysql /usr/local/mysql/data]# cd mysql]# ./scripts/mysql_install_db //建立資料庫]# chown -R mysql:mysql /var/lib/mysql]# chown -R mysql:mysql /usr/local/mysql/data]# /usr/local/mysql/bin/safe_mysqld --user=mysql & //啟動 mysql 測試Starting mysqld daemon with databases from /usr/local/mysql/data]# ln -s /var/lib/mysql/mysql.sock /tmp/]# netstat -tl grep mysqltcp 0 0 *:mysql *:* LISTEN]# vi /etc/rc.d/rc.localcd /usr/local/mysql; /usr/local/mysql/bin/safe_mysqld --user=mysql &//開機後自動啟動]# /usr/local/mysql/bin/mysqladmin -u root password 'your.password'//建立mysql密碼]# /usr/local/mysql/bin/mysql -u root -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2 to server version: 4.0.23Type 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql> exitBye//mysql 資料庫的存放有兩個可能地方1./var/lib/mysql2./usr/local/mysql/data//mysql shutdown]# /usr/local/mysql/bin/mysqladmin -u root -p shutdown---------------------------------------------------------------------------Apache ---------------------------------------------------------------------------]# cd /usr/local/src]# tar -zxvf httpd-2.0.53.tar.gz]# cd httpd-2.0.53]# ./configure --prefix=/usr/local/apache \> --enable-so --enable-rewrite(--enable-module=so --enable-module=rewrite --activate-module=src/modules/php4/libphp4.a for apache 1.3.xx)]# make; make install]# cd /usr/local/apache]# vi /usr/local/apache/conf/httpd.confUser nobodyGroup #-1 -->Group nobody]# /usr/local/apache/bin/apachectl start]# netstat -utltcp 0 0 *:http *:* LISTEN//預設網頁根目錄在 /usr/local/apache/htdocs/---------------------------------------------------------------------------PHP---------------------------------------------------------------------------]# cd /usr/local/src]# tar -zxvf php-4.3.9.tar.gz]# cd php-4.3.9]# ./configure --prefix=/usr/local/php4 \>--with-apxs2=/usr/local/apache/bin/apxs \>--with-mysql=/usr/local/mysql \>--with-config-file-path=/usr/local/php4]# make; make install]# cp php.ini-dist /usr/local/php4/php.ini]# vi /usr/local/apache/conf/httpd.conf //加下面兩行LoadModule php4_module modules/libphp4.soAddType application/x-httpd-php .php]# /usr/local/apache/bin/apachectl restart]# vi test.php //?phpinfo();? 測試PHP 在Apache 上運作 ---------------------------------------------------------------------------phpMyAdmin---------------------------------------------------------------------------]# cd /usr/local/src]# tar -zxvf phpMyAdmin-2.6.0-pl3.tar.gz]# mv phpMyAdmin-2.6.0-pl3 /www/htdocs/phpMyAdmin]# cd /www/htdocs/phpMyAdmin]# cp config.inc.php config.inc.php.bak]# vi config.inc.php$cfg['PmaAbsoluteUri'= 'http://IP/phpMyAdmin/';$cfg['Servers'][$i]['auth_type'] = 'config';$cfg['Servers'][$i]['user'] = 'root';$cfg['Servers'][$i]['password'] = '設定密碼';http://IP/phpMyAdmin 測試---------------------------------------------------------------------------phpSysInfo---------------------------------------------------------------------------]# cd /usr/local/src]# tar -zxvf phpsysinfo-2.3.tar.gz]# mv phpsysinfo-dev /www/htdocs/phpsysinfo]# cd /www/htdocs/phpsysinfo]# cp config.php.new config.phphttp://IP/phpsysinfo 測試---------------------------------------------------------------------------Awstats---------------------------------------------------------------------------]# cd /usr/local/src]# tar -zxvf awstats-6.2.tgz]# mv awstats-6.2 /usr/local/awstats]# cd /usr/local/awstats/tools]# perl awstats_configure.pl //產生分析 apache log 的 AWStats 設定檔......-----> Need to create a new config file ?Do you want me to build a new AWStats config/profilefile (required if first install) [y/N] ?y......-----> Define config file name to createWhat is the name of your web site or profile analysis ?Example: www.mysite.comExample: demoYour web site, virtual server or profile name:> www.example.com......-----> Define config file pathIn which directory do you plan to store your config file(s) ?Default: /etc/awstatsDirectory path to store config file(s) (Enter for default):> (Press 'Enter')......]# chmod 755 /usr/local/awstats]# mkdir /var/lib/awstats]# ls /etc/awstats]# cp /etc/awstats/awstats.www.example.com.conf awstats.www.example.com.conf.bak]# vi /etc/awstats/awstats.www.example.com.confLogFile="/usr/local/apache/logs/access_log"SiteDomain="www.example.com"DirCgi="/cgi-bin"DirIcons="/icon"DefaultFile="index.php"Lang="tw"]# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.example.com -update]# /usr/local/apache/bin/apachectl restarthttp://www.example.com/awstats/awstats.pl?config=www.example.com]# vi /etc/crontab0 2 * * * root perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.example.com//設定每天凌晨2點重新讀檔(ps. os:windows)1.確定 httpd.conf access_log 為 combined2.如出現 ...couldn't spawn child process: c:/mywebroot/cgi-bin/awstats.pl 500 Error到 httpd.conf 加上 ScriptInterpreterSource registry (coz web server is not able to known how to run perl scripts)3.c:\Program Files\AWStats\wwwroot\cgi-bin\awstats.www.example.com 改log files 路徑---------------------------------------------------------------------------兩台server 透過SSH 不需要輸入密碼加密傳輸檔案方式 -- 可當作備份用 設定如下:]#cd /root/.ssh (進入到/root/.ssh/ 目錄下)]#ssh-keygen -d (產生ssh的公鑰和私鑰)Generating public/private dsa key pair.Enter file in which to save the key (/root/.ssh/id_dsa): (產生到 -- 按Enter 即可)Enter passphrase (empty for no passphrase): (設定passwd -- 按Enter 即可)Enter same passphrase again: (再按一次Enter)Your identification has been saved in /root/.ssh/id_dsa.Your public key has been saved in /root/.ssh/id_dsa.pub.此時目錄下會產生公鑰 id_dsa.pub 和私鑰 id_dsa 現在要把 id_dsa.pub 丟到 [另一台的IP] 並且更名為 authorized_keys]#scp id_dsa.pub [另一台的IP] :/root/.ssh/authorized_keysroot@[另一台的IP] 's password:id_dsa.pub 100% ***************************** 613 00:00現在 ssh 到 另一台 server 就不用輸入密碼了。PS: 如果無法用 SCP 傳檔,可到 /root/.ssh/ 目錄下打開 known_hosts,將裡頭資料清空便可。---------------------------------------------------------------------------網頁資料的壓縮、備份、排程 將備份好的檔放在 /home/backup/ 底下( autobackup.sh --- 這是備份資料庫的程式檔 )裡面寫上 /usr/local/mysql/bin/mysqladmin -uroot -p[密碼] shutdown (先關掉資料庫)tar cvfz /home/backup/backup_mysql.tar.gz /var/lib/mysql/ (將存放db的folder壓縮後,放在/home/backup 底下)/usr/local/mysql/bin/safe_mysqld --user=mysql & (重新執行mysql )----------------------------------------------------------------第二個檔 ( autobackup_www.sh --- 這是備份網頁的程式檔 )裡面寫上 /usr/local/apache/bin/apachectl stop (先關閉apache)tar cvfz /home/backup/backup_www.tar.gz /www/htdocs (將存放www的folder壓縮後,放在/home/backup 底下)/usr/local/apache/bin/apachectl start (重新執行apache )----------------------------------------------------------------]#crontab -l (列出排程備份的項目)50 1 * * * /home/backup/autobackup.sh (Day 1:50a.m.,執行/home/backup/autobackup.sh)15 2 * * 1 /home/backup/autobackup_www.sh (Mon. 2:15a.m.,執行home/backup/autobackup_www.sh)15 2 * * 3 /home/backup/autobackup_www.sh (Weds. 2:15a.m.,執行home/backup/autobackup_www.sh)15 2 * * 5 /home/backup/autobackup_www.sh (Fri. 2:15a.m.,執行home/backup/autobackup_www.sh)最後如要修改排程的話,請用 crontab -e