Apache源码安装

Apache源码安装
Apache软件包下载网址:
wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.41.tar.gz

1、解压编译安装依赖包httpd-2.4.41.tar.gz到 /usr/local/src/目录下
tar zxvf httpd-2.4.41.tar.gz -C /usr/local/src/


2、切换到/usr/local/src/httpd-2.4.41/目录下
cd  /usr/local/src/httpd-2.4.41/


3、配置安装路径、和相关Apache模块

./configure --prefix=/usr/local/apache \
--enable-so --enable-rewrite \
--enable-ssl \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=event
  • #执行配置语句后,使用检查 echo $? ,当执行结果为0时,便是配置正常。

《参数配置说明》:
--prefix=/usr/local/apache2.4                       #安装路径
--enable-so                                         #支持动态加载模块
--enable-rewrite                                    #支持网站地址重写
--enable-ssl                                        #支持SSL加密
 

  • 一共有三种稳定的MPM(Multi-Processing Module,多进程处理模块)模式。它们分别是prefork,worker和event,它们同时也代表这Apache的演变和发展。

4、编译并安装:

 make -j 4 && make install

5、ls查看配置文件

 ls /usr/local/apache/conf/httpd.conf


6、查看网站目录

 ls /usr/local/apache/htdocs/

7、生成启动脚本
 

cp /usr/local/apache/bin/apachectl /etc/init.d/    # 把配置文件复制到/etc/init.d目录下

chmod +x /etc/init.d/apachectl                     # 并赋给执行权限

8、写个apache系统服务脚本, 以754的权限保存此文件

vim /usr/lib/systemd/system/apache.service

[Unit]
Description=apache
After=network.target
[Service]
Type=forking
ExecStart=/etc/init.d/apachectl start
ExecReload=/etc/init.d/apachectl restart
ExecStop=/etc/init.d/apachectl stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target

chmod 754 /usr/lib/systemd/system/apache.service

9、启动服务
 

systemctl enable apache

systemctl start apache.service 

10、默认是daemon用户运行的进程

ps aux|grep apache

11、单独创建一个用户来运行服务:

useradd -M -s /sbin/nologin apache              // 创建一个用户用来运行apache


vim  /usr/local/apache/conf/httpd.conf          // 修改配置文件改变apache运行身份
User apache                      # 运行用户
Group apache                     # 运行组,创建apache的时候已经即时创建了apache这个组


12、更改目录权限

chown -R apache:apache /usr/local/apache/conf/httpd.conf       //默认是root,改为apache


 

  • 7
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

の正在缓存99%

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值