lamp平臺的搭建:apache的編譯安裝

最近百度了下網上編譯搭建lamp平臺的文章,感受大都寫的亂糟糟的,不少編譯過程當中會遇到的問題文章裏也都沒有提出來,搞的斷斷續續的非常不爽,這裏本人將作下統籌,把常見的問題也列舉出來供你們參考php

前期工做

檢查是否安裝過apache mysql php,如有就刪掉吧,檢查方法自行百度html

centos7停用firewall防火牆,啓用iptables(centos6的話直接去開放端口就好)mysql

systemctl stop firewalld.service #中止firewall服務
systemctl disable firewalld.service #禁止firewall開機啓動

yum -y install iptables-services #安裝iptables服務

vi /etc/sysconfig/iptables #編輯iptables配置
.....在22端口行下添加80和3306端口
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT #apache端口
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT #mysql端口
:wq! #保存退出

systemctl restart iptables.service #重啓iptables服務
systemctl enable iptables.service #開機啓動iptables

若是你不想用iptables,繼續要用firewall,firewall添加端口的方法以下linux

firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload

停用selinux,不然編譯安裝可能會出錯sql

vi /etc/selinux/config #編輯selinux配置
.....
#SELINUX=enforcing #註釋掉
#SELINUXTYPE=targeted #註釋掉
SELINUX=disabled #增長
:wq! #保存退出
setenforce 0 #使配置當即生效

更新下yum的倉庫apache

epel 爲 yum 的擴展源centos

yum install epel-release #擴展包更新包
yum update #更新yum源

安裝開發包工具瀏覽器

yum groupinstall "Development Tools"

Apache的安裝

apache的下載:http://httpd.apache.org/download.cgi,這裏咱們下載穩定版httpd-2.4.12.tar.gztcp

apache的新版須要apr apr-util的支持,確定少人在編譯時都遇到 apr not found的錯誤,解決方法有兩個ide

一、編譯安裝apr和apr-util,但同時要編譯安裝pcre

二、將apr和apr-util的源文件放入apache的srclib文件夾下,編譯時加上使用內置的apr版本便可,方便的很

第一種:

yum remove "apr*"

tar -zxvf apr-1.5.2.tar.gz
tar -zxvf apr-util-1.5.4.tar.gz

cd apr-1.5.2
./configure --prefix=/usr/local/apr
make && make install

cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util –-with-apr=/usr/local/apr
make && make install

#本身下pcre,我推薦使用第二種方法,簡單
unzip -o pcre-8.10.zip
cd pcre-8.10
./configure --prefix=/usr/local/pcre
make && make install

cd httpd-2.4.12
./configure --prefix=/usr/local/apache --enable-so --enable-deflate=shared --enable-expires=shared  --enable-headers=shared --enable-rewrite=shared --enable-static-support --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre
make && make install

第二種很簡單:(推薦)

下載apr和apr-util將文件放在apache源文件的srclib目錄下

 srclib          

    |--apr      

    |--apr-util

tar -zxvf httpd-2.4.12.tar.gz #解壓到當前目錄

mkdir ./httpd-2.4.12/srclib/apr ./httpd-2.4.12/srclib/apr-util #建立apr和apr-util的內置文件夾

#解壓apr apr-util
tar -zxvf apr-1.5.2.tar.gz
tar -zxvf apr-util-1.5.4.tar.gz

#將apr apr-util分別拷貝至 apache源文件加下的srclib/apr 和 srclib/apr-util下
cp -r apr-1.5.2/* ./httpd-2.4.12/srclib/apr 
cp -r apr-util-1.5.4/* ./httpd-2.4.12/srclib/apr-util

#編譯安裝apache
cd httpd-2.4.12

./configure --prefix=/usr/local/apache --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared  --enable-headers=shared --enable-rewrite=shared --enable-static-support

make && make install

--prefix=/usr/local/apache:指定安裝目錄
--with-included-apr:在編譯時強制使用當前源代碼中綁定的APR版本,也就是咱們放入srclib文件夾下的apr和apr-util
--enable-so:容許運行時加載DSO模塊
--enable-deflate=shared:將deflate模塊編譯爲DSO
--enable-expires=shared:將expires模塊編譯爲DSO
--enable-headers=shared:將headers模塊編譯爲DSO
--enable-rewrite=shared:將rewrite模塊編譯爲DSO
--enable-static-support:使用靜態鏈接(默認爲動態鏈接)編譯全部二進制支持程序

配置工做

#將apache加入系統服務,並設置開機啓動
cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
vi /etc/init.d/httpd
#在#!/bin/sh下加入
#chkconfig: 2345 10 90
#description:Activates/Deactivates Apache Web Server
:wq!
chkconfig --add httpd 將apache加入系統控制
chkconfig httpd on 將apache設爲開機啓動 systemctl enable httpd.service也能夠

#添加apache用戶
useradd apache
#建立apache文檔根目錄(我比較強迫保持與yum安裝的一致)
mkdir -p /var/www/html
chown -R apache:apache /var/www/html

vi /usr/local/apache/conf/http.conf
DocumentRoot '/var/www/html'
AllowOverride All
Require all granted
:wq!
#重啓apache
systemctl restart httpd.service

如今去瀏覽器中輸入localhost就能夠正常訪問了

apache安裝到此就OK了

下一篇:http://my.oschina.net/sallency/blog/473626

相關文章
相關標籤/搜索