LAMP環境的源碼包搭建
實驗環境:
CentOS6.4 32位系統
VMware workstation 10
利用php平臺搭建的一些網站和論壇是非常出色的,網站的性能出色與他後臺的數據庫關係密切,而工作原理大致都是先同過web服務器來調用或加載有關的模塊工能來實現的,從安裝順序及服務的調用上來看,我們應該先安裝MySQL後安裝Apache。最後纔是模塊的加載
首先我們掛載光驅,並且安裝有關的開發環境軟件包
預編譯環境的搭建,在開始源碼包安裝之前一定要確認我們的預編譯環境是否完善,如圖安裝如下的軟件包
數據庫的源碼安裝:
準備要安裝的軟件包並將數據庫源碼包解壓縮到/usr/local目錄下
因爲我們要用到cmake命令,但是大部分時候我們都沒裝這個名令,所以我們要先裝一下這個命令:
然後重新執行該命令
在cmake 完成之後,你會發現又出錯的信息,具體信息如圖所示,
報錯的提示信息是要我們去安裝一個庫,因爲這個庫的缺失才造成剛纔的報錯
意爲告訴我們進行一個庫的安裝
刪除緩存文件,安裝相應的軟件包
完成之後在返回執行cmake,(這就是編譯,只要出錯就要想辦法解決,並重新執行)
然後執行make 命令(你也可以一塊執行)
數據庫的安裝與其他軟件有不同的地方,因爲在系統安裝的時候本身有一套完善的控制及路徑,所以
一些文件需要用新數據庫的support-file文件去,所以
接下來就是文件的覆蓋及路徑選擇了,對於MySQL來說這是很重要的,如圖信息是在告訴我們,已經有了一個MySQL的有關文件存在,在使用時默認使用的配置文件可能是它,所以要麼刪除,要麼覆蓋
進行覆蓋操作
然後執行以下命令,把權限改爲如下內容:
並且要用我們支持文件下的有關文件(覆蓋)去修改MySQL的腳本控制,並給予可執行權限
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# chmod a+x /etc/init.d/mysqld
然後啓動MySQL數據庫看是否正常
[root@localhost mysql]# service mysqld start
Starting MySQL......... SUCCESS!
[root@localhost mysql]# netstat -tupln |grep 3306
tcp 0 0 :::3306 :::* LISTEN 29649/mysqld
然後將它們加入到開機啓動項中
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig mysqld on
然後修改系統的環境變量PATH並重新讀取該文件
[root@localhost mysql]# vim /etc/profile
(這是一張出錯的圖,這個一時手急的錯誤折騰了我好長時間,特意留下這張圖提醒自己吧。。。注意,此處的正確改法應爲PATH=$PATH:/usr/local/mysql/bin)
[root@localhost mysql]# . /etc/profile
安裝Apache的可移植工具:apr
[root@localhost ~]# tar -zxvf apr-1.4.6.tar.gz -C /usr/local/src
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# cd ./apr-1.4.6/
[root@localhost apr-1.4.6]# ./configure --prefix=/usr/local/apr
(編譯配置的詳細步驟及解釋可參閱Apache的源碼安裝全過程)
[root@localhost apr-1.4.6]# make && make install
然後安裝apr的一個支持工具 apr-util-1.5.1.tar.gz
[root@localhost ~]tar -zxvf apr-util-1.5.1.tar.gz -C /usr/local/src
[root@localhost apr-1.4.6]# cd ..
[root@localhost src]# cd ./apr-util-1.5.1/
[root@localhost apr-util-1.5.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
[root@localhost ~]# cd /usr/local/src/apr-util-1.5.1/
[root@localhost apr-util-1.5.1]# make && make install
安裝httpd服務器
[root@localhost ~]tar -jxvf httpd-2.4.4.tar.bz2 -C /usr/local/src
[root@localhost httpd-2.4.4]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-rewrite --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr-util/bin/apu-1-config --with-pcre --with-z --enable-mpms-shared=all
在這裏可以體現源碼包安裝的一個好處就是可以指定具體的路徑,工具,要加載的模塊,要實現及支持的功能都可以在這實現,具體的命令介紹大家可以用./configure --help 來查看
你會在這發現一個報錯的地方,我們要按要求進行解決
checking for pcre-config... false
configure: error: pcreconfig for libpcre not found. PCRE is required and available from http://pcre.org/
[root@localhost httpd-2.4.4]#
在查證會看到已經安裝該包
[root@localhost httpd-2.4.4]# mount /dev/cdrom /media/cdrom
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@localhost httpd-2.4.4]# rpm -qa |grep pcre
pcre-7.8-6.el6.i686
很可能是有關的devel包沒裝,把它裝上去
[root@localhost httpd-2.4.4]# yum --disablerepo=\* --enablerepo=c6-media install pcre-devel
Complete!
[root@localhost httpd-2.4.4]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-rewrite --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr-util/bin/apu-1-config --with-pcre --with-z --enable-mpms-shared=all
configure: WARNING: OpenSSL version is too old
no
checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures
[root@localhost httpd-2.4.4]# yum --disablerepo=\* --enablerepo=c6-media install mod_ssl
Installed:
mod_ssl.i686 1:2.2.15-26.el6.centos
Complete!
[root@localhost httpd-2.4.4]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-rewrite --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr-util/bin/apu-1-config --with-pcre --with-z --enable-mpms-shared=all
可以看到沒有提到依賴安裝httpd ,我們可以安裝完成,然後接着./configure
[root@localhost httpd-2.4.4]# rpm -qa |grep mod_ssl
mod_ssl-2.2.15-26.el6.centos.i686
[root@localhost httpd-2.4.4]# yum --disablerepo=\* --enablerepo=c6-media list all |grep mod_ssl
mod_ssl.i686 1:2.2.15-26.el6.centos @c6-media
[root@localhost httpd-2.4.4]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-rewrite --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr-util/bin/apu-1-config --with-pcre --with-z --enable-mpms-shared=all
繼續提示安裝的話就把--enable=ssl 取消掉,這個對該實驗不會有影響
完成後繼續執行make makeinstall
config.status: creating build/pkg/pkginfo
config.status: creating build/config_vars.sh
config.status: creating include/ap_config_auto.h
config.status: executing default commands
[root@localhost httpd-2.4.4]# make && make install
在我們指定的有關目錄下應該會看到/usr/local下會有個Apache的目錄,在/etc/httpd/下應該有配置文件的產生,包括 conf.d 和 extra開頭的擴展的配置文件
改下下配置文件中的servername選項,不然會在啓動時有一個小的“報錯”
然後去啓動這個服務試試,注意,如果這是你的系統上一不小心安裝的有Apache服務器,那就得想辦法去卸載它了,如果你不確定你是用什麼工具裝的(rpm . yum)就只能兩個都試一下了,小編在此錯了好長時間,主要是鎖文件,腳本文件,和加入開機啓動項的緣故,有時間小編再把它寫出來分享吧
[root@localhost conf]# cd /usr/local/apache/bin
[root@localhost bin]# ls
ab checkgid envvars-std htdbm httpd rotatelogs
apachectl dbmmanage fcgistarter htdigest httxt2dbm
apxs envvars htcacheclean htpasswd logresolve
[root@localhost bin]# httpd -k start
httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
httpd (pid 17080) already running
[root@localhost bin]# netstat -tupln |grep 80
tcp 0 0 :::80 :::* LISTEN 17080/httpd
tcp 0 0 :::443 :::* LISTEN 17080/httpd
事實上我們在做完這些之後要進行腳本的編寫,和頭文件庫文件以及man手冊的鏈接,並加入chkconfig的管理(參見本文鏈接文件)
(注意,在修改/etc/profile 文件下的命令路徑(改了但是無效(路徑先後的緣故)),如果修改無效,之後要想啓動源碼安裝的Apache的服務要在httpd腳本前加全路徑./usr/local/apachme/bin(本例))
[root@localhost bin]# pkill httpd
[root@localhost bin]# /usr/local/apache/bin/httpd -k start
[root@localhost bin]# echo $PATH
/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
以上爲無效的修改,注意,是因爲添加的路徑在最後,而系統在執行時有先後順序
安裝php-5.5.8
用tar命令將包解壓縮到目錄中
-rw-r--r--. 1 root root 32794954 Jan 20 19:09 mysql-5.6.15.tar.gz
-rw-r--r--. 1 root root 13005675 Jan 21 00:22 php-5.5.8.tar.bz2
[root@localhost ~]# tar -jxvf php-5.5.8.tar.bz2 -C /usr/local/src
然後接下還是編譯配置
--with-apxs2=FILE 該參數指明瞭要將php建立成Apache2的一個共享模塊文件
在php和web(Apache)的結合中主要有兩種方式,一是靠Apache模塊,一種靠fastcgi這種將Apache看作獨立服務器的一種方法,參數爲 --enable-fpm
[root@localhost local]# cd /usr/local/src/php-5.5.8/
[root@localhost php-5.5.8]# ./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
checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2 installation
出錯了,繼續解決吧
[root@localhost php-5.5.8]# rpm -qa |grep libxml2
libxml2-python-2.7.6-8.el6_3.4.i686
libxml2-2.7.6-8.el6_3.4.i686
[root@localhost php-5.5.8]# mount
[root@localhost php-5.5.8]# yum --disablerepo=\* --enablerepo=c6-media install libxml2-devel
安裝完成我們繼續編譯
Installed:
libxml2-devel.i686 0:2.7.6-8.el6_3.4
Dependency Installed:
zlib-devel.i686 0:1.2.3-29.el6
Complete!
[root@localhost php-5.5.8]# ./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
爲了便於看到平臺的搭建結果我們有必要編寫一下httpd的腳本文件,內容如下
#!/bin/bash
prog=/usr/local/apache/bin/httpd
lockfile=/var/lock/subsys/httpd
# chkconfig: 2345 88 44 這的#不是註釋
# description: the httpd server
start () {
if [ -e $lockfile ]; then
echo "the httpd is started"
else
echo "the httpd is starting..."
sleep 1
$prog -k start &>/dev/null && echo "ok" && touch $lockfile || echo "fail"
fi
}
stop () {
if [ ! -e $lockfile ] ; then
echo "the httpd is stoped"
else
echo "the httpd is stoping...."
sleep 1
$prog -k stop &>/dev/null && echo "ok" && rm -rf $lockfile || echo "file"
fi
}
status () {
if [ -e $lockfile ]; then
echo "the http is runing....."
else
echo "the httpd is stop"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "usage {start|stop|restart}"
esac
啓動服務查看端口及鎖文件的存在
[root@localhost htdocs]# service httpd restart
the httpd is stoping....
ok
the httpd is starting...
ok
[root@localhost htdocs]ll /var/lock/subsys/http*
-rw-r--r--. 1 root root 0 Jan 21 22:08 /var/lock/subsys/httpd
[root@localhost init.d]# chkconfig --list |grep httpd
httpd 0:off1:off2:off3:off4:off5:off6:off
[root@localhost init.d]# ll /etc/rc.d/rc3.d/ |grep http
lrwxrwxrwx. 1 root root 15 Jan 21 01:49 K15httpd -> ../init.d/httpd 我們的腳本放置處
可以查看有沒有下圖中的那個模塊,這個關於php的共享庫文件是Apache上實現加載php功能用的,
[root@localhost http]# cd /usr/local/apache/modules/
[root@localhost modules]# ll |grep php*
-rwxr-xr-x. 1 root root 23326394 Jan 21 21:59 libphp5.so
然後編寫一個小的php頁面文件測試一下
[root@localhost htdocs]# vim index.php
[root@localhost htdocs]# ll
total 8
-rw-r--r--. 1 root root 45 Jun 11 2007 index.html
-rw-r--r--. 1 root root 24 Jan 21 23:42 index.php
注意這時我們的web目錄下有兩個頁面文件,而系統默認的.html結尾的是頁面文件,所以在開始時會把.php的認爲是一個目錄,需要我們手動去點進去,如圖:
解決辦法是先刪除一個文件,然後留下php的文件,並把Apache中的讀取.php的配置文件項改寫爲.php,如圖:
[root@localhost htdocs]# rm index.html
rm: remove regular file `index.html'? y
頁面內容如下
<? php
phpinfo() ;
?>
然後測試:
前面我們說過在處理php請求時會調用上面的這一個模塊進行phpd的頁面處理,當然我們還要另外加一道指令讓他完成基於php的請求,如下圖所示(一定要注意空格,這都錯了兩次)
我們可以用瀏覽器測試一下和數據庫之間的聯通性,是否正常,(php)頁面內容如圖所示
然後在瀏覽器中測試,注意瀏覽器緩存的影響,記得清一下緩存
關閉MySQL數據庫後結果,正常;
最後我們具體用wordpress來測試一下我們的平臺工作是否正常
如下解壓並複製到有關目錄:
-rw-r--r--. 1 root root 13005675 Jan 21 00:22 php-5.5.8.tar.bz2
-rw-r--r--. 1 root root 6806135 Jan 22 00:07 wordpress-3.8-zh_CN.zip
[root@localhost ~]# unzip wordpress-3.8-zh_CN.zip
[root@localhost ~]# mv wordpress-3.8-zh_CN.zip /usr/local/apache/htdocs/
按照安裝文件的有關內容完成安裝後可以看到論壇建立完成後有關頁面及效果(具體安裝步驟請參閱lamp平臺下安裝wordpress及phpadmin全過程)
論壇後臺頁面:
論壇的前臺瀏覽器效果頁面(無主題環境下)