安裝時的順序:
Httpd-----mysql------php
安裝:
安裝httpd(源碼)
1、配置yum 源,看當前的系統是否存在編譯環境
Yum grouplist
Development Libraries
Development Tools
Legacy Software Development
X Software Development
如果系統不存在以上包組,可以用yum groupinstall 安裝
2、上傳httpd源碼包
3、解壓到指定目錄
Tar zxvf httpd-2.4.7.tar.gz –C /usr/src
4、在安裝httpd時需要用到兩個apr可移植運行庫和工具
apr-1.5.0.tar.gz和apr-util-1.5.3.tar.gz需要一起上傳到服務器
並解壓到相應目錄並安裝
Tar zxvf apr-1.5.0.tar.gz –C /usr/src
Tar zxvf apr-util-1.5.3.tar.gz –C /usr/src
cd /usr/src/apr-1.5.0
./configure –prefix=/usr/local/apr 配置並指明安裝路徑
Make 編譯
Make install 安裝
安裝完成之後他的庫文件可能有其他程序的依賴(解決該方法)
在/etc/ld.so.conf.d/下創建一個文件,並指明apr的安裝路徑
Vim /etc/ld.so.conf.d/apr.conf (一定要以.conf結尾)
/usr/local/apr/lib
刷新緩存(刷新之前可以先看下/etc/ld.so.cache文件的大小)
[root@wnt10 apr-util-1.5.3]# ll /etc/ld.so.cache
-rw-r--r-- 1 root root 49683 Feb 27 20:55 /etc/ld.so.cache
Ldconfig 刷新緩存在看cache文件
[root@wnt10 apr-util-1.5.3]# ldconfig
[root@wnt10 apr-util-1.5.3]# ll /etc/ld.so.cache
-rw-r--r-- 1 root root 49845 Mar 5 00:51 /etc/ld.so.cache
可以用ldconfig –pv 來查看apr模塊是否被加載
[root@wnt10 apr-util-1.5.3]# ldconfig -pv |grep apr
libgstdataprotocol-0.10.so.0 (libc6) => /usr/lib/libgstdataprotocol-0.10.so.0
libaprutil-1.so.0 (libc6) => /usr/lib/libaprutil-1.so.0
libapr-1.so.0 (libc6) => /usr/local/apr/lib/libapr-1.so.0
libapr-1.so.0 (libc6) => /usr/lib/libapr-1.so.0
libapr-1.so (libc6)=> /usr/local/apr/lib/libapr-1.so
可以看到apr模塊被成功加載
除了庫文件有可能被其他程序所調用外,頭文件一樣也可能被其他程序所調用
系統所找到的頭文件一般都會放在/usr/inclide/ 或者/usr/local/include/
這時爲了方便系統所找到頭文件可以做一個軟鏈接
Ln –s /usr/local/apr/include/usr/include/apr
cd /usr/src/apr-until 如果不確定怎麼安裝可以先查看readme 或者install文件
./configure --prefix=/usr/local/apr-util--with-apr=/usr/local/apr/bin/apr-1-config
表明要和apr的執行程序所關聯起來
Make && make install
Vim /etc/ld.so.conf.d/apr-util.conf (操作原意同上)
/usr/local/apr-util/lib
Ldconfig
Ldconfig –pv |grep apr-util
[[email protected]]# ldconfig -pv |grep apr-util
libaprutil-1.so.0 (libc6)=> /usr/local/apr-util/lib/libaprutil-1.so.0
libaprutil-1.so(libc6) => /usr/local/apr-util/lib/libaprutil-1.so
ln –s /usr/local/apr-util/include /usr/include/apr-util
如果想在系統下任何路徑下都能去執行/usr/loca/apr-util/bin/apu-1-conf就需要把它添加到環境變量裏面,系統的環境變量一般會涉及到4個文件
/etc/profile /etc/bashrc (系統) ~.bashrc ~.bash_profile(個人)
如果想讓任何人都能去執行apu-1-conf和apr-1-conf就需要放到系統裏面/etc/profile
Vim /etc/profile
添加PATH=$PATH:/usr/local/apr-util/bin:/usr/local/apr/bin
如果想使其生效,可在下次登錄時自動生效或 . /etc/profile
5、好了,這裏的準備環境已經完成,下面正式安裝httpd源碼包
進入/uar/src/httpd
[[email protected]]# ./configure \(表示換行)
>--prefix=/usr/local/apache \ 指明路徑
>--with-apr=/usr/local/apr/bin/apr-1-config \ 指明和apr關聯的可執行文件
>--with-apr-util=/usr/local/apr-util/bin/apu-1-config \ 和apr-util關聯的執行文件
>--sysconfdir=/etc/httpd \ 指明安裝路徑
>--enable-mods-shared=all \ 指明所用的模塊
>--enable-ssl \ 開啓ssl功能
>--enable-mpms-shared=all \ 指明mpm機制
>--enable-rewrite \ 開啓地址重寫功能
>--with-z \ 開啓網頁傳輸自動壓縮
> --enable-so 開啓模塊功能
這時系統報了一個pcre的錯誤:
configure: error: pcre-config for libpcre not found. PCREis required and available from http://pcre.org/
[[email protected]]# yum list |grep pcre
Thissystem is not registered with RHN.
RHNsupport will be disabled.
pcre.i386 6.6-2.el5_1.7 installed
pcre-devel.i386 6.6-2.el5_1.7 rhel-server
發現pcre-devel工具沒有安裝,可以yuminstall pcre-devel直接安裝
安裝完成之後再配置httpd後面還有加上—with-pcre
Make && make install
安裝完成之後想要所有人都能使用/bin/下的可執行文件還需要配置環境變量,
Vim /etc/profile
PATH=$PATH:/usr/local/apr-util/bin:/usr/local/apr/bin:/usr/local/apache/bin
Ln –s /usr/local/apache/include/ /usr/include/apache
這裏沒有庫文件,但是有man(幫助手冊)還需要把man添加到系統路徑
Vim /etc/man.config
添加MANPATH/usr/local/apache/man
還有就是控制腳本,一般系統的控制腳本是放在/etc/init.d/下
創建一個httpd的腳本
Vim /etc/init.d/httpd
Chmod a+x /etc/init.d/httpd
#!/bin/bash
# chkconfig: 2345 56 26
# description: httpd server daemon
conf=/etc/httpd/httpd.conf
lock=/var/lock/subsys/httpd
prog=/usr/local/apache/bin/httpd
. /etc/init.d/functions
start () {
if
[ -f $lock ] ; then
echo "the httpd isstarted"
else
echo -n "the httpd is starting......."
sleep 1
$prog -f $conf && echo "[ok]" && touch$lock || echo "[fail]"
fi
}
stop () {
if
[ -f $lock ] ; then
echo -n "the httpd is stoping ......"
sleep 1
killproc httpd && echo "[ok]" && rm -rf$lock ||echo "[fail]"
else
echo "the httpd is stoped......"
fi
}
status () {
if
[ -f $lock ] ; then
echo "the httpd isstarted......"
else
echo "the httpd is stop"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
*)
echo "the httpd useage {start|stop|status|restart}"
esac
chkconfig –add httpd
chkconfig –list |grep httpd
[root@wnt10 init.d]# chkconfig --list |grep httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
這樣httpd就安裝完畢,下載源碼包地址http://httpd.apache.org
安裝mysql(源碼)下載地址:www.mysql.com
1、下載源碼包上傳到服務器(mysql5.6.10)
2、解壓到指定目錄(同httpd的解壓方法一樣)
Mysql在5.6以後沒有./configure配置文件,這裏需要cmake工具(說明文檔)
先下載cmake工具上傳到服務器進行解壓縮
tar zxvfcmake-2.8.12.2.tar.gz -C /usr/src/
cd/usr/src/cmake
./configure –prefix=/usr/local/cmake
Make && make install
修改環境變量 /etc/profile
PATH=$PATH:/usr/local/apr-util/bin:/usr/local/apr/bin:/usr/local/apache/bin:/usr/local/cmak
e/bin
添加man手冊/etc/man.config
MANPATH /usr/local/cmake/man
安裝完cmake之後需要創建一個系統賬號mysql和mysql組
Groupadd mysql
Useradd –r –gmysql mysql
準備工作完成之後,安裝mysql
進入到解壓目錄/usr/src/mysql
Cmake . (如果不加其他參數表明安裝默認選項)
Make &&make install
經過漫長的等待時間,總算安裝完成mysql
然後需要把bin下的工具加到系統環境變量/etc/profile
PATH=$PATH:/usr/local/apr-util/bin:/usr/local/apr/bin:/usr/local/apache/bin:/usr/local/cmak
e/bin:/usr/local/mysql/bin
添加完之後還要添加頭文件、庫文件以及man手冊
更改man手冊/etc/man.config
MANPATH /usr/local/mysql/man
Ln –s /usr/local/mysql/include /usr/include/mysql
Vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
Ldconfig
Ldconfig –pv |grep mysql
這裏把基本的安裝配置添加等等全做完之後還要做一些設置
Cd /usr/local/mysql
Chown –R mysql. 更改mysql目錄下所有文件及目錄的所有者爲mysql
Chgrp –R mysql . 更改mysql目錄下所有文件及目錄的所屬組爲mysql
或者Chown –R mysql.mysql. 也可以
Scripts/mysql_install_db–user=mysql 去安裝初始數據庫以mysql的用戶安裝
初始的過程中會看到INnoDB (這表示是5.6版本以後的數據庫引擎5.5以前的數據庫引擎爲myISAM)僅供瞭解
初始化完成之後需要把所有者改回root,其中有一個data特殊所有者爲mysql
Chown –R root .
Chown –R mysqldata
cpsupport-files/my-default.cnf /etc/my.cnf 拷貝mysql的配置文件到/etc下
cpsupport-files/mysql.server /etc/init.d/mysqld 把mysql的控制腳本拷貝到/etc/init.d/下叫mysqld
這時就可以使用
Service mysqldstart|stop|restart|status等等的參數
Chkconfigmysqld on 開機自動運行
到這裏mysql已經安裝完畢
安裝php源碼包
1、下載源碼包上傳到服務器
2、解壓到指定目錄(同httpd的解壓方法一樣)
3、[[email protected]]# ./configure \
> --prefix=/usr/local/php \ 安裝路徑
> --sysconfdir=/etc/php.conf \ 主配置文件安裝路徑
> --with-apxs2=/usr/local/apache/bin/apxs\ 必須要有
> --with-gd \ 對圖形的支持
> --with-jpeg-dir \ 對不同格式圖片的支持
> --with-png-dir \
> --with-zlib-dir \ 支持壓縮
> --enable-mbstring \ 支持多種字符級
> --with-mysql=/usr/local/mysql \ 調用mysql 必須要有
>--with-mysqli=/usr/local/mysql/bin/mysql_config \ php和mysql結合的接口文件在什麼地方必須要有
Make && make install
安裝完之後
然後需要把bin下的工具加到系統環境變量/etc/profile
PATH=$PATH:/usr/local/apr-util/bin:/usr/local/apr/bin:/usr/local/apache/bin:/usr/local/cmak
e/bin:/usr/local/mysql/bin:/usr/local/php/bin
如果想讓httpd支持php網頁需要在httpd的配置文件加上一下一行,並且需要加上index.php
Addtype application/x-httpd-php .php .phtml
以下是配置文件改完之後的內容
AddTypeapplication/x-httpd-php .php .phtml
<IfModuledir_module>
DirectoryIndex index.php index.html
</IfModule>
重啓服務
默認apache:站點的主目錄在/usr/local/apache/htdocs
[[email protected]]# cd /usr/local/apache/htdocs/
[root@wnt10htdocs]# ls
index.html
[root@wnt10htdocs]# mv index.html index.php
Vim index.php
<html><body><h1>Itworks!</h1></body></html>
<?php
phpinfo();
?>
用網頁測試顯示php的信息頁面這說明httpd與php結合成功
Vim index.php
<html><body><h1>Itworks!</h1></body></html>
<?php
$link=Mysql_connect(‘127.0.0.1’,’root’,’123’);
If ($link)
Echo “ok”;
Else echo”fail”;
?>
用網頁測試顯示ok的信息這說明mysql與php結合成功(這裏需要重啓mysqld服務)