本文講了從源碼簡單的安裝apache+mysql+php+phpMyAdmin 安裝步驟我們基本安裝源碼本身提供的安裝文檔來。
安裝過程中 出現缺少其他軟體包的情況 我們將使用yum安裝 如果你的RHEL未付費無法使用yum 請配置CentOS的yum源 或者下載rpm包安裝
安裝之前 防火牆與selinux均設定無效。
本文測試環境RHEL5.5 同樣適合於CentOS5.5。
本文適合新手學習安裝 不適合生產環境。
1.下載軟體
[root@RHEL src]# cd /usr/local/src/<br />[root@RHEL src]# wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.50.tar.gz/from/http://ftp.iij.ad.jp/pub/db/mysql/<br />[root@RHEL src]# wget http://jp.php.net/get/php-5.2.14.tar.bz2/from/this/mirror<br />[root@RHEL src]# wget http://ftp.riken.jp/net/apache//httpd/httpd-2.2.16.tar.gz<br />[root@RHEL src]# wget http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.3.7/phpMyAdmin-3.3.7-all-languages.tar.bz2
2.安裝配置mysql
2.1.編譯安裝<br />[root@RHEL src]# tar -xzvf mysql-5.1.50.tar.gz<br />[root@RHEL src]# cd mysql-5.1.50<br />[root@RHEL mysql-5.1.50]# more INSTALL-SOURCE<br />2.3.1. Source Installation Overview<br />The basic commands that you must execute to install a MySQL source<br />distribution are:<br />shell> groupadd mysql<br />shell> useradd -g mysql mysql (一會我們修改一下 不讓mysql使用者能登入系統)<br />shell> gunzip < mysql-VERSION.tar.gz | tar -xvf - (我已經解壓了 這步省略)<br />shell> cd mysql-VERSION (我們已經進入解壓目錄了)<br />shell> ./configure --prefix=/usr/local/mysql<br />shell> make<br />shell> make install<br />shell> cp support-files/my-medium.cnf /etc/my.cnf<br />shell> cd /usr/local/mysql<br />shell> chown -R mysql .<br />shell> chgrp -R mysql .<br />shell> bin/mysql_install_db --user=mysql<br />shell> chown -R root .<br />shell> chown -R mysql var<br />shell> bin/mysqld_safe --user=mysql &<br />[root@RHEL mysql-5.1.50]# groupadd mysql<br />[root@RHEL mysql-5.1.50]# useradd -g mysql -s /bin/false mysql<br />[root@RHEL mysql-5.1.50]# ./configure --prefix=/usr/local/mysql<br />......<br />checking for termcap functions library... configure: error: No curses/termcap library found<br />......<br />OOPS!出錯了!<br />[root@RHEL mysql-5.1.50]# yum -y install ncurses-devel<br />(rpmhttp://ftp.sjtu.edu.cn/centos/5.5/os/i386/CentOS/ncurses-devel-5.5-24.20060715.i386.rpm)<br />[root@RHEL mysql-5.1.50]# ./configure --prefix=/usr/local/mysql<br />[root@RHEL mysql-5.1.50]# make<br />[root@RHEL mysql-5.1.50]# make install<br />[root@RHEL mysql-5.1.50]# cd /usr/local/mysql<br />[root@RHEL mysql]# chown -R mysql .<br />[root@RHEL mysql]# chgrp -R mysql .<br />[root@RHEL mysql]# bin/mysql_install_db --user=mysql<br />[root@RHEL mysql]# chown -R root .<br />[root@RHEL mysql]# chown -R mysql var<br />[root@RHEL mysql]# bin/mysqld_safe --user=mysql &<br />2.2.確認mysql狀態 並修改密碼<br />[root@RHEL mysql]# ps -ef | grep mysql<br />[root@RHEL mysql]# /usr/local/mysql/bin/mysqladmin -u root password 'mysql'<br />[root@RHEL mysql]# /usr/local/mysql/bin/mysql -uroot -p<br />Enter password:<br />Welcome to the MySQL monitor. Commands end with ; or /g.<br />Your MySQL connection id is 2<br />Server version: 5.1.50 Source distribution<br />Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.<br />This software comes with ABSOLUTELY NO WARRANTY. This is free software,<br />and you are welcome to modify and redistribute it under the GPL v2 license<br />Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.<br />mysql><br />2.3.使用官方提供的啟動指令碼並添加開機啟動<br />[root@RHEL mysql]# cp share/mysql/mysql.server /etc/init.d/mysqld<br />[root@RHEL mysql]# /etc/init.d/mysqld stop<br />Shutting down MySQL100909 20:06:48 mysqld_safe mysqld from pid file /usr/local/mysql/var/RHEL.pid ended<br /> [確定]<br />[1]+ Done bin/mysqld_safe --user=mysql<br />[root@RHEL mysql]# /etc/init.d/mysqld start<br />Starting MySQL. [確定]<br />[root@RHEL mysql]# /sbin/chkconfig --add mysqld<br />[root@RHEL mysql]# /sbin/chkconfig mysqld on
3.安裝apache2.2
3.1.編譯安裝<br />[root@RHEL mysql]# cd /usr/local/src/<br />[root@RHEL src]# tar -xzvf httpd-2.2.16.tar.gz<br />[root@RHEL src]# cd httpd-2.2.16<br />[root@RHEL httpd-2.2.16]# more INSTALL<br />Quick Start - Unix<br /> ------------------<br /> For complete installation documentation, see [ht]docs/manual/install.html or</p><p>http://httpd.apache.org/docs/2.2/install.html</p><p> $ ./configure --prefix=PREFIX<br /> $ make<br /> $ make install<br /> $ PREFIX/bin/apachectl start<br /> NOTES: * Replace PREFIX with the filesystem path under which<br /> Apache should be installed. A typical installation<br /> might use "/usr/local/apache2" for PREFIX (without the<br /> quotes).<br />*在他說的最簡單的安裝方式上 我們加2個編譯參數<br />*--enable-rewrite rule based URL manipulation<br />*--enable-so DSO capability<br />[root@RHEL httpd-2.2.16]# ./configure --prefix=/usr/local/apache2 --enable-rewrite --enable-so<br />[root@RHEL httpd-2.2.16]# make<br />[root@RHEL httpd-2.2.16]# make install<br />3.2.建立apache專用使用者<br />[root@RHEL httpd-2.2.16]# groupadd apache<br />[root@RHEL httpd-2.2.16]# useradd -g apache -M -s /sbin/nologin apache<br />[root@RHEL httpd-2.2.16]# vi /usr/local/apache2/conf/httpd.conf<br />找到如下2句 並在行頭加#號注釋掉<br />User daemon<br />Group daemon<br /> 追加如下2句<br />User apache<br />Group apache<br />3.3.啟動狀態確認<br />[root@RHEL httpd-2.2.16]# /usr/local/apache2/bin/apachectl start<br />[root@RHEL httpd-2.2.16]# lsof -i:80<br />[root@RHEL httpd-2.2.16]# lsof -i:80<br />COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME<br />httpd 14125 root 3u IPv6 194322 TCP *:http (LISTEN)<br />httpd 14354 apache 3u IPv6 194322 TCP *:http (LISTEN)<br />httpd 14355 apache 3u IPv6 194322 TCP *:http (LISTEN)<br />httpd 14356 apache 3u IPv6 194322 TCP *:http (LISTEN)<br />httpd 14357 apache 3u IPv6 194322 TCP *:http (LISTEN)<br />httpd 14358 apache 3u IPv6 194322 TCP *:http (LISTEN)<br />[root@RHEL httpd-2.2.16]# curl http://localhost (你可以在瀏覽器裡輸入http://ip測試)<br /><html><body><h1>It works!</h1></body></html>
*通過apachectl就可以方便的啟動關閉apache了 我就不做啟動指令碼了
*如果你需要你可以上網搜一下 或者參照/etc/init.d/下的其他指令碼 在apachectl的基礎上修改一個
*或者 你可以再/etc/rc.local裡追加一句來讓apache開機啟動/usr/local/apache2/bin/apachectl start
4.源碼編譯安裝php
4.1.編譯安裝<br />root@RHEL httpd-2.2.16]# cd /usr/local/src/<br />[root@RHEL src]# tar -jxvf php-5.2.14.tar.bz2<br />[root@RHEL src]# cd php-5.2.14<br />[root@RHEL php-5.2.14]# more INSTALL<br />Apache 2.0 on Unix systems<br /> ·.......<br /> You are highly encouraged to take a look at the Apache Documentation to<br /> get a basic understanding of the Apache 2.0 Server.<br /> ......<br /> Example 2-4. Installation Instructions (Apache 2 Shared Module Version)<br />1. gzip -d httpd-2_0_NN.tar.gz<br />2. tar xvf httpd-2_0_NN.tar<br />3. gunzip php-NN.tar.gz<br />4. tar -xvf php-NN.tar<br />5. cd httpd-2_0_NN<br />6. ./configure --enable-so<br />7. make<br />8. make install<br />Now you have Apache 2.0.NN available under /usr/local/apache2,<br />configured with loadable module support and the standard MPM prefork.<br />To test the installation use your normal procedure for starting<br />the Apache server, e.g.:<br />/usr/local/apache2/bin/apachectl start<br />and stop the server to go on with the configuration for PHP:<br />/usr/local/apache2/bin/apachectl stop.<br />9. cd ../php-NN<br />10. ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql (一會我們指定一下mysql的安裝路徑)<br />11. make<br />12. make install<br />.......<br />13. Setup your php.ini<br />cp php.ini-dist /usr/local/lib/php.ini<br />.......<br />14. Edit your httpd.conf to load the PHP module.<br />......<br />For PHP 5:<br /> LoadModule php5_module modules/libphp5.so<br />15. Tell Apache to parse certain extensions as PHP.<br />......<br /> AddType application/x-httpd-php .php .phtml<br />It's also common to setup the .phps extension to show highlighted PHP<br />source, this can be done with:<br /> AddType application/x-httpd-php-source .phps<br />16. Use your normal procedure for starting the Apache server, e.g.:<br /> /usr/local/apache2/bin/apachectl start<br />......<br />[root@RHEL php-5.2.14]# ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql<br />......<br />configure: error: xml2-config not found. Please check your libxml2 installation.<br />......<br />OOPS!出錯了!<br />[root@RHEL php-5.2.14]# yum -y install libxml2-devel<br />(我的情況 安裝libxml2-devel的時候 依賴於zlib-devel)<br /> (rpm http://ftp.sjtu.edu.cn/centos/5.5/os/i386/CentOS/zlib-devel-1.2.3-3.i386.rpm)<br /> (rpm http://ftp.sjtu.edu.cn/centos/5.5/os/i386/CentOS/libxml2-devel-2.6.26-2.1.2.8.i386.rpm)<br />[root@RHEL php-5.2.14]# ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql<br />[root@RHEL php-5.2.14]# make<br />[root@RHEL php-5.2.14]# make install<br />[root@RHEL php-5.2.14]# cp php.ini-dist /usr/local/lib/php.ini<br />[root@RHEL php-5.2.14]# vi /usr/local/apache2/conf/httpd.conf<br />在內容裡搜一下是否有libphp5.so<br />我的情況 已經有了 如果沒有追加下面那句前面不帶#的<br /># LoadModule foo_module modules/mod_foo.so<br />LoadModule php5_module modules/libphp5.so<br />#<br />再搜尋AddType關鍵字 在那附近追加如下一句<br />AddType application/x-httpd-php .php .phtml<br />再搜尋下面一段 把第二句DirectoryIndex的後面追加index.php<br /><IfModule dir_module><br /> DirectoryIndex index.html index.php<br /></IfModule><br />4.1.2測試php網頁<br />[root@RHEL php-5.2.14]# cd /usr/local/apache2/htdocs/<br />[root@RHEL htdocs]# vi index.php<br />輸入內容<br /><?php<br />phpinfo();<br />?><br />[root@RHEL php-5.2.14]# /usr/local/apache2/bin/apachectl restart<br />[root@RHEL mysql]# curl -I http://localhost/index.php<br />或者你在你的瀏覽器裡輸入http://yourip/index.php<br />4.1.3測試php和mysql串連<br />[root@RHEL htdocs]# vi phpmysql.php<br />輸入內容<br /><?php<br /> mysql_connect("localhost","root","mysql") or die("MySQL First Test:Failed");<br /> echo "MySQL First Test:Success";<br />?><br />因為我們編譯php的時候沒有加--with-mysqli選項 所以不支援mysqli擴充<br />[root@RHEL htdocs]# curl http://localhost/phpmysql.php<br />MySQL First Test:Success<br />好了 我這裡成功了<br />你可以再瀏覽器裡輸入http://ip/phpmysql.php
5.安裝配置phpMyAdmin
5.1.配置phpMyAdmin<br />[root@RHEL mysql]# cd /usr/local/src/<br />[root@RHEL src]# tar -jxvf phpMyAdmin-3.3.7-all-languages.tar.bz2<br />我們把phpMyAdmin配置到/var/www/下 命名為phpMyAdmin<br />[root@RHEL src]# test -d /var/www || mkdir -p /var/www<br />[root@RHEL src]# mv phpMyAdmin-3.3.7-all-languages /var/www/phpMyAdmin<br />[root@RHEL src]# cp /var/www/phpMyAdmin/config.sample.inc.php /var/www/phpMyAdmin/config.inc.php<br />[root@RHEL src]# chmod 660 /var/www/phpMyAdmin/config.inc.php<br />[root@RHEL src]# vi /var/www/phpMyAdmin/config.inc.php<br />追加$cfg['Lang'] = 'zh-utf-8';<br />----------可選設定 為phpMyAdmin設定50位的短語密碼---------<br />------推薦你設定 但是要使用mkpasswd命令 你需要安裝expect包<br />[root@RHEL src]# mkpasswd -l 50<br />clecXjgn7Hg%whkyajmmq8zisgzceinvcuqnwhbxlwapnzemwm<br />複製產生的短語密碼<br />[root@RHEL src]# vi /var/www/phpMyAdmin/config.inc.php<br /> 找到如下參數<br />$cfg['blowfish_secret'] = 'clecXjgn7Hg%whkyajmmq8zisgzceinvcuqnwhbxlwapnzemwm'<br />----------------------可選設定 結束-----------------------<br />[root@RHEL src]# chown -R root.apache /var/www/phpMyAdmin<br />[root@RHEL src]# cd /usr/local/apache2/conf/<br />[root@RHEL conf]# vi extra/phpmyadmin.conf<br />加入內容<br />Alias /phpMyAdmin /var/www/phpMyAdmin<br /><Location /phpMyAdmin><br />Order deny,allow<br />Deny from all<br />Allow from 127.0.0.1<br />Allow from 10.110.108.55 //這裡改成你實際允許訪問的ip<br /></Location><br />[root@RHEL conf]# vi httpd.conf<br />追加<br />Include conf/extra/phpmyadmin.conf<br />[root@RHEL conf]# /usr/local/apache2/bin/apachectl restart<br />5.2.測試 在瀏覽器輸入下面的網址</p><p>http://ip/phpMyAdmin/</p><p>輸入我們前面設定的mysql使用者名稱root 和密碼mysql<br />Enjoy!
後話;因為我們安裝php的時候 加的參數比較少 所以開啟phpMyAdmin的時候會有一些警告
但是我相信讀者已經會重新編譯php來解決這些問題了吧!