Linux 下(xia)搭建(jian)Apache 服務器
時間(jian):2018-09-25 來(lai)源(yuan):未(wei)知
在(zai)(zai)開發(fa)過程中尤其實在(zai)(zai)開發(fa)web程序(xu)時,我們(men)經常需要測(ce)試(shi)web程序(xu)是(shi)(shi)否運(yun)(yun)行·正常或者(zhe)測(ce)試(shi)結果是(shi)(shi)否正確,因此我們(men)需要有(you)一個可以(yi)運(yun)(yun)行web程序(xu)的(de)服(fu)務器(qi)。大家(jia)也都知道web服(fu)務器(qi)的(de)種類很多,可以(yi)根據不同的(de)需求來選(xuan)擇不同的(de)web server。但是(shi)(shi)長用的(de)莫過于Apache和(he)Nginx了。對于這兩個服(fu)務器(qi)我們(men)都可以(yi)到(dao)對應的(de)官(guan)方站點進行下(xia)載安裝(zhuang)。
直接安(an)裝(zhuang)下(xia)載好的(de)二進(jin)制包的(de)確很方便和簡單(dan),但是有時候現成的(de)安(an)裝(zhuang)包可(ke)能(neng)無法提供我(wo)們(men)需要的(de)一(yi)些特定的(de)功(gong)能(neng),那么怎(zen)么辦呢?今(jin)天我(wo)們(men)就分(fen)享(xiang)一(yi)下(xia)在linux下(xia)如何通(tong)過源碼來編譯安(an)裝(zhuang)Apache和所需的(de)模塊(kuai)。具(ju)體(ti)步驟,如下(xia):
一、安裝apache
1、安裝apache
#tar -zxvf httpd-2.2.22.tar.gz
#cd httpd-2.2.22
#./configure --enable-moudle=so --prefix=/usr/local/apache
出現錯(cuo)誤 apr not found 錯(cuo)誤:
解決辦法:
1.下載所需軟件(jian)包(bao):
wget //archive.apache.org/dist/apr/apr-1.4.5.tar.gz
wget //archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz
wget //jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip
a:解決(jue)apr not found問(wen)題>>>>>>
[root@xt test]# tar -zxf apr-1.4.5.tar.gz
[root@xt test]# cd apr-1.4.5
[root@xt apr-1.4.5]# ./configure --prefix=/usr/local/apr
[root@xt apr-1.4.5]# make && make install
b:解決APR-util not found問題>>>>
[root@xt test]# tar -zxf apr-util-1.3.12.tar.gz
[root@xt test]# cd apr-util-1.3.12
[root@xt apr-util-1.3.12]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
[root@xt apr-util-1.3.12]# make && make install
c:解決(jue)pcre問題>>>>>>>>>
[root@xt test]#unzip -o pcre-8.10.zip
[root@xt test]#cd pcre-8.10
[root@xt pcre-8.10]#./configure --prefix=/usr/local/pcre
[root@xt pcre-8.10]#make && make install
2、#./configure --enable-moudle=so --prefix=/usr/local/apache --with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--with-pcre=/usr/local/pcre
3、 make && make install
4、
添(tian)加(jia):exportPATH添(tian)加(jia):export PATH=/usr/local/apache/bin:$PATH
啟動:httpd -k start
停止(zhi):httpd -k stop
重啟:httpd -k restart
5、修改/usr/local/apache/conf/httpd.conf文(wen)件(jian),
設置:ServerName localhost:80
二、安裝php
1、解(jie)壓配置
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs \
--with-mysql=/usr(如(ru)果是(shi)使用(yong)apt-get 安裝的mysql) --with-mysqli=/usr/bin/mysql_config \
--with-pear --with-libxml-dir --disable-fileinfo
出現錯(cuo)誤,提(ti)示缺少 libxm12
apt-get install -y libxml2 libxml2-dev
2、make
make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1
編譯PHP5.5 make 時(shi)出現錯誤
make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1
解決辦法
這是由于(yu)內存小于(yu)1G所導致.
在(zai)./configure加(jia)上(shang)選(xuan)項:
--disable-fileinfo
Disable fileinfo support 禁用 fileinfo
3、make install
4、 將(jiang)php源碼包中(zhong)(zhong)的php.ini-development 復制到/usr/local/lib/中(zhong)(zhong)
cp php-5.6.13/php.ini-development /usr/local/lib/php.ini
5、修改(gai)Apache配置文(wen)件(/usr/local/apache/conf/httpd.conf)以支持對PHP的解(jie)析。
如果httpd.conf中(zhong)沒有下(xia)列語句,就將它們分(fen)別添(tian)加到LoadModule和AddType項的后面。
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php
在DirectoryIndex index.html index.html.var一行后加入index.php,即改為(wei):
DirectoryIndex index.html index.html.var index.php
重(zhong)啟(qi)Apache服務器(qi):
#/usr/local/apache2/bin/apachectl restart
6、測試
在Apache服務器的文件根目(mu)錄(/usr/local/apache2/htdocs/)下(xia)新(xin)建(jian)一個PHP文件test.php,并輸入以下(xia)內(nei)容:
phpinfo();
?>
在瀏覽器中輸入(ru)//localhost/test.php。

