1. 程式人生 > >如何搭建apache服務?

如何搭建apache服務?

span blog 永久 準備 kconfig UC 比較 ron sel

為了日後便於查詢,本文所涉及到的所有命令集合如下:

chkconfig iptables off  #關閉防火墻命令  在Centos7中使用的是chkconfig firewalld off
vi /etc/sysconfig/selinux  #打開selinux配置文件
yum install httpd -y  #安裝httpd軟件
vi /etc/httpd/conf/httpd.conf #配置httpd文件
service httpd restart    #重啟httpd服務

什麽是apache服務?


apache服務就是用來部署網站的服務。其對應的軟件名就httpd

開啟apache服務


1.準備環境

  • 永久關閉防火墻
    chkconfig iptables off  #關閉防火墻命令  在Centos7中使用的是chkconfig firewalld off
  • 關閉selinux
    vi /etc/sysconfig/selinux  #打開selinux配置文件

    打開selinux配置文件,其中的SELINUX選項改為disabled

  • 技術分享圖片

  • 配置IP地址

2.進行httpd軟件的安裝

使用命令

yum install httpd -y  #安裝httpd軟件

進行httpd軟件的安裝

3.修改配置文件

使用命令

vi /etc/httpd/conf/httpd.conf

其中比較關鍵的配置項有以下幾個

  • Listen 80 說明監聽端口為80
  • DocumentRoot "/var/www/html" 文檔根目錄

4.重啟服務

使用命令

service httpd restart

進行apache服務的重啟生效操作

5.測試

在DocumentRoot目錄也就是 /var/www/html新建一個文件

使用以下命令隨便創建一個文件

cd /var/www/html/  #進入文檔根目錄
touch hello.txt     #創建文件
echo "hello world" > hello.txt    #在文件中寫入內容
    

回到windows中打開瀏覽器輸入ip/文件正常訪問,如果無法訪問請再次檢查防火墻

技術分享圖片

關於apache的知識就講到這裏,感謝各位看官

如何搭建apache服務?