學習目標:apache在linux上的應用,經過三種方式在瀏覽器上訪問php
LAMP:linux+apache+MYSQL+phphtml
wamp:windows+apache+MYSQL+phplinux
linux上安裝apacheapache
1.安裝:yum -y install httpdwindows
查找:whereis httpdcentos
etc/httpd]: conf 主配置文件目錄主要有 httpd.conf瀏覽器
conf.d/*.conf 自定義配置文件安全
logs :日誌文件,訪問日誌錯誤日誌服務器
lib:模塊app
若是apache安裝成爲linux的服務的話,能夠用如下命令操做:
service httpd start 啓動
service httpd restart 從新啓動
service httpd stop 中止服務
service httpd status查看httpd的運行狀態
rpm -qa | grep httpd查看httpd是否已經安裝
ps -ef | grep httpd命令能夠查看httpd是否應運行
若是是使用默認的80端口,啓動後,能夠在瀏覽器中輸入下圖所示的localhost來測試httpd服務
2.啓動:service httpd start
在windows地址欄輸入ip地址,端口默認80
若是不能打開,檢查 httpd]:vi /conf/httpd.conf裏的ServerName localhost:80有沒有註釋掉
3.
cd /var/www/html
echo "hello apache" > index.html
ll
mv index.html demo.html
4.配置文件的節點
cd /etc/httpd
httpd]:ll conf
httpd]:ll conf.d
httpd]:vi /conf/httpd.conf
配置文件:listen :端口:80
document root:站點目錄
servername:主機名,域名
directory:配置站點目錄參數
directory index:配置站點目錄,默認首頁
errorlog:錯誤日誌
customlog:訪問日誌
virtual host:虛擬主機配置節
5.經過三種方式進行瀏覽器的訪問
建立目錄:mkdir /var/www/baseip1
....................../baseip2
....................../port1
....................../port2
......................./school
......................./person
conf.d]:vi virtual.conf(由於conf.d是附屬配置文件)
base :id
base:port
base:domain
基於ip訪問的設置:
1.vi virtual.conf
2.ifconfig
3.ifconfig etho:1 172.19.105.200 netmask 255.255.255.0
ifconfig etho:2 172.19.102.201 netmask 255.255.255.0
4.conf.d] : vi virtual.conf (注意.conf結尾)
<VirtualHost 172.19.105.200>
ServerName 172.19.105.200 (可加可不加)
DocumentRoot /var/www/baseip1
</VirtualHost>
<VirtualHost 172.19.105.201>
ServerName 172.19.105.201(可加可不加)
DocumentRoot /var/www/baseip1
</VirtualHost>
5.echo "172.19.105.200" > /var/www/baseip1/index.html
echo "172.19.105.201" > /var/www/baseip2/index.html
6.關閉防火牆:service iptables stop或者systemctl stop firewalld.service
7.service httpd restart
基於端口訪問的設置:
1. echo "port81" > /var/www/port1/index.html
echo "port82" > /var/www/port2/index.html
2.vi virtual.conf (端口號有的不能用,致使沒法重啓,可換下數字試試)
Listen 81(L大寫)
NameVirtualHost 172.19.105.5:81
<VirtualHost 172.19.105.5:81>
ServerName 172.19.105.5:81
DocumentRoot /var/www/port1
</VirtualHost>
Listen 82(L大寫)
NameVirtualHost 172.19.105.5:82
<VirtualHost 172.19.105.5:82>
ServerName 172.19.105.5:82
DocumentRoot /var/www/port2
</VirtualHost>
3.重啓服務:service httpd restart
基於域名的訪問設置:
1. echo "school" > /var/www/school/index.html
echo "person" > /var/www/person/index.html
2. vi virtual.conf
NameVirtualHost 172.19.105.5:80
<VirtualHost 172.19.105.5:80>
ServerName www.school.top
DocumentRoot /var/www/school
</VirtualHost>
NameVirtualHost 172.19.105.5:80
<VirtualHost 172.19.105.5:80>
ServerName www.person.top
DocumentRoot /var/www/person
</VirtualHost>
3.DNS域名的添加
位置 C:\WINDOWS\system32\drivers\etc\hosts
172.19.105.5 www.school.top
172.19.105.5 www.person.top(注意有哪些域名)
4.重啓服務
service httpd restart
注意點:防火牆:iptables
安全訪問:SElinux
訪問形式:經過瀏覽器進行訪問,默認端口號80
353行是這一行,要把註釋去掉,否則在不添加任何文本時,
再也不訪問默認的testing首頁面
353 IncludeOptional conf.d/*.conf
centos7:防火牆的啓動關閉
查詢:firewall-cmd-state
開啓服務
# systemctl start firewalld.service
關閉防火牆
# systemctl stop firewalld.service
開機自動啓動
# systemctl enable firewalld.service
關閉開機制動啓動
# systemctl disable firewalld.service
查看選項:grep options /etc/httpd/conf/httpd.conf
去掉註釋節:grep -Ev '^(#|$)' /etc/httpd/conf/httpd.conf
windows上安裝apache
1.進入apache服務器官網http://httpd.apache.org/,這裏咱們如下載穩定版的
httpd 2.2.29爲例,點擊download
因爲官方網頁改版,之前的方式可能五法進行下載,爲了避免浪費你們的時間,特此修正2015-01-24
第一步依舊是點擊download
點擊連接Files for Microsoft Windows
The Apache HTTP Server Project itself does not provide binary releases of software, only source code. Individual committers may provide binary packages as a convenience, but it is not a release deliverable.
If you cannot compile the Apache HTTP Server yourself, you can obtain a binary package from numerous binary distributions available on the Internet.
Popular options for deploying Apache httpd, and, optionally, PHP and MySQL, on Microsoft Windows, include:
ApacheHaus
Apache Lounge
BitNami WAMP Stack
WampServer
XAMPP
大體意思是說apache自己不提供已編譯的安裝包,只提供源碼,若是你本身沒法編譯,能夠選擇下面這些官方推薦的第三方提供編譯的網站。
其中後兩個是有名的wamp以及xampp集成環境,若是隻想下載apache能夠選擇前三個網站,這裏咱們第一個ApacheHaus爲例。
打開ApacheHaus以後你會發現這個網站上有各類windows版本,能夠盡情選擇你要下載的版本。
點擊紅框中的圖標便可開始下載,x86是32位的,x64是64位的,根據本身的操做系統選擇下載
看電腦有沒有安裝軟件相應的運行包,好比你下載的是VC9版本,那麼你須要先安裝Microsoft Visual C++ 2008 Redistributable ,同理VC11版本你須要安裝Microsoft Visual C++ 2012 Update 4 Redistributable Package (X86 & x64)
在ApacheHaus網站的最底部提供了相應的Visual Studio Redistributable Packages下載連接
解壓後是一個壓縮包,把他移動到你想放置的地方。
命令行下進入到apache下面的bin目錄,輸入
httpd -k install
把apache安裝成windows後臺服務。
利用ApacheMonitor來啓動你的apache
The Apache Monitor is a desktop tray application that allows you to monitor the existence of a running Apache service and easily start, stop and restart Apache. To use it just double click on the ApacheMonitor.exe in the \Apache24\bin folder. If you want it to start automatically for you when you log into the computer, just drag a copy into the Startup folder in Window's Start Menu.
針對你們遇到的一些問題作下簡單總結 windows上的安裝
一、因爲apache默認是監聽80端口,若是你的電腦iis是啓動狀態,而且也使用了80端口,apache將沒法正常啓動,須要先中止iis,另外迅雷也可能會使用80端口,因此也要關閉迅雷。查看80端口是否被佔用,命令行下輸入:
netstat -aon|findstr "80"
若是看到如圖的結果,說明80端口已被使用,須要先關閉相關軟件,或者修改apache默認的監聽端口
打開apache目錄下的conf/httpd.conf 搜索 "Listen 80"
修改成Listen 8088
保存以後再從新啓動apache
二、httpd -k install 輸入該命令後查看服務是否安裝成功
開始-->運行-->services.msc-->肯定
打開後若是在服務列表可以看到apache字樣,說明,服務安裝成功,能夠直接點擊左邊的啓動按鈕來啓動服務
三、服務沒法正常安裝,首先肯定軟件32位和64位是否和本身的系統匹配
其次,看電腦有沒有安裝軟件相應的運行包,好比你下載的是VC9版本,那麼你須要先安裝Microsoft Visual C++ 2008 Redistributable ,同理VC11版本你須要安裝Microsoft Visual C++ 2012 Update 4 Redistributable Package (X86 & x64)
在ApacheHaus網站的最底部提供了相應的Visual Studio Redistributable Packages下載連接