linux源码安装apache2,CentOS7编译安装Apache2
在LAMP環境下對于服務的安裝是必不可少的,在linux環境下安裝軟件也有兩種不同的方式,一種是yum安裝當然了不同的linux發行版本使用略有不同,另一種是通過編譯安裝,編譯安裝要比yum安裝要可控此,但是要比yum安裝略微麻煩些我們下面這種方式就是通過編譯安裝的方式安裝Apache2服務器軟件,如果你覺得麻煩可以使用類似的yum方式哦!
安裝軟件運行基礎
apr
下載地址
[root@localhost soft]# wget -i http://www-eu.apache.org/dist//apr/apr-1.6.3.tar.gz
解壓編譯安裝
解壓
[root@localhost soft]# tar -zxf apr-1.6.3.tar.gz && apr-1.6.3
編譯
[root@localhost apr-1.6.3]# ./configure --prefix=/usr/local/apr
安裝
[root@localhost apr-1.6.3]# make && make install
apr-util
下載地址
[root@localhost soft]# wget -i http://www-eu.apache.org/dist//apr/apr-util-1.6.1.tar.gz
解壓編譯安裝
解壓
[root@localhost soft]# tar -zxf apr-util-1.6.1.tar.gz && cd apr-util-1.6.1
編譯
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
安裝
[root@localhost apr-util-1.6.1]# make && make install
pcre
下載地址
[root@localhost soft]# wget -i https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz
解壓編譯安裝
解壓
[root@localhost soft]# tar -zxf pcre-8.41.tar.gz && cd pcre-8.41
編譯
[root@localhost pcre-8.41]# ./configure --prefix=/usr/local/pcre
安裝
[root@localhost pcre-8.41]# make && make install
安裝Apache2
下載地址
[root@localhost soft]# wget -i http://www-us.apache.org/dist//httpd/httpd-2.4.29.tar.bz2
解壓編譯安裝
解壓
[root@localhost soft]# tar -jxf httpd-2.4.29.tar.bz2 && cd httpd-2.4.29
編譯
[root@localhost httpd-2.4.29]# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre
安裝
[root@localhost httpd-2.4.29]# make && make install
配置Apache2
修改配置文件
[root@localhost soft]# vim /usr/local/apache2/conf/httpd.conf
修改監聽端口號
Listen 8088
修改 ServerName
ServerName www.apache-host.dev:8088
修改項目目錄
DocumentRoot "/www/apache-host"
修改項目目錄具體參數
設置Apache2為Linux服務并實現開機自啟動
添加Apache2配置文件 apachectl 到linux服務
拷貝文件并重命名
[root@localhost soft]# cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
將系統配置目錄下的 httpd 添加到 系統服務
[root@localhost soft]# chkconfig --add httpd
設置系統服務 httpd 為開機啟動
[root@localhost soft]# chkconfig httpd on
檢測系統服務 httpd 是否啟動成功
查看系統服務狀態
[root@localhost soft]# chkconfig --list | grep httpd
系統服務狀態詳情
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
可見服務已經在 第2 到 第5 運行等級打開, 說明系統服務 httpd 已正常開啟開機啟動
禁用系統服務 httpd
禁用系統服務
[root@localhost soft]# chkconfig httpd off
禁用系統服務狀態
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
可見服務已經在 第1 到 第6 運行等級關閉, 說明系統服務 httpd 已正常關閉開機啟動功能
開啟系統服務Apache2
[root@localhost soft]# systemctl start httpd.service
查看系統服務運行狀態
[root@localhost soft]# systemctl status httpd.service
驗證是否成功安裝Apache2
通過curl命令行檢測是否安裝成功
檢測
[root@localhost soft]# curl -I "http://127.0.0.1:8088"
結果
HTTP/1.1 200 OK
Date: Sun, 31 Dec 2017 18:23:24 GMT
Server: Apache/2.4.29 (Unix)
Content-Type: text/html;charset=ISO-8859-1
通過瀏覽器檢測是否安裝成功
總結
以上是生活随笔為你收集整理的linux源码安装apache2,CentOS7编译安装Apache2的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 路由器把密码忘了解决方法没有如何设置路由
- 下一篇: linux 提示符 异常,linux终端