Linux Centos安装及卸载Apache
一.卸载
1.查看有没有安装apache,出现下面信息则安装过
[root@localhost ~]# rpm -qa|grep httpd
httpd-2.2.15-53.el6.centos.x86_64
httpd-tools-2.2.15-53.el6.centos.x86_64
2.执行卸载命令,出现下面信息则要先卸载 gnome-user-share
[root@localhost ~]# rpm -e httpd
error: Failed dependencies:
httpd >= 2.2.0 is needed by (installed) gnome-user-share-2.28.2-3.el6.x86_64
3.卸载 gnome-user-share
[root@localhost ~]# rpm -e gnome-user-share
4.卸载完成后再执行卸载命令
[root@localhost ~]# rpm -e httpd
5.查看是否还存在其他apache包,用命令卸载
[root@localhost backend]# rpm -qa|grep httpd
httpd-tools-2.2.15-53.el6.centos.x86_64
#用命令 rpm -e xxxx --nodeps 命令卸载
[root@localhost backend]# rpm -e httpd-tools-2.2.15-53.el6.centos.x86_64 --nodeps
二.安装
1.安装命令
yum install httpd
2.查看,如果出现下面信息则安装完成
[root@localhost ~]# rpm -qa httpd
httpd-2.2.15-53.el6.centos.x86_64
3.启动
#启动
[root@localhost ~]# service httpd start Starting httpd: [ OK ]
#查看进程 [root@localhost ~]# ps -ef|grep httpd root 3710 1 0 20:58 ? 00:00:00 /usr/sbin/httpd apache 3713 3710 0 20:58 ? 00:00:00 /usr/sbin/httpd apache 3714 3710 0 20:58 ? 00:00:00 /usr/sbin/httpd apache 3715 3710 0 20:58 ? 00:00:00 /usr/sbin/httpd apache 3716 3710 0 20:58 ? 00:00:00 /usr/sbin/httpd apache 3717 3710 0 20:58 ? 00:00:00 /usr/sbin/httpd apache 3718 3710 0 20:58 ? 00:00:00 /usr/sbin/httpd apache 3719 3710 0 20:58 ? 00:00:00 /usr/sbin/httpd apache 3720 3710 0 20:58 ? 00:00:00 /usr/sbin/httpd root 3723 3634 0 20:58 pts/2 00:00:00 grep httpd
4.修改apache的路径和默认80端口
(1)修改配置文件
[root@localhost ~]# vi /etc/httpd/conf/httpd.conf
(2)修改端口号,改为82端口
(3)添加ServerName属性,localhost后面跟上修改的端口号82
(4)修改apache的默认目录,以 /usr/java/apache 路径为例
(5)启动apache失败,出现下面错误,则要安装 semanage
[root@localhost /]# service httpd start
Starting httpd: (13)Permission denied: make_sock: could not bind to address [::]:82
(13)Permission denied: make_sock: could not bind to address 0.0.0.0:82
no listening sockets available, shutting down
Unable to open logs
[FAILED]
(6)安装 semanage 命令
yum provides /usr/sbin/semanage
(7)安装 policycoreutils-python 命令
yum -y install policycoreutils-python
(8)查看端口,没有包含82端口,则要手动添加
[root@localhost ~]# semanage port -l|grep http
http_cache_port_t tcp 3128, 8080, 8118, 8123, 10001-10010
http_cache_port_t udp 3130
http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000
pegasus_http_port_t tcp 5988
pegasus_https_port_t tcp 5989
(9)添加82端口
[root@localhost ~]# semanage port -a -t http_port_t -p tcp 82
[root@localhost ~]# semanage port -l|grep http
http_cache_port_t tcp 3128, 8080, 8118, 8123, 10001-10010
http_cache_port_t udp 3130
http_port_t tcp 82, 80, 81, 443, 488, 8008, 8009, 8443, 9000
pegasus_http_port_t tcp 5988
pegasus_https_port_t tcp 5989
(10)添加成功重启apache
[root@localhost ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@localhost ~]# ps -ef|grep httpd
root 4402 1 0 21:21 ? 00:00:00 /usr/sbin/httpd
apache 4405 4402 0 21:21 ? 00:00:00 /usr/sbin/httpd
apache 4406 4402 0 21:21 ? 00:00:00 /usr/sbin/httpd
apache 4407 4402 0 21:21 ? 00:00:00 /usr/sbin/httpd
apache 4408 4402 0 21:21 ? 00:00:00 /usr/sbin/httpd
apache 4409 4402 0 21:21 ? 00:00:00 /usr/sbin/httpd
apache 4410 4402 0 21:21 ? 00:00:00 /usr/sbin/httpd
apache 4411 4402 0 21:21 ? 00:00:00 /usr/sbin/httpd
apache 4412 4402 0 21:21 ? 00:00:00 /usr/sbin/httpd
root 4415 4226 0 21:22 pts/1 00:00:00 grep httpd