當(dāng)前位置:首頁(yè) > 嵌入式培訓(xùn) > 嵌入式學(xué)習(xí) > 講師博文 > Linux 下搭建Apache 服務(wù)器
在開(kāi)發(fā)過(guò)程中尤其實(shí)在開(kāi)發(fā)web程序時(shí),我們經(jīng)常需要測(cè)試web程序是否運(yùn)行·正常或者測(cè)試結(jié)果是否正確,因此我們需要有一個(gè)可以運(yùn)行web程序的服務(wù)器。大家也都知道web服務(wù)器的種類(lèi)很多,可以根據(jù)不同的需求來(lái)選擇不同的web server。但是長(zhǎng)用的莫過(guò)于Apache和Nginx了。對(duì)于這兩個(gè)服務(wù)器我們都可以到對(duì)應(yīng)的官方站點(diǎn)進(jìn)行下載安裝。
直接安裝下載好的二進(jìn)制包的確很方便和簡(jiǎn)單,但是有時(shí)候現(xiàn)成的安裝包可能無(wú)法提供我們需要的一些特定的功能,那么怎么辦呢?今天我們就分享一下在linux下如何通過(guò)源碼來(lái)編譯安裝Apache和所需的模塊。具體步驟,如下:
一、安裝apache
1、安裝apache
#tar -zxvf httpd-2.2.22.tar.gz
#cd httpd-2.2.22
#./configure --enable-moudle=so --prefix=/usr/local/apache
出現(xiàn)錯(cuò)誤 apr not found 錯(cuò)誤:
解決辦法:
1.下載所需軟件包:
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:解決apr not found問(wèn)題>>>>>>
[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問(wèn)題>>>>
[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:解決pcre問(wèn)題>>>>>>>>>
[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、
添加:exportPATH添加:export PATH=/usr/local/apache/bin:$PATH
啟動(dòng):httpd -k start
停止:httpd -k stop
重啟:httpd -k restart
5、修改/usr/local/apache/conf/httpd.conf文件,
設(shè)置:ServerName localhost:80
二、安裝php
1、解壓配置
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs \
--with-mysql=/usr(如果是使用apt-get 安裝的mysql) --with-mysqli=/usr/bin/mysql_config \
--with-pear --with-libxml-dir --disable-fileinfo
出現(xiàn)錯(cuò)誤,提示缺少 libxm12
apt-get install -y libxml2 libxml2-dev
2、make
make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1
編譯PHP5.5 make 時(shí)出現(xiàn)錯(cuò)誤
make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1
解決辦法
這是由于內(nèi)存小于1G所導(dǎo)致.
在./configure加上選項(xiàng):
--disable-fileinfo
Disable fileinfo support 禁用 fileinfo
3、make install
4、 將php源碼包中的php.ini-development 復(fù)制到/usr/local/lib/中
cp php-5.6.13/php.ini-development /usr/local/lib/php.ini
5、修改Apache配置文件(/usr/local/apache/conf/httpd.conf)以支持對(duì)PHP的解析。
如果httpd.conf中沒(méi)有下列語(yǔ)句,就將它們分別添加到LoadModule和AddType項(xiàng)的后面。
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php
在DirectoryIndex index.html index.html.var一行后加入index.php,即改為:
DirectoryIndex index.html index.html.var index.php
重啟Apache服務(wù)器:
#/usr/local/apache2/bin/apachectl restart
6、測(cè)試
在Apache服務(wù)器的文件根目錄(/usr/local/apache2/htdocs/)下新建一個(gè)PHP文件test.php,并輸入以下內(nèi)容:
phpinfo();
?>
在瀏覽器中輸入//localhost/test.php。