天天看點

Red Hat 7 Apache 安裝與配置Apache服務安裝與配置

Apache服務安裝與配置

檢測主機中是否安裝Apache

rpm -qa | grep httpd
           

安裝Apache指令

yum -y install httpd
           
如果安裝錯誤請參考 Yum配置安裝 https://blog.csdn.net/qq_39906884/article/details/84139028

檢視 Apache 狀态

systemctl status httpd.service
           
Red Hat 7 Apache 安裝與配置Apache服務安裝與配置

啟動 Apache

再次檢視 Apache 狀态

systemctl start httpd.service
systemctl status httpd.service
           
Red Hat 7 Apache 安裝與配置Apache服務安裝與配置

設定 Apache 開機啟動

systemctl enable httpd.service
           

檢視本機的IP位址

打開浏覽器, 網址輸入本機ip位址或者localhost, 為以下内容說明正确打開了 Apache 服務

Red Hat 7 Apache 安裝與配置Apache服務安裝與配置

打開防火牆

Red Hat 7 Apache 安裝與配置Apache服務安裝與配置

http 服務打勾

Red Hat 7 Apache 安裝與配置Apache服務安裝與配置

在另一台主機上打開浏覽器網址填寫伺服器ip位址 , 可以檢視與伺服器一樣的内容

Red Hat 7 Apache 安裝與配置Apache服務安裝與配置

檔案介紹

Apache伺服器配置檔案: /etc/httpd/conf/httpd.conf

Web站點的相關檔案目錄: /var/www

Web站點根目錄: /var/www/html

Web站點的日志檔案目錄: /var/log/httpd

在Web站點根目錄: /var/www/html下放入寫好的index.html檔案, 然後然後再浏覽器輸入伺服器IP, 顯示index.html内容

設定個人Web站點配置

修改 /etc/httpd/conf.d/userdir.conf 檔案

将17行的 UserDir disabled 注釋, 解除24行UserDir public_html 的注釋

Red Hat 7 Apache 安裝與配置Apache服務安裝與配置

設定SELinux打開對主目錄的通路(加**-P**選項代表永久打開)

setsebool -P httpd_enable_homedirs on
           

切換使用者(用dou使用者為例),

在家目錄建立public_html目錄,

修改家目錄權限

su - dou
chmod 755 -R /home/dou
           

随後重新開機Apache服務

systemctl restart httpd.service 
           

在浏覽器輸入 伺服器IP/~dou, 顯示出來index.html的網頁内容

Red Hat 7 Apache 安裝與配置Apache服務安裝與配置

繼續閱讀