源码安装httpd服务

编译安装httpd

编译安装apache需要三个源码包
安装顺序为: apr apr-util httpd
准备工作

[root@localhost ~]# yum groups mark install "Development Tools"  //安装开发工具包
[root@localhost ~]# useradd -r -M -s /sbin/nologin apache  //创建一个系统用户 不生成家目录 拒绝登录/sbin/nologin 
[root@localhost ~]# id apache 
uid=975(apache) gid=973(apache) 组=973(apache)
[root@localhost ~]# yum -y install openssl-devel pcre-devel expat-devel libtool    //安装依赖包
[root@localhost ~]# yum - y install make  //编译需要make命令

下载源码包并解压
源码包地址:https://downloads.apache.org/

//wget命令下载
[root@localhost ~]# wget https://downloads.apache.org/httpd/httpd-2.4.53.tar.gz
[root@localhost ~]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz
[root@localhost ~]# wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz
//解压
[root@localhost ~]# tar -xf apr-1.7.0.tar.gz  
[root@localhost ~]# tar -xf apr-util-1.6.1.tar.gz 
[root@localhost ~]# tar -xf httpd-2.4.53.tar.gz 

安装apr源码包

[root@localhost ~]# cd apr-1.7.0/
[root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.7.0]# make
[root@localhost apr-1.7.0]# make install 

安装apr-util源码包

[root@localhost ~]# cd apr-util-1.6.1/ 
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr   //apr-util是apr的子包 所以需要指定指定主包的位置
[root@localhost apr-1.7.0]# make
[root@localhost apr-1.7.0]# make install 

安装httpd源码包

[root@localhost ~]# cd httpd-2.4.53/
[root@localhost httpd-2.4.53]#  ./configure --prefix=/usr/local/apache \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util/ \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork
[root@localhost apr-1.7.0]# make
[root@localhost apr-1.7.0]# make install   //此处似乎不能补全需要手敲

设置环境变量

[root@localhost ~]# ls /usr/local/   //此目录就是安装三个源码包的位置
apache  apr-util  etc    include  lib64    sbin   src
apr     bin       games  lib      libexec  share
[root@localhost ~]# cd /usr/local/apache/
[root@localhost apache]# ls   //环境变量的目录
bin    cgi-bin  error   icons    logs  manual
build  conf     htdocs  include  man   modules


//创建环境变量后httpd和apachectl命令就可以使用了
[root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/apache.sh 
[root@localhost ~]# source /etc/profile.d/apache.sh 
[root@localhost ~]# which httpd
/usr/local/apache/bin/httpd
[root@localhost ~]# which apachectl 
/usr/local/apache/bin/apachectl

//   /usr/local/apache/ 目录下常用目录解释
bin 命令
conf 配置文件
htdocs 网站
logs 日志
include 头文件
man 帮助文档

配置映射关系

[root@localhost ~]# ls /usr/local/apache/   //有头文件include所以需要做链接
bin    cgi-bin  error   icons    logs  manual
build  conf     htdocs  include  man   modules
[root@localhost ~]# ln -s /usr/local/apache/include/ /usr/include/apache

配置man文档

[root@localhost ~]# vim /etc/man_db.conf  //添加下面一条
MANDATORY_MANPATH                       /usr/local/share/apache  

配置防火墙 Selinux httpd

[root@localhost ~]#  systemctl disable --now firewalld.service   //关闭防火墙
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0  //关闭selinux  当前生效
[root@localhost ~]# getenforce 
Permissive
[root@localhost ~]# vim /etc/selinux/config   //永久关闭
SELINUX=disabled  //第一个修改为disabled

//开启80端口号
[root@localhost ~]# ss -antl   //查看端口号80是否开启
State     Recv-Q    Send-Q         Local Address:Port         Peer Address:Port    
LISTEN    0         128                  0.0.0.0:111               0.0.0.0:*       
LISTEN    0         32             192.168.122.1:53                0.0.0.0:*       
LISTEN    0         128                  0.0.0.0:22                0.0.0.0:*       
LISTEN    0         5                  127.0.0.1:631               0.0.0.0:*       
LISTEN    0         128                     [::]:111                  [::]:*       
LISTEN    0         128                     [::]:22                   [::]:*       
LISTEN    0         5                      [::1]:631                  [::]:*       
[root@localhost ~]# apachectl start  //开启80端口号
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message  //警告信息可以无视

[root@localhost ~]# ss -antl  //再次查看80端口已经开启了
State     Recv-Q    Send-Q         Local Address:Port         Peer Address:Port    
LISTEN    0         128                  0.0.0.0:111               0.0.0.0:*       
LISTEN    0         32             192.168.122.1:53                0.0.0.0:*       
LISTEN    0         128                  0.0.0.0:22                0.0.0.0:*       
LISTEN    0         5                  127.0.0.1:631               0.0.0.0:*       
LISTEN    0         128                     [::]:111                  [::]:*       
LISTEN    0         128                        *:80                      *:*       
LISTEN    0         128                     [::]:22                   [::]:*       
LISTEN    0         5                      [::1]:631                  [::]:*     

访问虚拟机的ip地址
在这里插入图片描述
取消警告信息

[root@localhost ~]# apachectl stop  //无论在开启还是关闭都会出来提示
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message

[root@localhost ~]# cd /usr/local/apache/
[root@localhost apache]# cd conf/   //进到配置文件目录 
[root@localhost conf]# ls
extra  httpd.conf  magic  mime.types  original
[root@localhost conf]# vim httpd.conf   //将下面一行的注释取消掉
ServerName www.example.com:80
[root@localhost conf]# apachectl start   //此时就不会出现警告信息了
[root@localhost conf]# ss -antl
State     Recv-Q    Send-Q         Local Address:Port         Peer Address:Port    
LISTEN    0         128                  0.0.0.0:111               0.0.0.0:*       
LISTEN    0         32             192.168.122.1:53                0.0.0.0:*       
LISTEN    0         128                  0.0.0.0:22                0.0.0.0:*       
LISTEN    0         5                  127.0.0.1:631               0.0.0.0:*       
LISTEN    0         128                     [::]:111                  [::]:*       
LISTEN    0         128                        *:80                      *:*       
LISTEN    0         128                     [::]:22                   [::]:*       
LISTEN    0         5                      [::1]:631                  [::]:*   

使用systemctl命令设置httpd
使用源码包安装apache服务 默认是不能用systemctl的
任何源码安装的服务都适用

[root@localhost ~]# cd /usr/lib/systemd/system   
[root@localhost system]# ls sshd.service 
sshd.service
[root@localhost system]# cp sshd.service httpd.service  //复制一份这个文件改名为httpd.service
[root@localhost system]# vim httpd.service   //编辑这个文件
[root@localhost system]# cat httpd.service 
[Unit]
Description=httpd server daemon   //修改为httpd
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start   //更改为apachectl的路径   开启
ExecStop=/usr/local/apache/bin/apachectl stop   //关闭
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
//测试 
[root@localhost system]# systemctl daemon-reload      //重新加载服务 让其生效
[root@localhost system]# systemctl status httpd   //此时就可以使用systemcl 查看httpd
● httpd.service - httpd server daemon
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset:>
   Active: inactive (dead)

[root@localhost system]# systemctl start httpd   //开启httpd服务
[root@localhost system]# systemctl enable --now httpd  //设置为开机自启
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@localhost system]# systemctl status httpd
● httpd.service - httpd server daemon
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: >
   Active: active (running) since Fri 2022-04-15 18:31:27 CST; 7min ago
 Main PID: 410896 (httpd)
    Tasks: 6 (limit: 11160)
   Memory: 5.4M
   CGroup: /system.slice/httpd.service
           ├─410896 /usr/local/apache/bin/httpd -k start
           ├─410897 /usr/local/apache/bin/httpd -k start
           ├─410898 /usr/local/apache/bin/httpd -k start
           ├─410899 /usr/local/apache/bin/httpd -k start
           ├─410900 /usr/local/apache/bin/httpd -k start
           └─410901 /usr/local/apache/bin/httpd -k start

配置三种不同的虚拟主机

虚拟主机可使一个服务器放多个网站

ip地址访问

[root@localhost extra]# cd /usr/local/apache/htdocs/  //此目录为存放完网站的目录
[root@localhost htdocs]# mkdir test.example.com  //创建一个测试目录用于存放网站
[root@localhost htdocs]# ls
index.html  test.exampl.com  
[root@localhost htdocs]# cd test.exampl.com/ 
[root@localhost test.exampl.com]# echo 'abc' > abc.html   //创建网站的此时页面
[root@localhost test.exampl.com]# cd ..
[root@localhost ~]# cd /usr/local/apache/conf/extra/   //虚拟主机文件存放路径
[root@localhost extra]# ls
httpd-autoindex.conf  httpd-languages.conf           httpd-ssl.conf
httpd-dav.conf        httpd-manual.conf              httpd-userdir.conf
httpd-default.conf    httpd-mpm.conf                 httpd-vhosts.conf
httpd-info.conf       httpd-multilang-errordoc.conf  proxy-html.conf
[root@localhost extra]# vim httpd-vhosts.conf    //修改虚拟主机文件

<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/test.example.com"   //网站的存放位置
    ServerName test.example.com     //域名
    ErrorLog "logs/test.example.com-error_log"    //错误日志存放位置
    CustomLog "logs/test.example.com-access_log" common     //日常日志存放位置
</VirtualHost>

//主配置文件未生效
[root@localhost extra]# vim /usr/local/apache/conf/httpd.conf   //将此文件的下面一行 注释取消 让其包含虚拟主机文件 使其生效
Include conf/extra/httpd-vhosts.conf
[root@localhost extra]# systemctl restart httpd   //重启服务

再次访问虚拟机ip地址 就能看到测试页面
在这里插入图片描述
单击abc.html就可以看到写入abc
在这里插入图片描述

此时虽然访问到了但是需要点击一下才能访问测试页面,与平时访问网站并不一样

[root@localhost htdocs]# cd test.example.com/
[root@localhost test.example.com]# mv abc.html index.html   //只需要将abc.html修改为index.html 即可

//修改为index.html是因为主配置文件内 规定了必须为index.html才可直接跳转为网页
[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf 
<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

访问ip地址成功
在这里插入图片描述

ip加端口号访问
相同ip不同端口

[root@localhost ~]# cd /usr/local/apache/htdocs/   
[root@localhost htdocs]# mkdir web.example.com  //创建一个新的存放网站的目录
[root@localhost htdocs]# ls
index.html  test.example.com  web.example.com   
[root@localhost htdocs]# cd web.example.com/  
[root@localhost web.example.com]# echo "123" > index.html   //创建一个新的测试文件
[root@localhost web.example.com]# cat index.html 
123

//修改虚拟主机文件
[root@localhost ~]# cd /usr/local/apache/conf/extra/
[root@localhost extra]# vim httpd-vhosts.conf 
[root@localhost extra]# cat httpd-vhosts.conf 
<VirtualHost *:80>   //此为abc.html网站的配置
    DocumentRoot "/usr/local/apache/htdocs/test.example.com"
    ServerName test.example.com
    ErrorLog "logs/test.example.com-error_log"
    CustomLog "logs/test.example.com-access_log" common
</VirtualHost>

Listen 81  //为其添加81的监听
<VirtualHost *:81>   //将端口号修改为81
    DocumentRoot "/usr/local/apache/htdocs/web.example.com"
    ServerName web.example.com
    ErrorLog "logs/web.example.com-error_log"
    CustomLog "logs/web.example.com-access_log" common
</VirtualHost>


[root@localhost extra]# systemctl restart httpd.service   //重启服务
[root@localhost extra]# ss -antl  //查看端口号出现了两个端口80 81
State     Recv-Q    Send-Q         Local Address:Port         Peer Address:Port      
LISTEN    0         128                        *:80                      *:*       
LISTEN    0         128                        *:81                      *:*       

再次输入ip地址
加上端口号即可访问不同的测试页面

81端口号
在这里插入图片描述
80端口号
80是默认的可以不需要接端口号
在这里插入图片描述

不同ip访问
不同ip相同端口

[root@localhost ~]# ip addr add 192.168.220.146/24 dev ens160   //为ens160添加一个新的ip   此添加为临时添加
[root@localhost ~]# ip addr show ens160 
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:88:45:00 brd ff:ff:ff:ff:ff:ff
    inet 192.168.220.145/24 brd 192.168.220.255 scope global dynamic noprefixroute ens160
       valid_lft 1482sec preferred_lft 1482sec
    inet 192.168.220.146/24 scope global secondary ens160
       valid_lft forever preferred_lft forever
    inet6 fe80::25e8:73ad:fbe9:f338/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

[root@localhost ~]# cd /usr/local/apache/conf/extra/
[root@localhost extra]# vim httpd-vhosts.conf 
[root@localhost extra]# cat httpd-vhosts.conf 
<VirtualHost 192.168.220.145:80>   //修为固定ip
    DocumentRoot "/usr/local/apache/htdocs/test.example.com"
    ServerName test.example.com
    ErrorLog "logs/test.example.com-error_log"
    CustomLog "logs/test.example.com-access_log" common
</VirtualHost>

<VirtualHost 192.168.220.146:80>  //修改为新添加的ip端口号改为80
    DocumentRoot "/usr/local/apache/htdocs/web.example.com"
    ServerName web.example.com
    ErrorLog "logs/web.example.com-error_log"
    CustomLog "logs/web.example.com-access_log" common
</VirtualHost>

[root@localhost extra]# systemctl restart httpd.service  //重启服务

192.168.220.145 的测试页面
在这里插入图片描述
192.168.220.146的测试页面
在这里插入图片描述

相同ip端口不同域名

[root@localhost extra]# cat httpd-vhosts.conf 
<VirtualHost *:80>   //修改为*
    DocumentRoot "/usr/local/apache/htdocs/test.example.com"
    ServerName test.example.com    //此处就是域名
    ErrorLog "logs/test.example.com-error_log"
    CustomLog "logs/test.example.com-access_log" common
</VirtualHost>

<VirtualHost *:80>   //修改为*
    DocumentRoot "/usr/local/apache/htdocs/web.example.com"
    ServerName web.example.com   //此处就是域名
    ErrorLog "logs/web.example.com-error_log"
    CustomLog "logs/web.example.com-access_log" common
</VirtualHost>

域名是无法访问的需要修改hosts文件
路径: C:\Windows\System32\drivers\etc

hosts文件内添加这两行
192.168.220.145 test.example.com
192.168.220.145 web.example.com

web.example.com域名访问
在这里插入图片描述
test.example.com域名访问
在这里插入图片描述

配置拒指定ip访问

[root@localhost extra]# cat httpd-vhosts.conf 
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/test.example.com"
    ServerName test.example.com
    ErrorLog "logs/test.example.com-error_log"
    CustomLog "logs/test.example.com-access_log" common
</VirtualHost>

<Directory "/usr/local/apache/htdocs/test.example.com">   //添加要拒绝的网站存放位置
    <RequireAll>
        Require not ip 192.168.220.1  //添加要拒绝的ip 
        Require all granted
    </RequireAll>
</Directory>

<VirtualHost *:80> 
    DocumentRoot "/usr/local/apache/htdocs/web.example.com"
    ServerName web.example.com
    ErrorLog "logs/web.example.com-error_log"
    CustomLog "logs/web.example.com-access_log" common
</VirtualHost>

web是没有做拒绝的所以可以访问
在这里插入图片描述
test对192.168.220.1(主机)所以无法访问
在这里插入图片描述

配置https步骤

配置httpd.conf,取消以下内容的注释

[root@localhost conf]# vim httpd.conf   //源码安装的服务模块在httpd.conf文件里
LoadModule ssl_module modules/mod_ssl.so  //注释掉这一行

生成证书

openssl实现私有CA:

[root@localhost ~]# cd /etc/pki/
[root@localhost pki]# mkdir CA
[root@localhost pki]# cd CA/
[root@localhost CA]# mkdir private
[root@localhost CA]# (umask 077;openssl genrsa -out private/cakey.pem 2048)   //在private目录下生成私钥文件
Generating RSA private key, 2048 bit long modulus (2 primes)
.....................+++++
...............................................+++++
e is 65537 (0x010001)
[root@localhost CA]# ls private/
cakey.pem
[root@localhost CA]# openssl rsa -in private/cakey.pem -pubout   //查看公钥 可不做

CA生成自签署证书

[root@localhost CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 365  //生成一个证书 有效日期为365
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN  //国家
State or Province Name (full name) []:HB   //省份
Locality Name (eg, city) [Default City]:WH  //市
Organization Name (eg, company) [Default Company Ltd]:kurumi   //公司
Organizational Unit Name (eg, section) []:kurumi  //单位
Common Name (eg, your name or your server's hostname) []:web.example.com  //域名
Email Address []:1@123.com  //邮箱

[root@localhost CA]# mkdir certs newcerts crl
[root@localhost CA]# touch index.txt && echo 01 > serial

客户端(例如httpd服务器)生成密钥

[root@localhost ~]# cd /usr/local/apache/conf/
[root@localhost conf]# ls
extra  httpd.conf  magic  mime.types  original
[root@localhost conf]# mkdir ssl
[root@localhost conf]# cd ssl/
[root@localhost ssl]# (umask 077;openssl genrsa -out httpd.key 2048)
Generating RSA private key, 2048 bit long modulus (2 primes)
.............................................................................+++++
..........................+++++
e is 65537 (0x010001)

客户端生成证书签署请求

[root@localhost ssl]# openssl req -new -key httpd.key -days 365 -out httpd.csr
Ignoring -days; not generating a certificate
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN    
State or Province Name (full name) []:HB
Locality Name (eg, city) [Default City]:WH
Organization Name (eg, company) [Default Company Ltd]:kurumi
Organizational Unit Name (eg, section) []:kurumi
Common Name (eg, your name or your server's hostname) []:web.example.com
Email Address []:1@123.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[root@localhost ssl]# ls
httpd.csr  httpd.key

CA签署客户端提交上来的证书

[root@localhost ssl]# openssl ca -in httpd.csr -out httpd.crt -days 365
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 1 (0x1)
        Validity
            Not Before: Apr 15 13:58:39 2022 GMT
            Not After : Apr 15 13:58:39 2023 GMT
        Subject:
            countryName               = CN
            stateOrProvinceName       = HB
            organizationName          = kurumi
            organizationalUnitName    = kurumi
            commonName                = web.example.com
            emailAddress              = 1@123.com
        X509v3 extensions:
            X509v3 Basic Constraints: 
                CA:FALSE
            Netscape Comment: 
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier: 
                8F:D1:86:60:47:6A:E9:20:B8:97:90:8C:32:1C:54:8E:7F:B4:4F:11
            X509v3 Authority Key Identifier: 
                keyid:40:1B:42:0B:EF:88:2B:F5:BA:76:17:9B:C5:48:60:1C:82:B5:D7:83

Certificate is to be certified until Apr 15 13:58:39 2023 GMT (365 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
[root@localhost ssl]# ls
httpd.crt  httpd.csr  httpd.key

在httpd-vhosts.conf中配置虚拟主机
在httpd-ssl.conf中配置证书的位置

[root@localhost conf]# vim httpd.conf   //取消注释 让其包含
Include conf/extra/httpd-ssl.conf
[root@localhost conf]# vim extra/httpd-ssl.conf 
DocumentRoot "/usr/local/apache/htdocs/web.example.com"   //修改为证书的域名
ServerName web.example.com:443   //修改
ServerAdmin you@example.com   
ErrorLog "/usr/local/apache/logs/error_log"
TransferLog "/usr/local/apache/logs/access_log"


SSLCertificateFile "/usr/local/apache/conf/ssl/httpd.crt"   //修改httpdctl的路径

SSLCertificateKeyFile "/usr/local/apache/conf/ssl/httpd.key"  //修改httpd.key的路径

检查配置文件是否有语法错误
检查语法发现有一个模块未打开

[root@localhost conf]# httpd -t
AH00526: Syntax error on line 92 of /usr/local/apache/conf/extra/httpd-ssl.conf:
SSLSessionCache: 'shmcb' session cache not supported (known names: ). Maybe you need to load the appropriate socache module (mod_socache_shmcb?).
[root@localhost conf]# vim extra/httpd-ssl.conf 

[root@localhost conf]# vim /usr/local/apache/conf/httpd.conf   //修改配置文件
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so  //将此行注释取消 让其启动
[root@localhost conf]# httpd -t  //再次检测成功
AH00112: Warning: DocumentRoot [/usr/local/apache/web.example.com] does not exist
Syntax OK

启动或重启服务
设置hosts以便用域名访问(仅学习阶段,企业实际工作中无需做此步。)

[root@localhost conf]# systemctl restart httpd
[root@localhost conf]# ss -antl
State     Recv-Q    Send-Q         Local Address:Port         Peer Address:Port    
LISTEN    0         128                  0.0.0.0:111               0.0.0.0:*       
LISTEN    0         128                  0.0.0.0:22                0.0.0.0:*       
LISTEN    0         5                  127.0.0.1:631               0.0.0.0:*       
LISTEN    0         128                     [::]:111                  [::]:*       
LISTEN    0         128                        *:80                      *:*       
LISTEN    0         128                     [::]:22                   [::]:*       
LISTEN    0         5                      [::1]:631                  [::]:*       
LISTEN    0         128                        *:443                     *:*       //重启后端口有了443

此时就可以使用https访问
在这里插入图片描述

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 1. 下载httpd源码包,解压缩到指定目录。 2. 安装必要的依赖库,如apr、apr-util、pcre等。 3. 进入httpd源码目录,执行configure命令,生成Makefile文件。 4. 执行make命令,编译httpd源码。 5. 执行make install命令,安装httpd到指定目录。 6. 配置httpd的配置文件httpd.conf,启动httpd服务。 7. 在浏览器中输入http://localhost,即可访问httpd服务。 ### 回答2: 在Linux系统上,Apache HTTP服务器是最常见的Web服务器。要在Linux系统上安装Apache HTTP服务器,可以使用预编译的软件包或自己从源代码中编译安装。源代码编译安装httpd可以更好地优化自己的服务。以下是您需要遵循的步骤: 1. 下载Apache HTTP服务器源代码 您可以在Apache HTTP服务器官方网站上下载最新的源代码。在下载之前,您应该首先确定您要下载的是最新版本的源代码。 2. 设置httpd安装目录 通常,httpd的安装目录默认为“/usr/local/apache2”,但您可以将其更改为其他目录。可以通过设置configure选项来指定安装目录,如下所示: ./configure --prefix=/your/installation/directory 3. 安装依赖软件 在安装Apache之前,您需要安装一些必要的软件。这些软件包括APR,APR-util和pcre。在Ubuntu和Debian上,可以使用以下命令安装这些软件包: sudo apt-get install libapr1-dev libaprutil1-dev libpcre3-dev 4. 配置和编译源代码 解压缩源代码并进入目录,然后使用./configure命令进行配置: ./configure --prefix=/usr/local/apache2 然后,使用make命令编译源代码: make 5. 安装和配置httpd 完成编译后,可以使用make install命令安装httpd: make install 之后,进入“/usr/local/apache2/conf”目录并编辑“httpd.conf”文件。您需要根据您的情况更改以下设置: - 服务器名称 - 监听端口 - 文档根目录 - 访问权限 编辑完毕后,保存并退出httpd.conf文件。然后,可以启动httpd服务器并测试其功能。例如,可以使用以下命令启动httpd服务器: /usr/local/apache2/bin/apachectl start 如果安装和配置正确,您应该可以在浏览器中访问http://localhost,看到Apache欢迎页面。 总之,从源代码编译安装httpd更好的控制服务器的行为和性能,需要遵循上述几个步骤,即下载、设置安装目录、安装依赖软件、配置和编译源代码、安装和配置httpd,才能成功安装和使用。 ### 回答3: Apache HTTP Server是一个跨平台的,开放源代码的Web服务器。它是最流行的Web服务器之一,并广泛用于Linux系统中。这里我们讲述如何通过源码编译安装httpd。 1. 下载源代码 从官网下载Apache HTTP Server的源代码,这里我们下载最新版本2.4.46。在终端中输入以下命令完成对源代码的下载和解压缩: ```bash wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.46.tar.gz tar zxvf httpd-2.4.46.tar.gz ``` 2. 安装Prerequisites 在编译和安装httpd之前,需要先在系统中安装一些软件包。使用以下命令在Ubuntu系统中安装这些软件包: ```bash sudo apt-get update sudo apt-get install build-essential sudo apt-get install libexpat1-dev sudo apt-get install libaprutil1-dev sudo apt-get install libpcre3-dev ``` 3. 配置和编译 在安装了Prerequisites之后,使用以下命令配置Apache HTTP Server的构建: ```bash cd httpd-2.4.46 ./configure --prefix=/usr/local/apache2 --enable-so --enable-ssl --with-ssl=/usr/bin/openssl --with-included-apr --enable-mpms-shared=all ``` 解释一下上面的参数: - --prefix:指定httpd的安装路径 - --enable-so:启用动态加载模块 - --enable-ssl:启用SSL支持 - --with-ssl:指定SSL库的位置 - --with-included-apr:使用当前源代码中所包含的APR库 - --enable-mpms-shared=all:开启多进程模块 4. 进行安装 在完成configure之后,使用以下命令编译和安装httpd: ```bash make sudo make install ``` 此时会将编译后的文件安装在--prefix指定的路径下。 5. 配置服务 使用以下命令将httpd设定为系统服务: ```bash sudo cp /usr/local/apache2/bin/apachectl /etc/init.d/ sudo chmod +x /etc/init.d/apachectl sudo update-rc.d apachectl defaults ``` 至此,我们已经成功通过源码编译安装httpd,并将其设定为系统服务。最后,使用以下命令启动httpd服务: ```bash sudo service apachectl start ``` 可以通过以下的网址验证httpd是否成功安装: ```bash http://localhost/ ``` 在浏览器中输入上述命令,若显示 “It works!” 则证明httpd已经成功安装。 总之,安装Apache HTTP Server是在Linux系统上运行Web服务器的最佳方式之一。通过源码编译安装httpd可以为管理员提供更多的自定义选项和更好的控制。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值