Linux apache2.4.33安装
1、安装编译环境
yum install gcc gcc++ -y
2、下载所需安装包
wget http://archive.apache.org/dist/httpd/httpd-2.4.33.tar.gz
wget http://archive.apache.org/dist/apr/apr-1.6.3.tar.gz
wget http://archive.apache.org/dist/apr/apr-util-1.6.1.tar.gz
wget https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz
2、安装apr
tar -zxvf apr-1.6.3.tar.gz
cd apr-1.6.3/
./configure --prefix=/usr/local/apr (prefix=/usr/local/apr 是apr的安装目录)
make && make install
3、安装apr-util
tar -zxvf 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
(缺少expat库)如果报如下错误,请执行:yum install expat-devel
4、安装pcre库
先检查系统是否已默认安装
rpm -qa pcre
如果没有安装pcre通过以下命令
tar -zxvf pcre-8.42.tar.gz
cd pcre-8.42/
./configure --prefix=/usr/local/pcre
make && make install
yum -y install gcc-c++
在我的安装过程中没有执行绿色底命令,所以必须执行下面一步
yum安装pcre-devel包
yum install pcre-devel -y
5、安装httpd
tar -xf httpd-2.4.33.tar.bz2
cd httpd-2.4.33/
cp -rf /home/apr-1.6.3 /home/httpd-2.4.33/srclib/apr
cp -rf /home/apr-util-1.6.1 /home/httpd-2.4.33/srclib/apr-util
./configure --prefix=/usr/local/httpd --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-rewrite --enable-so --with-pcre --with-included-apr
make && make install
如果是编译安装的pcre,替换configure命令,其他不变
./configure --prefix=/usr/local/httpd --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-rewrite --enable-so --with-pcre=/usr/local/pcre/ --with-included-apr
6、配置apache
cd /usr/local/httpd/conf
vi httpd.conf
找到Listen 80,将80修改为你要的端口
找到ServerName www.example.com:80, 将其修改为ServerName localhost:80 80修改为你要的端口
添加apache到Linux服务
cp /usr/local/httpd/bin/apachectl /etc/rc.d/init.d/
mv /etc/rc.d/init.d/apachectl /etc/rc.d/init.d/httpd
cd /etc/rc.d/init.d/
vi httpd
在第一行下添加如下三行文字
Comments to support chkconfig on RedHat Linux
chkconfig: 2345 90 90
description:http server
·注册服务
chkconfig --add httpd #所有开机模式下自启动
chkconfig httpd on #345开机模式下自启动
·配置环境变量
vi /etc/profile
在最后一行加入
PATH=$PATH:/usr/local/apache/bin
保存退出
source /etc/profile
·启停apache的命令
service httpd start # 启动
service httpd stop # 停止
service httpd restart # 重启
apachectl -k start # 启动
apachectl -k stop # 停止