1. 程式人生 > >Centos 7.0 編譯安裝LAMP(Linxu+apache+mysql+php)之源碼安裝Apache (一)

Centos 7.0 編譯安裝LAMP(Linxu+apache+mysql+php)之源碼安裝Apache (一)

mysql apache mysql編譯安裝 apache編譯安裝 lamp編譯安裝

Apache 簡介:

Apache是世界使用排名第一的Web服務器軟件。它可以運行在幾乎所有廣泛使用的計算機平臺上,由於其跨平臺和安全性被廣泛使用,是最流行的Web服務器端軟件之一。它快速、可靠並且可通過簡單的API擴充,將Perl/Python解釋器編譯到服務器中。

安裝環境:

系統: centos 7.0 最小化安裝

軟件:httpd-2.4.26

依賴包:apr 、apr-util 、pcre 、gcc 、gcc-c++ 、perl-dvel、perl、openssl 、openssl-devel、ncurses 、 ncurses-dvel

準備工作:

  1. 關閉firewall:
    [[email protected] ~]# systemctl stop firewalld.service
    #停止firewall

    [[email protected] ~]# systemctl disable firewalld.service #禁止firewall開機啟動

  2. 安裝iptables防火墻

    [[email protected] ~]# yum install iptables-services #安裝

    [[email protected] ~]# vi /etc/sysconfig/iptables

    #編輯防火墻配置文件

    添加代碼如下:

    -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT#允許http協議80 端口通過

    -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT#允許mysql 3306端口通過

    :wq! #保存退出

    [[email protected] ~]systemctl restart iptables.service #最後重啟防火墻使配置生效

    [[email protected]

/* */ ~]systemctl enable iptables.service #設置防火墻開機啟動

  • 關閉selinux

    [[email protected] ~] vi /etc/selinux/config

    #SELINUX=enforcing #註釋掉

    #SELINUXTYPE=targeted #註釋掉

    SELINUX=disabled #增加改行內容

    :wq! #保存退出

    [[email protected] ~]#setenforce 0 #使配置立即生效

  • 源碼安裝包及依賴包上傳到目錄 /usr/local/src

  • appache源碼包 httpd-2.4.26.tar.gz

    mysql 源碼包 mysql-5.6.19

    php 源碼包 php-5.5.1

    安裝Apache 前準備,依賴包的安裝:

    1. 編譯安裝apr

      [[email protected] src]# tar -zxf apr-1.5.2.tar.gz

      [[email protected] src]# cd apr-1.5.2

      [[email protected] apr-1.5.2]# ./configure --prefix=/usr/local/apr #配置安裝路徑

      [[email protected] apr-1.5.2] make && make install #編譯安裝

    2. 編譯安裝apr-util

      [[email protected] src]# tar -zxf apr-util-1.5.4.tar.gz

      [[email protected] src]# cd apr-1.5.4

      [[email protected] apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr #必須執行--with-apr 安裝路徑

      [[email protected] apr-util-1.5.4] make && make install

    3. 編譯安裝pcre

      [[email protected] src]# tar -zxf pcre-8.39.tar.gz

      [[email protected] src]# cd pcre-8.39

      [[email protected] pcre-8.39]# ./configure --prefix=/usr/local/pcre

      [[email protected] pcre-8.39] make && make install

    4. 編譯安裝openssl

      [[email protected] src]# tar -zxf openssl-1.0.1h.tar.gz

      [[email protected] src]# cd openssl-1.0.1h

      [[email protected] openssl-1.0.1h]# ./configure --prefix=/usr/local/openssl

      [[email protected] openssl-1.0.1h] make && make install

    5. yum 安裝其他依賴包

      [[email protected] src]yum install -y gcc gcc-c++ ncurese-dvedl openssl-devel ncurese

    編譯安裝Apache:

    [[email protected] src]# tar -zxf httpd-2.4.26.tar.gz

    [[email protected] src]]# cd httpd-2.4.20

    [[email protected] httpd-2.4.20]#

    ./configure \
    --prefix=/usr/local/apache \

    --sysconfdir=/etc/httpd \

    --enable-so \

    --enable-ssl \

    --enable-cgi \

    --enable-rewrite \
    --with-zlib \

    --with-pcre=/usr/local/pcre \

    --with-openssl=/usr/local/openssl \
    --with-apr=/usr/local/apr \
    --with-apr-util=/usr/local/apr-util \
    --enable-mods-shared=most \

    --enable-mpms-shared=all \
    --with-mpm=event
    [[email protected] httpd-2.4.20]# make && make install

    選項解釋:
    --prefix=/usr/local/apache # 指定安裝目錄

    --sysconfdir=/etc/httpd # 指定配置文件安裝路徑
    --enable-so
    #允許運行時加載DSO模塊

    --enable-ssl #啟動ssl加密功能
    --enable-cgi
    # 啟用cgi協議

    --enable-rewrite #啟用URL重寫功能
    --with-zlib --with-pcre
    # 指定pcre的安裝路徑

    --with-apr=/usr/local/apr #指定apr的安裝路徑

    --with-apr-util=/usr/local/apr-util # 指定apr-util的安裝路徑

    --enable-modules=most #啟用大多數共享模塊
    --enable-mpms-shared=most
    #啟用MPM大多數參數
    --with-mpm=event
    #指定使用的MPM的類型

    復制服務腳本,讓其可以使用service起停

    [[email protected] httpd-2.4.20] cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/ #復制啟動本到啟動目錄下

    [[email protected] httpd-2.4.20] mv /etc/rc.d/init.d/apachectl /etc/rc.d/init.d/httpd

    [[email protected] httpd-2.4.20] chmod 755 -R /etc/rc.d/init.d/httpd

    [[email protected] httpd-2.4.20]vi /etc/httpd/httpd.conf #編輯httpd.conf文本

    在該行#ServerName www.example.com:80 下添加以下內容

    ServerName localhost:80

    :wq

    [[email protected] httpd-2.4.20] service httpd start #啟動httpd 服務

    把httpd 服務添加到開機服務列表

    [[email protected] httpd-2.4.20]vi /etc/httpd/httpd.conf #編輯httpd.conf文本 ,支持chkconfig 添加服務

    #!/bin/bash

    #chkconfig:345 61 61 //添加此行,345參數表示,在哪些運行級別啟動,啟動序號(S61);關閉序號(K61)

    #description:Apache httpd //添加此行,必寫,描述服務

    :wq #保存退出

    [[email protected] httpd-2.4.20]chkconfig --add httpd

    [[email protected] httpd-2.4.20]chkconfig httpd on

    驗證apache安裝 :

    [[email protected] src]# curl http://localhost #驗證安裝

    <html><body><h1>It works!</h1></body></html>

    [[email protected] src]# chkconfig --list

    httpd 0:關 1:關 2:開 3:開 4:開 5:開 6:關

    netconsole 0:關 1:關 2:關 3:關 4:關 5:關 6:關

    network 0:關 1:關 2:開 3:開 4:開 5:開 6:關


    至此 ,該Apache 服務安裝完成 ,後續將繼續為LAMP服務器安裝mysql服務 ,請看下文 Centos 7.0 官方編譯安裝LAMP之源碼安裝Mysql (二)





    本文出自 “ITCol_XiaoYu” 博客,請務必保留此出處http://itcolxiaoyu.blog.51cto.com/11439802/1942068

    Centos 7.0 編譯安裝LAMP(Linxu+apache+mysql+php)之源碼安裝Apache (一)