打算像宝塔面板那样,把apache,mysql,php等软件都安装在/www/server目录,这样找起来方便。
apache的安装路径为:/www/server/apache
httpd.conf的路径为:/www/server/apache/conf
本篇文章介绍如何编译安装apache2.4。
安装依赖包
# httpd安装的依赖包
yum -y install pcre-devel
yum -y install openssl-devel
yum -y groupinstall "Development Tools"
# arp-util安装的依赖包
yum install expat-devel
编译安装apr-1.7.0
如果有版本有变化,可以打开这个网址查找:https://mirrors.tuna.tsinghua.edu.cn/apache/apr/
cd /home
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.gz
tar xf apr-1.7.0.tar.gz
cd apr-1.7.0
./configure -prefix=/usr/local/apr
make && make install
编译安装apr-util-1.6.1
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
tar xf apr-util-1.6.1.tar.gz
cd apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
make && make install
编译安装httpd-2.4.41
wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.41.tar.gz
tar xf httpd-2.4.41.tar.gz
cd httpd-2.4.41
./configure --prefix=/www/server/apache --sysconfdir=/www/server/apache/conf --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-modeles=most --enable-mpms-shared=all --with-mpm=event
make && make install
添加httpd服务开启启动
ln -s /www/server/apache/bin/apachectl /etc/rc.d/init.d/httpd
vi /etc/rc.d/init.d/httpd
# 在#/bin/sh 下加上两行,#号不能省略
# chkconfig: 2345 95 10
# description: Activates/Deactivates Apache Web Server
#注册服务
chkconfig --add httpd
#开机自启动
systemctl enable httpd | chkconfig httpd on
修改ServerName
vi /www/server/apache/conf/httpd.conf
将#ServerName www.example.com:80
修改为:ServerName localhost:80
创建apache用户组
ps -aux | grep apache #源码编译apache,运行用户为deamon
useradd -U apache #创建apache用户组
#修改配置文件改变apache运行身份
vi /www/server/apache/conf/httpd.conf
User apache
Group apache
启动httpd
service httpd start
配置vhost
修改httpd.conf
去掉下面这行前面的#
号
#Include conf/extra/httpd-vhosts.conf
修改conf/extra目录下的httpd-vhosts.conf
文件,示例如下:
<VirtualHost *:80>
DocumentRoot "/home/wwwroot/web1"
ServerName web1.test.com
ErrorLog "/home/wwwlogs/web1.test.com-error_log"
CustomLog "/home/wwwlogs/web1.test.com-access_log" common
<Directory "/home/wwwroot/web1.test.com">
Options -Indexes +FollowSymlinks
AllowOverride All
Require all granted
DirectoryIndex index.html index.php
</Directory>
</VirtualHost>
参考:
https://www.cnblogs.com/h-gallop/p/11646085.html