|
Daniel Cheng
鄭文軒
2006/01/19 Ver01
LAMP 安裝 For RedHat9.0
前言:由於公司的那台伺服器 的 SCSI卡是 Adaptec的,因為原廠的驅動只有支援RedHat9.0以前版本,所以小弟便選用了RedHat9.0 2.4 Kernel的來進行安裝。
硬體環境
Xeon 2.4*2
1G RAM
IBM 15000RPM SCSI HDD 73GB*4
系統環境
RedHat 9.0
Kernel 2.4.20-8smp
Apache 2.0.55
PHP 5.1.1
MYSQL 4.1.16
GD 2.0.33
Freetype 2.1.10
Jpeg jpegv6b
Libpng 1.2.8
Libxml 2.6.22
Zlib 1.2.3
下載聯結
Apache 下載
http://apache.stu.edu.tw/httpd/httpd-2.0.55.tar.gz
MySQL 下載http://dev.mysql.com/get/Downloads/MySQL-4.1/mysql-4.1.16.tar.gz/from/http://mysql.cs.pu.edu.tw/
PHP 下載
http://tw2.php.net/get/php-5.1.1.tar.gz/from/tw.php.net/mirror
GD 下載
http://www.boutell.com/gd/http/gd-2.0.33.tar.gz
Jpeg 下載
ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz
libpng 下載
http://nchc.dl.sourceforge.net/sourceforge/libpng/libpng-1.2.8.tar.gz
Zlib 下載
http://keihanna.dl.sourceforge.net/sourceforge/libpng/zlib-1.2.3.tar.gz
FreeType 下載
http://jaist.dl.sourceforge.net/sourceforge/freetype/freetype-2.1.10.tar.gz
libxml 下載
http://xmlsoft.org/sources/libxml2-2.6.22.tar.gz
為什麼除了下載httpd,PHP,MySQL之外還要下載這麼多東西,因為 在PHP的語言有一個函式庫叫GD,程式者通常都會使用這些函式庫,為了方便 在安裝時統一編譯進去。
至於 libxml是因為PHP5 要求的libxml 版本 2.5.6 以上,Redhat 9 的 libxml RPM 套件最新版本也只到 libxml2-2.5.4,所以我們重新編譯一個 libxml這樣子才可以使用PHP5
實作開始
前言:通常在目錄的使用上,都會將TarBall解開來的檔案放在/usr/local/src/底下
然後會將程式安裝在/usr/local/底下,以下將會依照這些規則進行編譯
1. MySQL
cd /usr/local/src
tar zvxf mysql-4.1.16.tar.gz
cd mysql-4.1.16
./configure --prefix=/usr/local/mysql --with-zlib-dir=/usr --with-charset=big5 --sysconfdir=/etc --localstatedir=/var/mysql
./configure –help 查看 MakeFile參數說明
--prefix=/usr/local/mysql 設定MySQL安裝位置
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local]
--with-charset=big5是使mysql支持中文查詢
--with-charset=CHARSET
Default character set, use one of:
binary
armscii8 ascii big5 cp1250 cp1251 cp1256 cp1257
cp850 cp852 cp866 cp932 dec8 euckr gb2312 gbk geostd8
greek hebrew hp8 keybcs2 koi8r koi8u
latin1 latin2 latin5 latin7 macce macroman
sjis swe7 tis620 ucs2 ujis utf8
--with-zlib-dir=設定zlib的位置。(本次編譯位置為系統原有的zlib.h檔,非自行編譯的,自行編譯的位置於/usr/local)
--with-zlib-dir=DIR Provide MySQL with a custom location of compression
library. Given DIR, zlib library is assumed to be in
$DIR/lib and header files in $DIR/include. Specify
"bundled" to use bundled zlib.
make
make install
然後初始化數據庫:
/usr/local/mysql/bin/mysql_install_db
新增使用者:
groupadd -g 27 mysql
useradd -u 27 -g mysql -d /var/mysql/ -s /sbin/nologin mysql
設置權限:
chown -R root.mysql /usr/local/mysql
chown -R mysql.mysql /var/mysql
複製配置文件:
cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
複製啟動文件:
cp /usr/local/mysql/share/mysql/mysql.server /usr/local/mysql/share/mysql/mysqld
chmod a+x /usr/local/mysql/share/mysql/mysqld
啟動mysql:
/usr/local/mysql/share/mysql/mysqld start
修改密碼:初始的root密碼是空的
/usr/local/mysql/bin/mysqladmin -u root -p password [需要的密碼]
enter password:
把密碼修改為[需要的密碼],由於初始密碼為空,所以enter password直接Enter就好
測試一下新的密碼:
/usr/local/mysql/bin/mysql -u root -p
enter password:[需要的密碼]
如果順利的話就能進入mysql。
2. Zlib
cd /usr/local/src/
tar zxvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure
make
make install
3. libpng
cd /usr/local/src/
tar zxvf libpng-1.2.8.tar.tar
cd libpng-1.2.8
cp scripts/makefile.linux makefile
make
make install
注意,這裡的makefile不是用./configure生成,而是直接從scripts/裡拷一個
4. Freetype
cd /usr/local/src/
tar zxvf freetype-2.1.10.tar.gz
cd freetype-2.1.10
./configure
make
make install
5. Jpeg
會出一點小問題請先建立一個目錄
mkdir /usr/local/man/man1
cd /usr/local/src/
tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b/
./configure --enable-shared
--enable-shared build shared library using GNU libtool
make
make test
make install
注意,這裡configure一定要帶--enable-shared參數,不然,不會生成共享庫
6. GD
cd /usr/local/src/
tar zxvf gd-2.0.33.tar.gz
cd gd-2.0.33
./configure --with-png --with-freetype --with-jpeg
--with-png=DIR where to find the png library
--with-freetype=DIR where to find the freetype 2.x library
--with-jpeg=DIR where to find the jpeg library
make
make install
7. httpd
cd /usr/local/src/
tar zvxf httpd-2.0.55.tar.gz
cd httpd-2.0.55
/configure --prefix=/usr/local/apache2 --enable-so \
--enable-mods-shared=most
--prefix=PREFIX install architecture-independent files in PREFIX [/usr/local/apache2]
--enable-so DSO capability
--enable-mods-shared=MODULE-LIST Shared modules to enable
make
make install
8. libxml
cd /usr/local/src/
tar zvxf cd libxml2-2.6.22.tar.gz
cd libxml2-2.6.22
./configure --enable-xml --with-dom=/usr/local/include/libxml2 --with-dom-xslt=/usr/local/include/libxsl --with-libxml-dir=/usr/local/include/libxml
(備註:筆者在查看 MakeFile的說明檔,並沒有發現下列三個參數,在這邊做個註記,下次可以實驗不加參數)
9. PHP
cd /usr/local/src/
tar zvxf cd php-5.1.1.tar.gz
cd php-5.1.1
Ø ./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql/
--with-apache2=/usr/local/httpd/--enable-bcmath --with-zlib --with-gd --with-jpeg-dir
--enable-gd-native-ttf --with-ttf --with-freetype-dir --with-pear --enable-mbstring=tw enable-ftp
--with-iconv --with-apxs2=/usr/local/httpd/bin/apxs
Ø ./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql/ --with-apxs2=/usr/local/httpd/bin/apxs
--with-config-file-path=/usr/local/php5 --enable-bcmath --with-zlib-dir=/usr/local/lib/
--with-gd-dir=/usr/local/lib/ --with-jpeg-dir=/usr/local/lib/ --with-ttf --with-freetype-dir=/usr/local/lib/
--enable-mbstring=tw --enable-ftp --with-iconv
Ø ./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql/
--with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php5
--enable-bcmath --with-zlib --with-gd --with-jpeg --with-ttf --with-freetype
--enable-mbstring --enable-ftp --with-iconv --with-regex=php
(備註:筆者在測試的時候,是了三次參數,最後是最後面的不加DIR,達到所有功能,在這邊做完整紀錄,下次可以直接使用第三個參數進行編譯。)
--prefix=PREFIX install architecture-independent files in PREFIX [/usr/local]
--with-mysql[=DIR] Include MySQL support. DIR is the MySQL base directory
--with-apxs2[=FILE] Build shared Apache 2.0 Handler module. FILE is the optional
--with-config-file-path=PATH Set the path in which to look for php.ini [PREFIX/lib]
--enable-bcmath Enable bc style precision math functions
--with-zlib[=DIR] Include ZLIB support (requires zlib >= 1.0.9)
--with-gd[=DIR] Include GD support where DIR is GD install prefix.
If DIR is not set, the bundled GD library will be used
--with-jpeg-dir[=DIR] GD: Set the path to libjpeg install prefix
--with-ttf[=DIR] GD: Include FreeType 1.x support
--with-freetype-dir[=DIR] GD: Set the path to FreeType 2 install prefix
--enable-mbstring Enable multibyte string support
--enable-ftp Enable FTP support
--with-iconv-dir=DIR XMLRPC-EPI: iconv dir for XMLRPC-EPI
--with-regex=TYPE regex library type: system, apache, php. [TYPE=php]
WARNING: Do NOT use unless you know what you are doing
make
make install
轉存 PHP 基本組態檔案:
[root@test php-4.3.3]# cp php.ini-dist /usr/local/php4/php.ini
# 這個路徑與你剛剛在 ./configure 當中那個 --with-config-file-path 設定有關!
(備註: php.ini-dist 跟 php.ini-recommended 的不同 )
根據 php.ini-dist 的說明,二者不同之處在於 php.ini-dist 適合開發程式使用,而 php.ini-recommended 擁有較高的安全性設定,則適合上線當產品使用。
原文說明如下:
This is the default settings file for new PHP installations.
By default, PHP installs itself with a configuration suitable for
development purposes, and *NOT* for production purposes.
For several security-oriented considerations that should be taken
before going online with your site, please consult php.ini-recommended
and http://php.net/manual/en/security.php.
加入Mbstring模組
vi /usr/local/php5/php.ini
在大約563行地方加入 extension=php_mbstring.so
重新啟動Apache,就可以看到支援 mbstring
由於在編譯完成後會出現下面這行
Installing PEAR environment: /usr/local/php5/lib/php/
[PEAR] Archive_Tar - installed: 1.3.1
[PEAR] Console_Getopt - installed: 1.2
pear/PEAR can optionally use package "pear/XML_RPC" (version >= 1.4.0)
[PEAR] PEAR - installed: 1.4.5
Wrote PEAR system config file at: /usr/local/php5/etc/pear.conf
You may want to add: /usr/local/php5/lib/php to your php.ini include_path
Installing PDO headers: /usr/local/php5/include/php/ext/pdo/
所以在大概440行的地方會看到 Paths and directories
加入include_path ="/usr/local/php5/include/php/ext/pdo/:/usr/local/php5/lib/php"
至於加入這行有什麼意義,筆者不是Programing所以無法得知。
由於本次安裝在apache的設定檔發現已經加入php5的模組了,但是還是將做法寫入,可做檢查使用
vi /usr/local/apache2/conf/httpd.conf
大概在262行加入
LoadModule php5_module modules/libphp5.so
大概在424行加入
DirectoryIndex index.html index.html.var index.php index.htm
(備註:這邊為支援預設首頁的部份)
大概867行加入
AddType application/x-httpd-php .php
測試功能
接下來 測試php是否可以正常開啟
cd /usr/local/apache2/htdoc/
vi test.php
在裡面打入
<?php
phpinfo( );
?>
然後存檔
開啟瀏覽器打入網址及檔案名 |
|