centos7、centos8编译安装apache并指定用户运行
测试系统centos7、8编译安装apache2.4,指定apache用户运行。
安装支持组件
yum clean all
yum update -y
yum install expat-devel -y
yum groupinstall base -y
yum grouplist -y
yum groupinstall 'Development tools' -y
yum groupinstall 'Debugging Tools' -y
yum groupinstall 'Compatibility libraries' -y
yum install pcre* pcre-devel* openssl-devel* -y
yum install cmake -y
yum install python-devel -y
yum -y install gd *openssl*
先升级pcre版本
apache最新版下载地址https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/,这里下载目前的最新版本2.4.41版本
wget https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.46.tar.gz
下载apr及apr,最新版本可以去http://apache.communilink.net/apr/,下载,目前最新版本下载
wget http://source.loshub.com/linux/apache/apr-1.7.0.tar.gz
wget http://source.loshub.com/linux/apache/apr-util-1.6.1.tar.gz
解压apache和apr及apr-util
tar zxvf httpd-2.4.46.tar.gz
tar zxvf apr-1.7.0.tar.gz
tar zxvf apr-util-1.6.1.tar.gz
apr移动至httpd安装目录
mv apr-1.7.0 httpd-2.4.46/srclib/apr
mv apr-util-1.6.1 httpd-2.4.46/srclib/apr-util
建立软连32位系统跳过
ln -s /usr/lib64/libm.a /usr/lib/libm.a
ln -s /usr/lib64/libm.so /usr/lib/libm.so
ln -s /usr/lib64/libexpat.so /usr/lib/libexpat.so
安装apr
cd /root/httpd-2.4.46/srclib/apr
./configure --prefix=/usr/local/apr
make&&make install
安装依赖apr时报rm: cannot remove ‘libtoolT’: No such file or directory
编辑configure
找到RM"cfgfile"
将其注释掉即可
$RM "$cfgfile" 将其注释即可
RM"cfgfile"
安装apr-util
cd /root/httpd-2.4.46/srclib/apr-util
make clean
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make&&make install
编译安装httpd
cd /root/httpd-2.4.46
./configure --prefix=/usr/local/apache --sysconfdir=/usr/local/apache/etc --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-mods-shared=most --enable-mpms-shared=all --with-mpm=prefork --with-included-apr --libdir=/usr/lib64 --enable-ssl --with-ssl
make && make install
指定用户运行apache防止有BUG后对服务器产生影响
groupadd apache
useradd --shell /sbin/nologin -g apache apache
chown -R apache:apache /usr/local/apache/
编辑httpd.conf
vi /usr/local/apache/etc/httpd.conf
ServerName
去除前面的#,并把网址改成localhost
ServerName localhost:80如下图
并把User和Group改为apache如下图
启动httpd、停止httpd、重启httpd
cd /usr/local/apache/bin/
./apachectl start
./apachectl stop
./apachectl restart
加入防火墙
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
添加为系统服务
vi /lib/systemd/system/apache.service
输入以下代码
[Unit]
Description=apache
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start
ExecReload=/usr/local/apache/bin/apachectl restart
ExecStop=/usr/local/apache/bin/apachectl stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
加入系统启动
systemctl enable apache
开启apache
systemctl start apache
重启apache
systemctl restart apache
停止apache
systemctl stop apache
在浏览器中输入IP
显示It works!
完成
本文系作者 @天边的云 原创发布在Loshub站点。未经许可,禁止转载。
暂无评论数据