利用Linux CentOS7 搭建apache
系统:CentOS Linux release 7.6.1810
1、查看防火墙状态并关闭防火墙
临时关闭:systemctl stop firewalld
永久关闭:systemctl disable firewalld
2、查看SELinux状态并关闭
临时关闭:setenforce 0
永久关闭:vi /etc/selinux/config编辑SELinux配置文件
将SELINUX=enforcing改为SELINUX=disabled并保存退出
3、安装依赖包
-
yum groupinstall “Development Tools” -y
-
yum install libtool -y
-
yum install expat-devel pcre pcre-devel openssl-devel -y
4、下载httpd和apr源码包(这里引用了阿里云的镜像)
最新版的httpd版本号是httpd-2.4.43
wget https://mirrors.aliyun.com/apache/httpd/httpd-2.4.43.tar.gz
apr需要下载两个包,apr和apr-util,最新版本号分别是1.7.0和1.6.1
-
wget https://mirrors.aliyun.com/apache/apr/apr-1.7.0.tar.gz
-
wget https://mirrors.aliyun.com/apache/apr/apr-util-1.6.1.tar.gz
5、解压(可指定目录)
①解压httpd
-
tar xvf httpd-2.4.43.tar.gz -C /usr/local/src
②解压apr
-
tar xvf apr-1.7.0.tar.gz -C /usr/local/src
③解压apr-util
-
tar xvf apr-util-1.6.1.tar.gz -C /usr/local/src
6、解压完毕后进入解压目录
-
cd /usr/local/src
7、依次将apr和apr-util放入httpd的srclib文件夹下
-
mv apr-1.7.0 httpd-2.4.43/srclib/apr
-
mv apr-util-1.6.1 httpd-2.4.43/srclib/apr-util
8、进入httpd目录
-
cd /usr/local/src/httpd-2.4.43
9、编译源码
-
./buildconf
点3下代码可以全选进行复制哟👇
-
./configure –prefix=/usr/local/apache2 –enable-ssl –enable-so –with-mpm=event –with-included-apr –enable-cgi –enable-rewrite –enable-mods-shared=most –enable-mpms-shared=all
-
make && make install
10、配置环境变量
-
echo “export PATH=$PATH:/usr/local/apache2/bin” > /etc/profile.d/httpd.sh
-
source /etc/profile.d/httpd.sh
11、添加apache启动配置文件(选做)
-
vi /usr/lib/systemd/system/httpd.service
[Unit]
Description=The Apache HTTP Server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/apache2/bin/apachectl -k start
ExecReload=/usr/local/apache2/bin/apachectl -k graceful
ExecStop=/usr/local/apache2/bin/apachectl -k graceful-stop
PIDFile=/usr/local/apache2/logs/httpd.pid
PrivateTmp=false
[Install]
WantedBy=multi-user.target
12、启动Apache并设置为开机启动
-
systemctl start httpd
-
systemctl enable httpd
13、输入服务器IP查看是否搭建成功
成功图如下↓
原创文章,作者:Tingwep,如若转载,请注明出处:https://tingwep.cn/linux/id=462