一.先檢查編譯環境
[root@cms ~]# yum grouplist
需要安裝的幾組工具
Development Libraries (開發庫)
Development Tools (開發工具)
Legacy Software Development (傳統軟件開發工具)
X Software Development
二.構建編譯環境,使用yum安裝
[root@cms ~]# yum -y groupinstall "Development Libraries" "Development Tools" "Legacy Software Development"
環境構建完畢之後我們就可以編譯apache,mysql,php的源碼包。這裏我們使用mysql綠色安裝方式,所要使用到的包我們已經準備好了:
httpd-2.2.19.tar.bz2
mysql-5.5.15-linux2.6-i686.tar.gz 綠色的軟件
php-5.3.7.tar
三.安裝mysql,這裏使用綠色安裝方式,直接解壓到/usr/local重命名爲mysql下即可使用
[root@cms ~]# tar -zxvf mysql-5.5.15-linux2.6-i686.tar.gz -C /usr/local
[root@cms ~]# cd /usr/local #切換目錄
[root@cms local]# ln -s mysql-5.5.15-linux2.6-i686 mysql #爲mysql建立一個軟連接
[root@cms local]# ls #查看
bin games lib mysql sbin src
etc include libexec mysql-5.5.15-linux2.6-i686 share
[root@cms local]# cd mysql
[root@cms mysql]# less INSTALL-BINARY #參照install-binary來配置
[root@cms mysql]# groupadd mysql
[root@cms mysql]# useradd -r -g mysql mysql
[root@cms mysql]# chown -R mysql .
[root@cms mysql]# chgrp -R mysql .
[root@cms mysql]# chown -R root .
[root@cms mysql]# chown -R mysql data
[root@cms mysql]# scripts/mysql_install_db --user=mysql & #初始化數據庫
[root@cms mysql]# bin/mysqld_safe --user=mysql & #啓動mysql
[root@cms mysql]# vim /etc/profile #修改環境變量
[root@cms mysql]# . /etc/profile #重新讀取數據庫文件
[root@cms mysql]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin:/usr/local/mysql/bin
[root@cms mysql]# cd support-files/
[root@cms support-files]# cp my-large.cnf /etc/my.cnf
[root@cms support-files]# cp mysql.server /etc/init.d/mysqld
[root@cms support-files]# service mysqld restart #重啓服務
Shutting down MySQL..120506 16:05:44 mysqld_safe mysqld from pid file /usr/local/mysql/data/cms.pid ended
[ OK ]
Starting MySQL.. [ OK ]
[1]+ Done bin/mysqld_safe --user=mysql (wd: /usr/local/mysql)
(wd now: /usr/local/mysql/support-files)
[root@cms support-files]# netstat -tupln |grep mysql #查看服務開啓端口
tcp 0 0 :::3306 :::* LISTEN 4423/mysqld
[root@cms support-files]# chkconfig mysqld on #設置開機啓動
[root@cms support-files]# chkconfig --list |grep mysql
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
對頭文件進行連接
[[root@cms support-files]# cd /usr/include
[root@cms include]# ln -s /usr/local/mysql/include mysql
對庫文件進行連接
[root@cms include]# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf #顯示該內容
[root@cms include]# cd /etc/ld.so.conf.d
[root@cms ld.so.conf.d]# vim mysqld.conf
四.安裝Apache
[root@cms ld.so.conf.d]# cd
[root@cms ~]# tar -jxvf httpd-2.2.19.tar.bz2 -C /usr/local/src #對該源碼進行解壓縮
[root@cms ~]# cd /usr/local/src
[root@cms ~]# cd httpd-2.2.19
[root@cms httpd-2.2.19]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-ssl --enable-so --with-z
[root@cms httpd-2.2.19]# make #對源碼進行編譯
[root@cms httpd-2.2.19]# make install #對源碼進行安裝
[root@cms httpd-2.2.19]# cd /etc/httpd/
[root@cms httpd]# ll
[root@cms httpd]# vim httpd.conf #修改主配置文檔
[root@cms httpd-2.2.19]# cd /usr/local/apache/htdocs
[root@cms htdocs]# vim index.html
[root@cms htdocs]# vim /etc/profile #修改系統的環境變量
[root@cms htdocs]# . /etc/profile #重新讀取該文件
[root@cms htdocs]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/mysql/bin:/root/bin:/usr/local/mysql/bin:/usr/local/apache/bin
對庫文件進行連接
[root@cms htdocs]# cd /etc/ld.so.conf.d/
[root@cms htdocs]# vim httpd.conf
[root@cms ld.so.conf.d]# apachectl stop
[root@cms ld.so.conf.d]# apachectl start
[root@cms ld.so.conf.d]# netstat -tupln |grep httpd
tcp 0 0 :::80 :::* LISTEN 2862/httpd
測試一下
五.安裝PHP
[root@cms ~]# tar -jxvf php-5.3.7.tar.bz2 -C /usr/local/src #對源碼進行解壓縮
[root@cms ~]# cd /usr/local/src/php-5.3.7 #切換目錄
[root@cms php-5.3.7]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring=all
[root@cms php-5.3.7]# make #對源碼進行編譯
[root@cms php-5.3.7]# make test #測試(可省)
[root@cms php-5.3.7]# make install #對源碼進行安裝
下面是Apache跟PHP的結合
[root@cms php-5.3.7]# vim /etc/httpd/httpd.conf #修改主配置文檔
[root@cms php-5.3.7]# cd /usr/local/apache/htdocs/
[root@cms htdocs]# vim index.php
[root@cms php-5.3.7]# cd /usr/local/apache/modules/
[root@cms modules]# ll
[root@cms modules]# apachectl start
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
httpd (pid 845) already running
在瀏覽器輸入http://192.168.10.20出現下面結果
若輸入http://192.168.10.20/index.php則出現下面結果