首页 > 系统相关 >Linux 安装Httpd服务

Linux 安装Httpd服务

时间:2022-10-11 11:14:07浏览次数:71  
标签:Httpd httpd apr root centos7 -- Linux httpd24 安装

安装Httpd服务

版本说明:
CentOS 7 以上,默认系统是httpd 2.4,CentOS 6 版默认为httpd 2.2
Ubuntu 18.04 默认 Apache/2.4.29

范例:CentOS 8 安装httpd
[root@CentOS8 ~]# yum info httpd
Baseos                                                                                                                           3.8 MB/s | 3.9 kB     00:00    
AppStream                                                                                                                        4.2 MB/s | 4.3 kB     00:00    
EPEL                                                                                                                             7.1 kB/s | 4.7 kB     00:00    
EPEL                                                                                                                             1.1 MB/s |  13 MB     00:11    
Available Packages
Name         : httpd
Version      : 2.4.37
Release      : 30.module_el8.3.0+561+97fdbbcc
Architecture : x86_64
Size         : 1.7 M
Source       : httpd-2.4.37-30.module_el8.3.0+561+97fdbbcc.src.rpm
Repository   : AppStream
Summary      : Apache HTTP Server
URL          : https://httpd.apache.org/
License      : ASL 2.0
Description  : The Apache HTTP Server is a powerful, efficient, and extensible
             : web server.

[root@CentOS8 ~]# yum install httpd -y 
Last metadata expiration check: 0:00:21 ago on Mon 10 Oct 2022 10:57:38 PM CST.
Dependencies resolved.
=================================================================================================================================================================
 Package                                Architecture               Version                                                   Repository                     Size
=================================================================================================================================================================
Installing:
 httpd                                  x86_64                     2.4.37-30.module_el8.3.0+561+97fdbbcc                     AppStream                     1.7 M
Installing dependencies:
 apr                                    x86_64                     1.6.3-11.el8                                              AppStream                     125 k
 apr-util                               x86_64                     1.6.1-6.el8                                               AppStream                     105 k
 centos-logos-httpd                     noarch                     80.5-2.el8                                                Baseos                         24 k
 httpd-filesystem                       noarch                     2.4.37-30.module_el8.3.0+561+97fdbbcc                     AppStream                      37 k
 httpd-tools                            x86_64                     2.4.37-30.module_el8.3.0+561+97fdbbcc                     AppStream                     104 k
 mod_http2                              x86_64                     1.15.7-2.module_el8.3.0+477+498bb568                      AppStream                     154 k
Installing weak dependencies:
 apr-util-bdb                           x86_64                     1.6.1-6.el8                                               AppStream                      25 k
 apr-util-openssl                       x86_64                     1.6.1-6.el8                                               AppStream                      27 k
Enabling module streams:
 httpd                                                             2.4                                                                                          

Transaction Summary
=================================================================================================================================================================
Install  9 Packages

Total size: 2.3 M
Installed size: 6.0 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
 ..............
Installed:
  apr-1.6.3-11.el8.x86_64                                                           apr-util-1.6.1-6.el8.x86_64                                                 
  apr-util-bdb-1.6.1-6.el8.x86_64                                                   apr-util-openssl-1.6.1-6.el8.x86_64                                         
  centos-logos-httpd-80.5-2.el8.noarch                                              httpd-2.4.37-30.module_el8.3.0+561+97fdbbcc.x86_64                          
  httpd-filesystem-2.4.37-30.module_el8.3.0+561+97fdbbcc.noarch                     httpd-tools-2.4.37-30.module_el8.3.0+561+97fdbbcc.x86_64                    
  mod_http2-1.15.7-2.module_el8.3.0+477+498bb568.x86_64                            

Complete!
[root@CentOS8 ~]# systemctl enable httpd
httpd@          httpd.service   [email protected]  httpd.socket    
[root@CentOS8 ~]# systemctl enable httpd.service --now 
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@CentOS8 ~]# httpd -v
Server version: Apache/2.4.37 (centos)
Server built:   Nov  4 2020 03:20:37

范例:Ubuntu 1804 安装apache2
tom@ubuntu1804-1:~$ apt install apache2 -y
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
tom@ubuntu1804-1:~$ sudo apt install apache2 -y
[sudo] password for tom: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 ssl-cert
Suggested packages:
............
Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service → /lib/systemd/system/apache2.service.
Created symlink /etc/systemd/system/multi-user.target.wants/apache-htcacheclean.service → /lib/systemd/system/apache-htcacheclean.service.
Processing triggers for libc-bin (2.27-3ubuntu1.4) ...
Processing triggers for systemd (237-3ubuntu10.52) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for ufw (0.36-0ubuntu0.18.04.1) ...
Processing triggers for ureadahead (0.100.0-21) ...
tom@ubuntu1804-1:~$ apache2 -v
Server version: Apache/2.4.29 (Ubuntu)
Server built:   2022-06-23T12:51:37

apache和httpd它们是同一应用程序
只是某些Linux发行版在程序包管理器和配置文件中对它的引用有所不同。
基于RedHat的发行版(CentOS,Fedora)将其称为httpd,
而基于Debian的发行版(Ubuntu)将其称为apache

源码安装httpd服务

ABI和API:
  • 不同操作系统的API和ABI规范不同,软件要运行再不同的操作系统上就需要遵守不同操作系统的接口标准。

  • 在早期的Apache版本中,应用程序本身必须能够处理各种具体操作系统平台的细节,并针对不同的平台调用不同的处理函数

  • 随着Apache的进一步开发,Apache组织决定将这些通用的函数独立出来并发展成为一个新的项目。这样,APR的开发就从Apache中独立出来,Apache仅仅是使用 APR而已

APR:

Apache portable Run-time libraries,Apache可移植运行库,主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库。

APR官网:http://apr.apache.org

所以要编译安装httpd,就需要先安装apr和apr-util这两个可移植的运行库。

范例:CentOS7编译安装httpd2.4

安装httpd-2.4,依赖于apr-1.4+, apr-util-1.4+ (1.4以上的版本)

1.下载软件包并安装编译工具
下载apr包和httpd包
https://httpd.apache.org/
http://apr.apache.org

安装编译工具
[root@centos7 ~]# yum -y install gcc make pcre-devel openssl-devel expat-devel
2.编译安装apr
#先编译安装apr,再安装apr-util,最后安装httpd24
[root@centos7 ~]# mkdir -p  /apps/apr

[root@centos7 ~]# cd apr-1.7.0

[root@centos7 ~]# ./configure --prefix=/apps/apr

[root@centos7 ~]# make -j 2  && make install

3.编译安装apr-util
[root@centos7 ~]# mkdir /apps/apr-util

[root@centos7 ~]# cd apr-util-1.6.1

[root@centos7 ~]# ./configure --prefix=/apps/apr-util --with-apr=/apps/apr/

[root@centos7 ~]# make -j 2 && make install
4.编译安装 httpd-2.4
[root@centos7 ~]# mkdir /apps/httpd24

[root@centos7 ~]# cd httpd-2.4.54

[root@centos7 ~]# ./configure --prefix=/apps/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/apps/apr/ --with-apr-util=/apps/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork

[root@centos7 ~]# make -j 4 && make install
 
[root@centos7 ~]# useradd -s /sbin/nologin -r apache

5.编译安装后配置
Httpd编译过程:/apps/httpd24/build/config.nice

自带的服务控制脚本:/apps/httpd24/bin/apachectl
(1)创建专用用户
[root@centos7 ~]# useradd -s /sbin/nologin -r apache
(2)指定运行httpd的用户
[root@centos7 ~]# vim /apps/httpd24/conf/httpd
user apache
group apache
(3)配置环境变量
[root@centos7 ~]# echo 'PATH=/apps/httpd24/bin:$PATH' > /etc/profile.d/httpd.sh

[root@centos7 ~]# . /etc/profile.d/httpd.sh

[root@centos7 ~]# httpd -v
Server version: Apache/2.4.54 (Unix)
Server built:   Oct 11 2022 10:31:36

(4)配置帮助
[root@centos7 ~]# vim /etc/man_db.conf
MANDATORY_MANPATH           /apps/httpd24/man
(5)设置开机自动启动
[root@centos7 ~]# vim /etc/rc.d/rc.local

[root@centos7 ~]# /apps/httpd24/bin/apachectl start

[root@centos7 ~]# chmod +x /etc/rc.d/rc.local
(6)创建service unit文件(CentOS 7 以上版本)
[root@centos7 ~]# vim /usr/lib/systemd/system/httpd24.service
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)

[Service]
Type=forking
#EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/apps/httpd24/bin/apachectl start
#ExecStart=/apps/httpd24/bin/httpd $OPTIONS -k start
ExecReload=/apps/httpd24/bin/apachectl graceful
#ExecReload=/apps/httpd24/bin/httpd $OPTIONS -k graceful
ExecStop=/apps/httpd24/bin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target

创建启动脚本(CentOS 6 以前版本)

#自定义启动脚本(参考httpd-2.2的服务脚本)
[root@centos6 ~]# cp   /etc/rc.d/init.d/httpd /etc/rc.d/init.d/httpd24
[root@centos6 ~]# vim /etc/rc.d/init.d/httpd24
apachectl=/apps/httpd24/bin/apachectl
httpd=${HTTPD-/apps/httpd24/bin/httpd}
pidfile=${PIDFILE-/apps/httpd24/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}

[root@centos6 ~]# chkconfig -add httpd24

[root@centos6 ~]# chkconfig -list httpd24

编译安装httpd-2.4方法二

将apr和httpd一起进行编译安装。

1.将apr 和apr-util源码与httpd 源码合并
tar xf apr-1.7.0.tar.bz2
tar xf apr-util-1.6.1.tar.bz2
tar xf httpd-2.4.54.tar.bz2

mv apr-1.7.0 httpd-2.4.54/srclib/apr
mv apr-util-1.6.1 httpd-2.4.54/srclib/apr-util
ls httpd-2.4.54/srclib/
apr apr-util Makefile.in
  1. 将三者一并编译并安装
    --with-included-apr
cd httpd-2.4.54/
./configure \
--prefix=/apps/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-included-apr \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork  

make -j 4 && make install

安装后的配置和方法一相同。

标签:Httpd,httpd,apr,root,centos7,--,Linux,httpd24,安装
From: https://www.cnblogs.com/heyongshen/p/16778534.html

相关文章

  • JDK的安装和配置
    目录下载jdk配置环境测试安装下载jdkJDk安装包:官网:https://www.oracle.com/cn/java/technologies/downloads/网盘(速度更快):https://www.123pan.com/s/aiv9-hkrG(适合W......
  • springboot H2 linux下搭建使用
    这次研究是H2数据库了,关键还是再Linux下进行搭建部署的,被这个数据库快弄死了弄了4天时间,现在大致可以用了,还有些细节需要修正。我这边使用的是springboot集成模式。直接使......
  • Linux中$#,$0,$1,$2,$@,$*,$$,$? 的含义
    Linux中$#,$0,$1,$2,$@,$*,$$,$?的含义$#是传给脚本的参数个数$0是脚本本身的文件名$1是脚本后接的第一个参数$2是脚本后接的第二个参数$@是传给脚本......
  • Linux中find命令
    Linux中find命令Linux中find命令用来在指定目录下查找文件。任何位于参数之前的字符串都将被视为欲查找的目录名。如果使用该命令时,不设置任何参数,则find命令将在当前目录......
  • VUE自学日志00-Vue3安装
    目录#1.发布版本说明#2.VueDevtools#3.CDN#4.下载并自托管#5.npm#6.命令行工具(CLI)#7.Vite#8.对不同构建版本的解释#8.1.使用CDN或没有构建工具#vue(.runtime).global......
  • Windows10 RabbitMQ安装和启动详细步骤
    配置Erlang语言下载Erlang原因:RabbitMQ安装包依赖于Erlang语言包的支持,所以要先安装Erlang语言包,再安装RabbitMQ安装包。下载地址:http://www.erlang.org/downloads注......
  • linux如何挂载硬盘linux服务器上挂载磁盘(图文详解)
    1、检查网站的磁盘状态,确认是否有没有分区的磁盘。fdisk-l如上图所示,这个服务器有两个硬盘第一个42.9G,第二个236.2G。这种情况说明硬盘已经分区。2、格式化分区mkfs......
  • VSCode安装教程详细简单版
    https://blog.csdn.net/weixin_43928112/article/details/125813377VSCode插件总结:(rust语言)1.rust-analyzer:语言服务器、自动补全、语法高亮等;2.CodeLLDB:debug功能;3.Ev......
  • MAC下Anaconda的安装踩坑
    问题:安装官方Anaconda图形界面出现报错的现象本人的笔记本是MAcpro2015款不是M1芯片根据网上的解决办法选择第二个命令行方式的安装步骤1.下载,下载完成后是一个sh文......
  • Linux Centos7升级gcc RPM包安装,第三方SCL源仓库
    升级gcc可以用编译,也可用编译好的rpm包来直接安装,编译非常耗时间。  1.查看系统发行版本[root@Centos7~]#cat/etc/redhat-releaseCentOSLinuxrelease7......