2011年1月25日 星期二

Apache+MySQL+PHP - source安裝

環境RedHat AS5 for x86

確認所需套件zlib-devel.*  openssl-devel.*  libxml2-devel.*  flex 
bison  gcc  automake  autoconf  apache2  mysql  php  php-gd  php-mysql  php-pear  phpMyAdmin


例如:  # rpm -qa |grep zlib-devel
#zlib-devel-1.2.3-18.fc9.i386
以此類推查詢,看系統是否缺少某一套件

安裝套件Ex: 1. 原始檔安裝 libxml package
 下載網址 ftp://xmlsoft.org/ 

# tar zxvf libxml2-2.7.2.tar.gz
# cd libxml2-2.7.2
#./configure
# make && make install

 2. yum安裝 libxml2  package
# yum install –y  libxml2-devel.*
3. rpm安裝 libxml2  package
網址: http://www.rpmfind.net/linux/rpm2html
# rpm –ivh libxml2-2.7.2-1.fc10.i386.rpm

安裝Apache2下載網址 http://httpd.apache.org/download.cgi

解壓縮/編譯 Apache2# tar jxvf httpd-2.2.15.tar.bz2
# cd cd httpd-2.2.15
# ./configure --prefix=/usr/local/apache2 --enable-so --enable-ssl=static --enable-mods-shared=all --enable-modules=most --with-mpm=worker
# make && make install

編輯配置httpd.conf檔案# vi /usr/local/apache2/conf/httpd.conf
User apache   //Apache 的使用者及群組
Group apache
ServerAdmin darwin@catchlink.com  //管理E-mail位址
ServerName  192.168.1.246:80 //伺服器位址:80

<IfModule dir_module>
    DirectoryIndex index.html index.php index.php3 index.htm
</IfModule>

啟動apache2 # /usr/local/apache2/bin/apachectl start  //啟動Apache2
# ps -ef |grep httpd
root      4734     1  0 10:43 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
apache    4735  4734  0 10:43 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
apache    4736  4734  0 10:43 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
apache    4739  4734  0 10:43 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
apache    4743  4734  0 10:43 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
apache    4822  4734  0 10:43 ?        00:00:00 /usr/local/apache2/bin/httpd -k start


測試網頁 http://webserver IP/index.html


                                                                        出現 It Work!代表成功了

# /usr/local/apache2/bin/apachectl stop   //Apach2停止

調整Apache效能
編輯httpd-default檔案
# vi /usr/local/apache2/conf/extra/httpd-default.conf
內容如下
Timeout 60
KeepAlive On
MaxKeepAliveRequests 800
KeepAliveTimeout 5
HostnameLookups Off


編輯httpd-mpm檔案
bash-3.00# vi /usr/local/apache2/conf/extra/httpd-mpm.conf
內容如下
<IfModule mpm_worker_module>
    StartServers          2
    MaxClients          800
    MinSpareThreads      25
    MaxSpareThreads      100
    ThreadsPerChild      50
    MaxRequestsPerChild  100
</IfModule>

修改httpd.conf檔案#vi /usr/local/apache2/conf/httpd.conf
將httpd-mpm.conf及httpd-default註解取消 , 沒有此2行的就自行加入
Include conf/extra/httpd-mpm.conf
Include conf/extra/httpd-default.conf

自動啟動和關閉Apache Server# ln –s /usr/local/apache2/bin/apachectl  /etc/rc3.d/S85httpd
# ln –s /usr/local/apache2/bin/apachectl  /etc/rc0.d/K85httpd
# ln –s /usr/local/apache2/bin/apachectl  /etc/rc1.d/K85httpd
# ln -s /usr/local/apache2/bin/apachectl  /etc/rc2.d/K85httpd


安裝MySQL5
下載網址 http://dev.mysql.com/downloads/

新增mysql使用者及群組# groupadd mysql
# useradd –g mysql mysql

解壓縮/編譯 MYSQL5.1.44# tar zxvf mysql-5.1.44.tar.gz
# cd mysql-5.1.44
# ./configure --prefix=/usr/local/mysql5

安裝 mysql5.1.44# make && make install
# /usr/local/mysql5/bin/mysql_install_db  --user=mysql
# cp /usr/local/mysq5/share/mysql/my-medium.cnf /etc/my.cnf
# cp /usr/local/mysq5/share/mysql/mysql.server /etc/init.d/mysqld
# chown -R mysql:mysql /usr/local/mysql5
# /usr/local/mysql5/bin/mysqld_safe  --user= mysql  &
# export PATH=$PATH:/usr/local/mysql5/bin
# export LD_LIBRARY_PATH=/usr/local/mysql5/lib:/lib:/usr/local/lib:/var/lib

查看mysql Mysql預設使用的Port是3306
# netstat -na | grep 3306
      *.3306               *.*                0      0 49152      0 LISTEN

設定 MySQL 的 root user密碼  # cd /usr/local/mysql5/bin/
# ./mysqladmin -u root password gh8Q6prt
# ./mysqladmin -u root -h `hostname` password 'new-password' –p

測試 MySQL Server# mysqladmin version -p
Enter password:     //輸入剛加入的root 密碼

[root@dns local]# mysqladmin version -p
Enter password:
mysqladmin  Ver 8.42 Distrib 5.1.44, for pc-linux-gnu on i686
Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license

Server version          5.1.44-log
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /tmp/mysql.sock
Uptime:                 6 min 7 sec

Threads: 1  Questions: 9  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 0.24

如出現上面的有關mysql5相關資訊 , 則表示安裝成功!

查看mysql 內所有資料庫
 # ./mysqlshow -p
 Enter password:   輸入root 密碼
+--------------------+
|     Databases         |
+--------------------+
| information_schema |
| mysql                       |
| test                           |
+----------------------+

進入 mysql 模式# mysql -uroot -p
Enter password:   //輸入root 密碼
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.1.44-log Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database               |
+--------------------+
| information_schema |
| mysql                       |
| test                           |
+----------------------+
3 rows in set (0.00 sec)
mysql>
3 rows in set (0.00 sec)
mysql> quit;
Bye

自動啟動和關閉MySQL Server# chkconfig --add mysqld
# service mysqld restart
# chkconfig mysqld on

PHP5下載網址 http://www.php.net/
#  tar jxvf php-5.2.13.tar.bz2
#  cd php-5.2.13

編譯及安裝php # ./configure  --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs
--with-mysql=/usr/local/mysql5 –with-gd –with-zlib-dir
# make && make install

將php.ini設定檔copy至/usr/local/php5/lib目錄內
#cp php.ini-dist /usr/local/php5/lib/php.ini

安裝php 模組#pear install –f  Image_Color
#pear install –f  Numbers_Roman
#pear install –f  Numbers_Words
#pear install –f  Image_Canvas-alpha
#pear install –f  Image_Graph-0.3.0dev4.tgz
#pear install –f  Mail
#pear install –f  Mail-Mime

編輯Apache 設定檔 , 讓Apache可以看得懂PHP Script 並使PHP模組去解析它們
# vi /usr/local/apache2/conf/httpd.conf

檢查所下, 如沒有自行加入
DirectoryIndex index.html index.php index.php3 index.phtml
LoadModule php5_module        modules/libphp5.so
AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php .php .phtml

測試php5 module的方法# cd /usr/local/apache2/htdocs
# vi info.php
<?
phpinfo();
?>

打開IE測試:http://192.168.1.254/info.php

重啟動 Apache2 # usr/local/apache2/bin/apachectl restart //重新啟動Apache2

安裝 phpMyAdmin下載網址 http://www.phpmyadmin.net/

解壓縮phpMyAdmin#tar jxvf phpMyAdmin-3.3.0-all-languages.tar.bz2
# mv phpMyAdmin-3.3.0-all-languages /usr/local/apache2/htdocs/phpMyAdmin


打開瀏覽器



 
http://192.168.1.254/phpMyAdmin/

沒有留言:

張貼留言