Centos 下Apache(httpd) 安装过程

其实,网上这块的部署文章非常多 。随便搜索,都有 。

这篇文章,老徐帮大家挑选几个比较重点的过程 & 命令 。

1. 有些linux 版本中已经预置了有Apache,并且已经是服务了,所有首先检查系统中是否已经存在httpd的服务

1)先检查服务器 上是否已经启动了此服务 。

命令如下

ps -ef|grep httpd

2)查看linux系统服务中有没有httpd

chkconfig --list | grep httpd

3)如果有服务存在,那么需要先关闭httpd服务自启动
命令 chkconfig httpd off

4)停止httpd服务
命令 service httpd stop

5)再次查看,是否有进程存在
命令 ps -ef|grep httpd

6)如果有进程存在,关闭进程
命令 kill -9 pid

  1. 卸载httpd

1)先检查安装包 的名字

命令 rpm -qa|grep httpd

<pre style="box-sizing: border-box; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; white-space: pre-wrap; display: block; padding: 9.5px; margin: 0px 0px 10px; line-height: 1.38462; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); border-radius: 4px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">[root@istester]~# rpm -qa|grep httpd
httpd-2.2.15-69.el6.centos.x86_64
httpd-tools-2.2.15-69.el6.centos.x86_64</pre>

2)根据安装包名字删除包

rpm -e httpd-tools-2.2.15-69.el6.centos.x86_64

rpm -e httpd-2.2.15-69.el6.centos.x86_64

3)删除httpd.conf文件

<pre class="prettyprint" style="box-sizing: border-box; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; white-space: pre-wrap; display: block; padding: 9.5px; margin: 0px 0px 10px; line-height: 1.38462; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); border-radius: 4px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">#先检查文件在哪
find / -name httpd.conf

查出之后根据路径逐一删除

rm /xxx/xxx/httpd.conf</pre>

3. 准备事项已完成,剩下的就是常规安装了 。

注:我们通过yum的方式,在线安装,非常简单 。

1)检查是否存在httpd包

<pre style="box-sizing: border-box; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; white-space: pre-wrap; display: block; padding: 9.5px; margin: 0px 0px 10px; line-height: 1.38462; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); border-radius: 4px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">[www@istester ~]$ yum list httpd
Loaded plugins: security
base | 3.7 kB 00:00
epel | 4.7 kB 00:00
epel/primary_db | 6.0 MB 00:00
extras | 3.4 kB 00:00
extras/primary_db | 28 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 3.2 MB 00:00
Available Packages
httpd.x86_64 2.2.15-69.el6.centos base</pre>

2、安装Apache
yum install httpd

<pre style="box-sizing: border-box; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; white-space: pre-wrap; display: block; padding: 9.5px; margin: 0px 0px 10px; line-height: 1.38462; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); border-radius: 4px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">Total 20 MB/s | 932 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : apr-util-ldap-1.3.9-3.el6_0.1.x86_64 1/4
Updating : httpd-tools-2.2.15-69.el6.centos.x86_64 2/4
Installing : httpd-2.2.15-69.el6.centos.x86_64 3/4
Cleanup : httpd-tools-2.2.15-53.el6.centos.x86_64 4/4
Verifying : httpd-tools-2.2.15-69.el6.centos.x86_64 1/4
Verifying : httpd-2.2.15-69.el6.centos.x86_64 2/4
Verifying : apr-util-ldap-1.3.9-3.el6_0.1.x86_64 3/4
Verifying : httpd-tools-2.2.15-53.el6.centos.x86_64 4/4

Installed:
httpd.x86_64 0:2.2.15-69.el6.centos

Dependency Installed:
apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1

Dependency Updated:
httpd-tools.x86_64 0:2.2.15-69.el6.centos

Complete!</pre>

安装过程,不用理会,如果看到如上提示,说明安装成功了。

3、设置Apache服务的启动级别
chkconfig --levels 235 httpd on
Apache是一个服务,所以,可以通过设置服务的启动级别来让它启动。

4、启动服务

两种方式,

1)如下 /etc/init.d/httpd start

2)如下

service httpd start

5、查看服务是否正常启动

两种方式,

1)查看服务状态

<pre style="box-sizing: border-box; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; white-space: pre-wrap; display: block; padding: 9.5px; margin: 0px 0px 10px; line-height: 1.38462; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); border-radius: 4px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">[root@istester www]# service httpd status
httpd (pid 10339) is running...</pre>

2)查看进程

<pre style="box-sizing: border-box; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; white-space: pre-wrap; display: block; padding: 9.5px; margin: 0px 0px 10px; line-height: 1.38462; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); border-radius: 4px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">[root@istester www]# ps -ef|grep httpd | grep -v grep
root 10339 1 0 23:15 ? 00:00:00 /usr/sbin/httpd
apache 10341 10339 0 23:15 ? 00:00:00 /usr/sbin/httpd
apache 10342 10339 0 23:15 ? 00:00:00 /usr/sbin/httpd
apache 10343 10339 0 23:15 ? 00:00:00 /usr/sbin/httpd
apache 10344 10339 0 23:15 ? 00:00:00 /usr/sbin/httpd
apache 10345 10339 0 23:15 ? 00:00:00 /usr/sbin/httpd
apache 10346 10339 0 23:15 ? 00:00:00 /usr/sbin/httpd
apache 10347 10339 0 23:15 ? 00:00:00 /usr/sbin/httpd
apache 10348 10339 0 23:15 ? 00:00:00 /usr/sbin/httpd</pre>

补充,

1)停止服务

service httpd stop

2)重启服务

service httpd restart

6、安装之后的说明:

1)验证是否安装成功
现在打开http://ip 地址,看看有没有Apache的默认页面出来了?如果有就对了。

2)安装目录说明
Apache默认将网站的根目录指向/var/www/html
默认的主配置文件是/etc/httpd/conf/httpd.conf
配置存储在的/etc/httpd/conf.d/目录

End

文 / IDO老徐

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,524评论 5 460
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,869评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,813评论 0 320
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,210评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,085评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,117评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,533评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,219评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,487评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,582评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,362评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,218评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,589评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,899评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,176评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,503评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,707评论 2 335

推荐阅读更多精彩内容