Apache安裝搭建

Linux系統下安裝Apache服務器

第一步命令安裝apache:

yum install httpd httpd-devel –y

2.第二步執行命令:開啟服務器

systemctl start httpd.service

執行下面命令,使服務器隨Linux的啟動而啟動:

systemctl enable httpd.service

.做到這裡還是不行的,因為Linux系統中的防火牆會沒有給Apache開放端口,所以需要做以下操作:

firewall-cmd --zone=public --add-port=80/tcp –permanent

firewall-cmd –reload

.此時就可以在瀏覽器地址欄輸入服務器的ip地址訪問了,可以看到這樣的界面:

這樣apache服務器就成功安裝完成!5.安裝完成以後apache默認的安裝地址為 etc/httpd/conf/httpd.conf我們可以自定義apache的默認路徑首先在一個目錄下面創建一個文件夾如:在home文件下架創建一個html文件夾

切換路徑到home文件夾下:

cd /home

mkdir html

然後在打開apache原來的配置文件:

vi /etc/httpd/conf/httpd.conf

打開配置文件後將裡面的/var/www/html/ 修改為/home/dic

.做到這裡還是出問題.訪問ip時會出現這個問題

Apache安裝搭建

問題出現原因是 Linux系統中SELinux關閉訪問引起的SELinux一共有三種狀態分別是Enforcing,Permissive和Disabled狀態,

執行命令 setenforce 0

臨時關閉SELinux,就可以執行,但是下次重啟服務器時,SELinux還是會恢復原始狀態,所以找到SELnux的配置文件設置為disable狀態

vi /etc/selinux/config

·

重啟linux系統就可以了!完結!!


第二種方式源碼安裝

Apache安裝搭建

usr/local/apache2/bin/apachectl start 開啟服務

常見報錯

apache常見錯誤總結:1、./configure報錯Configuring Apache Portable Runtime library ...

checking for APR... configure: error: the --with-apr parameter is incorrect. It must specify an install prefix, a build directory, or an apr-config file.解決辦法:下載安裝apr:http://apache.etoak.com//apr/apr-1.4.6.tar.gzapr-utils:http://apache.etoak.com//apr/apr-util-1.4.1.tar.gz或者yum -y install apr apr-util

checking for pcre-config... falseconfigure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/解決辦法:[[email protected] httpd-2.4.1]# yum -y install pcre-devel2、啟動報錯:[[email protected] bin]# service apache startAH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this messagehttpd (pid 912) already running其實在這裡並不是報錯,只是個提醒信息,解決辦法比較多(1)、在/etc/hosts寫下當前ip與主機名的對應關係(2)、在本機指能解析本機主機名的DNS(3)、修改主配置文件,找到ServerName這一行寫入本機主機名


分享到:


相關文章: