第一種方法(centos、Redhat)yum安裝:
一、用yum安裝Apache服務
yum install -y http*html
二、啓動Apache服務
systemctl start httpdapache
三、查看Apache服務端口號和進程
netstat -anptu|grep http
ps -aux |grep httpubuntu
四、直接在瀏覽器輸入ip地址訪問
http://ip地址vim
備註:
Apache配置文件
/etc/httpd/conf/httpd.conf
網頁配置文件
/etc/httpd/conf.d/welcome.conf
網頁文件
/usr/share/httpd/noindex/index.htmlcentos
修改網頁文件改成本身製做的網頁
網頁配置文件能夠改網頁文件路徑瀏覽器
第二種方法(ubuntu、centos、Redhat)編譯安裝:
apache 安裝指南:http://httpd.apache.org/docs/2.4/install.html
編譯安裝說明:
在編譯安裝apache時,首先要先安裝Apache依賴環境
即
ubuntu@ubuntu:~$ ls
apr-1.6.3.tar.gz apr-util-1.6.1 apr-util-1.6.1.tar.gz pcre-8.39 pcre-8.39.tar.gztcp
1.編譯安裝apache有些依賴環境必須安裝,否則後面編譯會報找不到相應多文件:ide
APR(Apache portable Run-time libraries,Apache可移植運行庫)和APR-Util,apr介紹能夠參見:http://www.cnblogs.com/iLumia/p/4214886.html
下載地址:http://apr.apache.org/.net
PCRE庫 若是沒有安裝過pcre的話,請先下載:https://sourceforge.net/projects/pcre/files/pcre/8.39/pcre-8.39.tar.gz/download
除此以外,還有些磁盤空間要求,C編譯器,時間同步,Perl5 能夠根據須要,自行調整便可。code
2.安裝apr
ubuntu@ubuntu:~$ cd apr-1.6.3/ #進入下載的apr目錄下
./configure --prefix=/usr/local/apache/apr #指定安裝目錄
make -j4(根據本身電腦核數×2來設定並行編譯參數,提升編譯速度)
sudo make install
3.安裝apr-util
ubuntu@ubuntu:~$ cd apr-util-1.6.1/ #進入下載的apr-util目錄下
./configure --prefix=/usr/local/apache/apr-util --with-apr=/usr/local/apache/apr #指定安裝目錄和apr
make -j4
make install
4.安裝pcre
ubuntu@ubuntu:~$ cd pcre-8.39/ #進入下載的pcre目錄下
./configure --prefix=/usr/local/pcre #指定安裝目錄
make -j4
make install
5.安裝好依賴環境就能夠開始安裝Apache
ubuntu@ubuntu:~$ cd httpd-2.4.33/ #進入下載的apache目錄下
./configure --prefix=/usr/local/apache --with-apr=/usr/local/apache/apr --with-apr-util=/usr/local/apache/apr-util/ --with-pcre=/usr/local/pcre
make -j4
make install
到此Apache編譯安裝結束
6.添加啓動腳本
cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
7.添加環境變量
echo 'export PATH=$PATH:/usr/local/apache/bin' > /etc/profile.d/httpd.sh
chmod 777 /etc/profile.d/httpd.sh
source /etc/profile.d/httpd.sh
備註:以後就能夠多種方式管理httpd了,若是須要開機自啓,將啓動命令添加到/etc/rc.local 中便可。
注意:
sudo /usr/local/apache/bin/apachectl start
可能會報錯說端口被佔用,須要修改httpd.conf文件
sudo vim /usr/local/apache/conf/httpd.conf
而後把ServerName行改爲ServerName 本地ip:80
把Listen 80行改爲Listen 本地ip:80
而後保存,啓動apache服務.
service httpd start
Apache配置文件
/usr/local/apache/conf/httpd.conf
啓動文件
/etc/init.d/httpd
網頁界面顯示文件
/usr/local/apache/htdocs/index.html
Apache進程
ubuntu@ubuntu:/usr/local/apache/conf$ ps -ef |grep http
root 965 1 0 17:55 ? 00:00:00 /usr/local/apache/bin/httpd -k start
daemon 966 965 0 17:55 ? 00:00:00 /usr/local/apache/bin/httpd -k start
daemon 967 965 0 17:55 ? 00:00:00 /usr/local/apache/bin/httpd -k start
daemon 968 965 0 17:55 ? 00:00:00 /usr/local/apache/bin/httpd -k start
daemon 1054 965 0 17:56 ? 00:00:00 /usr/local/apache/bin/httpd -k start
ubuntu 1133 921 0 18:37 pts/0 00:00:00 grep --color=auto http
端口
ubuntu@ubuntu:/usr/local/apache/conf$ sudo netstat -anptu|grep 80
[sudo] password for ubuntu:
tcp 0 0 192.168.91.130:80 0.0.0.0:* LISTEN 965/httpd
Apache啓動狀態
ubuntu@ubuntu:/usr/local/apache/conf$ sudo service httpd status
● httpd.service
Loaded: loaded (/etc/init.d/httpd; bad; vendor preset: enabled)
Active: active (running) since Tue 2018-07-17 17:55:23 PDT; 43min ago
Docs: man:systemd-sysv-generator(8)
Process: 961 ExecStart=/etc/init.d/httpd start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/httpd.service
├─ 965 /usr/local/apache/bin/httpd -k start
├─ 966 /usr/local/apache/bin/httpd -k start
├─ 967 /usr/local/apache/bin/httpd -k start
├─ 968 /usr/local/apache/bin/httpd -k start
└─1054 /usr/local/apache/bin/httpd -k start
Jul 17 17:55:23 ubuntu systemd[1]: Starting httpd.service...Jul 17 17:55:23 ubuntu systemd[1]: Started httpd.service.