Linux下安裝Apache


安裝Apache參考網址
https://www.cnblogs.com/xdouby/p/6406873.html
第一步下載
網址
例如:
wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.37.tar.bz2
錯誤提示
xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory
yum -y install expat-devel
版本不兼容
https://blog.csdn.net/gouhexiong1989/article/details/78694037?tdsourcetag=s_pctim_aiomsg
見以網址錯誤提示
結論刪除1.6版本的apr 和apr-util,重新下載1.5版本重新編譯和安裝。
重新下載
http://archive.apache.org/dist/apr/
http://archive.apache.org/dist/apr/apr-1.5.2.tar.gz
http://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz

刪除舊版本的apr和apr-util
rm –rf /usr/local/apr
rm –rf /usr/local/apr-util

開始安裝
首先安裝編譯環境
yum install -y gcc gcc-c++
把壓縮包放到root下
第一步:安裝apr
tar –xvf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure --prefix=/usr/local/apr
會出現錯誤要下載gcc
yum -y install gcc(Ubuntu是apt-get,-y是一直yes不用自己選)
make –j
make install
第二步:安裝apr-util
tar –xvf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config
make –j
make install

第三步:安裝pcre
tar –xvf pcre-8.42.tar.gz
./configure --prefix=/usr/local/pcre
在之前會報錯,沒有c++,則需要裝apt-get(centos用yum) install gcc-c++
make –j
make install

第四步:安裝openssl
tar –xvf openssl-1.0.2q.tar.gz
cd openssl-1.0.2q
./config --prefix=/usr/local/openssl
make –j
make install
cd /usr/local
ln -s openssl ssl
在/etc/ld.so.conf文件的最后面,添加如下內容:
/usr/local/openssl/lib
執行 ldconfig
添加OPESSL的環境變量,在/etc/profile的最后一行,添加:
export OPENSSL=/usr/local/openssl/bin
export PATH=$OPENSSL:$PATH:$HOME/bin
執行source /etc/profile

第五步:安裝httpd
tar –xvf httpd-2.4.37.tar.gz
cd httpd-2.4.37
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-
util=/usr/local/apr-util --with-pcre=/usr/local/pcre
如果上述錯誤,則執行第四步,否則不必要
make –j
make install
第六步(不必要):啟動服務
添加防火牆配置
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
firewall-cmd –reload
netstat –apnt|grep 80
注:ubuntu:ufw disable

管理apache服務
apache默認占用80端口,所以如果有應用占用80這個端口,就要注意會存在端口沖突問題。
•啟動Apache:/usr/local/apache2/bin/apachectl start


發生錯誤AH00558: httpd: Could not reliably determine the server's fully qualified domain name,
using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message

解決網址https://blog.csdn.net/zhaomininternational/article/details/42293511

即執行vim /usr/local/apache2/conf/httpd.conf
搜索/ServerName
#ServerName www.example.com:80 更改為ServerName localhost:80
ps -aux |grep 進程號
netstat -anpt |grep 80查看端口
wget是Linux上網的命令,直接輸入wget查看是否可用,不可用則用yum install wget安裝
然后輸入wget localhost在本地下載一個文件為index.txt

防火牆配置網址
https://www.cnblogs.com/moxiaoan/p/5683743.html

 

1、firewalld的基本使用

 

啟動: systemctl start firewalld

 

關閉: systemctl stop firewalld

 

查看狀態: systemctl status firewalld 

 

開機禁用  : systemctl disable firewalld

 

開機啟用  : systemctl enable firewalld

 

•停止Apache:/usr/local/apache2/bin/apachectl stop
•重啟Apache:/usr/local/apache2/bin/apachectl restart

在瀏覽器中通過http://192.168.0.208:80,如果看到頁面中顯示“It works!”字樣,則代表Apache驗證
通過。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM