使用yum命令安装Apache
由于 CentOS 已经封装了 Apache,直接运行安装:1
[root@iZ23i2txh8jZ ~]# yum install httpd
同样配置系统让 Apache 随系统启动:1
[root@iZ23i2txh8jZ ~]# chkconfig --levels 235 httpd on
配置完毕,启动 Apache:1
[root@iZ23i2txh8jZ ~]# /etc/init.d/httpd start
如果在启动过程中出现:1
2
3
4[root@iZ23i2txh8jZ ~]# /etc/init.d/httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 10.168.213.151 for ServerName
[ OK ]
[root@iZ23i2txh8jZ ~]# /etc/init.d/httpd start
那就修改一下httpd.conf1
[root@iZ23i2txh8jZ ~]# vi /etc/httpd/conf/httpd.conf
找到#ServerName www.example.com:80 加入如下内容:1
2#ServerName www.example.com:80
ServerName localhost:80
然后重启apache1
[root@iZ23i2txh8jZ ~]# /etc/init.d/httpd restart
成功!!1
2
3
4[root@iZ23i2txh8jZ ~]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@iZ23i2txh8jZ ~]#
注意:在 CentOS 中 Apache 的默认根目录是 /var/www/html,配置文件 /etc/httpd/conf/httpd.conf。其他配置存储在 /etc/httpd/conf.d/ 目录。