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