Linux 下安裝 Apache 2.0.x + PHP 5 + MySQL 4.1.x

文章位置: 主頁 > 文章資料庫 > PHP 教學 > PHP 安裝 > Linux 下安裝 Apache 2.0.x + PHP 5 + MySQL 4.1.x
瀏覽次數: 13310
更新時間: 2005/05/11 18:53

概論

本文將會介紹在 Linux 下建構 Apache 2.0.x + PHP 5 + MySQL 4.1.x 的執行環境。而測試平台為 Fedora Core 3。因為本文介紹的方法是直接編譯 Source Code,而不是使用 RPM 檔,所以一般上在其他 Unix Like 環境下也能使用。

下載檔案

在開始安裝時請先下載以下軟體:

Apache 2.0.x: http://httpd.apache.org/download.cgi
PHP 5: http://www.php.net/downloads.php
MySQL 4.1.x: http://dev.mysql.com/get/Downloads/MySQL-4.1/mysql-standard-4.1.11-pc-linux-gnu-i686.tar.gz/from/pick


MySQL 安裝

為了較方法建構 PHP,所以先安裝 MySQL。首先用 "su -" 進入 root,然後 cd 到儲存以上檔案的目錄,並輸入以下指令,請留意,請將以下的 mysql-VERSION-OS 換成你的實際檔名:

安裝 MySQL:
shell> groupadd mysql
shell> useradd -g mysql mysql
shell> tar zxvf mysql-VERSION-OS.tar.gz
shell> mv mysql-VERSION-OS /usr/local/mysql
shell> cd /usr/local/mysql
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> chgrp -R mysql .
shell> cp bin/* /usr/bin/
shell> cp support-files/mysql.server /etc/rc.d/init.d/mysqld
shell> bin/mysqld_safe --user=mysql &


修改預設 root 密碼,以下的 newpwd 是新的密碼,請自行修改:
shell> mysql -u root
mysql> UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
mysql> FLUSH PRIVILEGES;



Apache 安裝

安裝好 MySQL 後,下一步就是 Apache,正如以上一樣,su 到 root 及 cd 到儲存 Apache 的目錄,輸入以下指令:

請修改以下的檔案名為成實際檔案名:
shell> tar zxvf httpd-2_0_NN.tar.gz
shell> cd httpd-2_0_NN
shell> ./configure --enable-so
shell> make
shell> make install
shell> cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd


測試是否安裝正確:
shell> /etc/rc.d/init.d/httpd start


打開瀏覽器到 http://localhost 看看是否看到 Apache 的預設版面,看到的話就表示安裝成功。


PHP 安裝

安裝 PHP 也跟以上大同小異,但要注意的是如要安裝特定模組,需先安裝特定的套件,例如安裝 GD 的話,需先有安裝 libjpeg, libpng 等函式庫。

以下例子會編譯 PHP 支援 mysql 4.1.x,請將 php-NN 換成實際的檔案:
shell> tar zxvf php-NN.tar.gz
shell> cd php-NN
shell> ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysqli=/usr/local/mysql/bin/mysql_config
shell> make
shell> make install
shell> cp php.ini-dist /usr/local/lib/php.ini
shell> /etc/rc.d/init.d/httpd restart


然後打開 /usr/local/apache2/conf/httpd.conf,加入以下 3 行:

LoadModule php5_module libexec/libphp5.so
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps

為了讓 index.php 可以當成首頁執行,在 DirectoryIndex 選項加入 index.php,最後在 /usr/local/apache2/htdocs/ 建立一個 info.php 的檔案,內容如下:

01 <?php
02
echo phpinfo();
03
?>


然後打開瀏覽器到 /http://localhost/info.php 看看是否見到 phpinfo 的介面,見到的話就表示大功告成了。

注意事項: 如果你的 MySQL 版本是 4.0.x 或以下,以上 PHP 的編譯當中需要將 --with-mysqli 改成 --with-mysql。


自動開啟服務

最後便要設定每次開機均會自動開啟 Apache 及 MySQL。因為不同的系統有不同的配置方法,例如 FreeBSD 需要將 startup scripts 放置在 /usr/local/etc/rc.d/ 內,而 Fedora Core 3 可以使用 ntsysv 或 chkconfig 指令。


總結

以上是建構 PHP + MySQL 執行環境的最基本步驟,日後會寫多一點關於建構 PHP 執行環境的文章,例如在 Windows 內安裝相信很多人有興趣。


====================================================
歡迎轉載,但轉載時請保留此宣告,不得作為商業用途
作者: Sam Tang <admin{at}phpini{dot}com>
來源網站: http://www.phpdc.com/


用戶評論 按這裡發表新評論 
CHAOYUAN user at yourdomain dat com
22 November 2005 09:43
很有幫助的文章, 謝謝!!
 
gygptjjjhzx zddzki at kqlfpw dat com
13 May 2008 07:24
5jK8wu <a href="http://kbkluichkrri.com/">kbkluichkrri</a>, [url=http://zehkyzudqkeu.com/]zehkyzudqkeu[/url], [link=http://qkwcnwmioogk.com/]qkwcnwmioogk[/link], http://yhawguwluawr.com/
 
Michael i-van2000 at mail dat ru
11 May 2008 11:46
<a href=http://thongs.weebly.com/my-girlfriends.html>Topless girlfriends</a> [url=http://thongs.weebly.com/my-girlfriends.html]My girlfriend topless[/url]
 
obsestoxips uttellovectex at yahoo dat com
11 May 2008 00:24
upsepurse <a href=http://google.com>google</a> http://google.com
Addelayjainny
 
obsestoxips uttellovectex at yahoo dat com
10 May 2008 22:38
upsepurse <a href=http://google.com>google</a> http://google.com
Addelayjainny
 
streep poker on line xcd5I5ed7 at msn dat com
09 May 2008 11:06
[url=http://membres.lycos.fr/spacer1/poker-game-online.html]poker game online[/url] http://membres.lycos.fr/spacer1/poker-game-online.html <a href=http://membres.lycos.fr/spacer1/poker-game-online.html>poker game online</a> <a href=http://membres.lycos.fr/balrog1/jeu-poker-texas-holdem-gratuites.html>jeu poker texas holdem gratuites</a> [url=http://membres.lycos.fr/balrog1/jeu-poker-texas-holdem-gratuites.html]jeu poker texas holdem gratuites[/url] http://membres.lycos.fr/balrog1/jeu-poker-texas-holdem-gratuites.html [url=http://membres.lycos.fr/spacer1/meilleur-poker-en-ligne.html]meilleur poker en ligne[/url] <a href=http://membres.lycos.fr/spacer1/meilleur-poker-en-ligne.html>meilleur poker en ligne</a> http://membres.lycos.fr/spacer1/meilleur-poker-en-ligne.html http://membres.lycos.fr/balrog1/poker-machine-gratuites.html <a href=http://membres.lycos.fr/balrog1/poker-machine-gratuites.html>poker machine gratuites</a> [url=http://membres.lycos.fr/balrog1/poker-machine-gratuites.html]poker machine gratuites[/url] http://membres.lycos.fr/balrog1/regle-du-poker-texas-holdem.html [url=http://membres.lycos.fr/balrog1/regle-du-poker-texas-holdem.html]regle du poker texas holdem[/url] <a href=http://membres.lycos.fr/balrog1/regle-du-poker-texas-holdem.html>regle du poker texas holdem</a>
 
 
 發表評論
姓名:
Email:
內容: