源码编译安装apache

一、安装依赖包

yum -y install wget make gcc gcc-c++ pcre openssl openssl-devel zlib unzip cmake ncurses-devel libjpeg libjpeg-devel libpng libpng-devel libxml2 libxml2-devel curl-devel libtool libtool-ltdl libtool-ltdl-devel libevent libevent-devel zlib-static zlib-devel autoconf pcre-devel gd perl freetype freetype-devel

二、安装apr

wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.6.3.tar.gz
tar xf apr-1.6.3.tar.gz 
cd apr-1.6.3
./configure --prefix=/usr/local/apr/
make
make install

三、安装apr-util

wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
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

四、编译安装apache

#创建运行apache的用户
groupadd www
useradd -g www www -s /bin/false

#下载软件
wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.29.tar.gz
tar -zxvf httpd-2.4.29.tar.gz
cd httpd-2.4.29

#编译
./configure --prefix=/usr/local/httpd/ \
--sysconfdir=/etc/httpd/ \
--with-include-apr \
--disable-userdir \
--enable-headers \
--with-mpm=worker \
--enable-modules=most \
--enable-so \
--enable-deflate \
--enable-defate=shared \
--enable-expires-shared \
--enable-rewrite=shared \
--enable-static-support \
--with-apr=/usr/local/apr/ \
--with-apr-util=/usr/local/apr-util/bin \
--with-ssl \
--with-z 

make
make install

五、修改apache配置(/etc/httpd/httpd.conf)

# 修改#ServerName www.example.com:80 改 ServerName locahost:80

#修改用户和用户组
把user=deamon group=deamon 改成 user=www group=www

六、增加apache环境变量

cat >> /etc/profile << END
export PATH=$PATH:/usr/local/httpd/bin/
END

source /etc/profile

七、配置apache开机启动

cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd

修改你的vim /etc/init.d/httpd脚本 在开始处#!/bin/bash之后的行后插入
# chkconfig: 345 61 61
# description:Apache httpd


# 增加服务
chkconfig --add httpd
chkconfig --level 2345 httpd on

八、启动|停止|重启apache方式

启动|停止|重启   /etc/init.d/httpd start|stop|restart

#扩展
启动          /usr/local/httpd/bin/apachectl -f /etc/httpd/httpd.conf
暴力停止      /usr/local/httpd/bin/apachectl -k stop
优雅停止      /usr/local/httpd/bin/apachectl -k graceful-stop
优雅的重启   /usr/local/httpd/bin/apachectl -k graceful
暴力重启     /usr/local/httpd/bin/apachectl -k restart

九、apache和php的整合

./configure --prefix=/usr/local/php/ \
--with-config-file-path=/usr/local/php/etc/ \
--with-apxs2=/usr/local/httpd/bin/apxs \             #主要是这个模块
--enable-fpm \
--with-zlib \
--with-libxml-dir \
--enable-sockets \
--with-curl \
--with-jpeg-dir \
--with-png-dir \
--with-gd \
--with-iconv-dir \
--with-freetype-dir \
--enable-gd-native-ttf \
--with-xmlrpc \
--with-openssl \
--with-mhash \
--with-mcrypt \
--with-pear \
--enable-mbstring \
--enable-sysvshm \
--enable-zip \
--with-mysql=/usr/local/mysql/ \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-mysql-sock \
--with-pdo-mysql \
--disable-fileinfo 

make
make install

备注:libiconv和libmcrypt以及mysql应提前安装好,路径都安装在了/usr/local目录下

十、设置php支持apache配置文件

# 编辑apache配置文件
vim /etc/httpd/httpd.conf

# 添加php支持
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps

# 添加默认索引页面index.php,再找到“DirectoryIndex”,在index.html后面加上“ index.php”
DirectoryIndex index.html index.php

# 不显示目录结构,找到“Options Indexes FollowSymLinks”,修改为
Options FollowSymLinks

# 开启apache支持伪静态,找到“AllowOverride None”,修改为
AllowOverride All

十一、扩展
整合apache和nginx的php编译参数

[root@linux-node2 php-7.2.4]# ./configure --prefix=/usr/local/php/ \
--with-apxs2=/usr/local/httpd/bin/apxs \
--with-libxml-dir \
--enable-sockets \
--with-curl \
--with-jpeg-dir \
--with-png-dir \
--with-gd \
--with-iconv \
--with-freetype-dir \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-xmlrpc \
--with-openssl \
--with-mhash \
--with-mcrypt \
--with-pear \
--enable-mbstring \
--enable-sysvshm \
--with-mysql=/usr/local/mysql/ \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-mysql-sock \
--with-pdo-mysql \
--with-recode=/usr \
--with-bz2=/usr \
--disable-debug \
--disable-phpdbg \
--enable-bcmath \
--enable-calendar \
--enable-exif \
--enable-ftp \
--with-gettext=/usr \
--with-gmp=/usr/include/linux \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sysvmsg \
--enable-sysvsem \
--enable-wddx \
--with-xsl \
--disable-fileinfo \
--enable-fpm \
--enable-zip \
--with-zlib

猜你喜欢

转载自blog.csdn.net/m0_37886429/article/details/79643078