1、下载相关包、安装依赖软件
wget http://172.81.248.135/download/make_apache.tar.gz
wget http://172.81.248.135/download/php-7.1.30.tar.gz
yum install gcc -y yum -y install libtool libtool-ltdl libtool-ltdl-devel
2、解压
tar -zxf apr-1.7.0.tar.gz
tar -zxf httpd-2.4.39.tar.gz
tar -zxf apr-util-1.6.1.tar.gz
tar -zxf pcre-8.35.tar.gz
安装apr
cd apr-1.7.0 ./configure --prefix=/work/installed/apr (注意:configure安装的文件夹目录可以自己定义)
报错:rm: cannot remove `libtoolT': No such file or directory
修改configure文件修改,把RM='$RM'改为RM='$RM -f'
重新编译 ./configure --prefix=/work/installed/apr make make install
安装apr-util
cd apr-util-1.6.1
./configure --prefix=/work/installed/apr-util --with-apr=/work/installed/apr
报错:
xml/apr_xml.c:35:19: 致命错误:expat.h:没有那个文件或目录
解决方法 :
yum install -y expat-devel make make install
安装pcre
cd pcre-8.35
./configure --prefix=/work/installed/pcre
报错:
configure: error: You need a C++ compiler for C++ support.
解决办法:
yum install -y gcc gcc-c++
重新编译
./configure --prefix=/work/installed/pcre make make install
准备工作完成,下一步
安装Apache
cd httpd-2.4.39
./configure --prefix=/work/installed/apache --with-apr=/work/installed/apr \
--with-apr-util=/work/installed/apr-util --with-pcre=/work/installed/pcre --enable-module=shared
make
make install
其中--enable-module=shared表示Apache可以动态的加载模块,为以后安装php铺垫。
配置Apache:
修改配置文件,如果不修改的话就启动了apache服务的话就会出现问题:
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
解决方法:
在安装的目录下修改文件:
vim /work/installed/apache/conf/httpd.conf
# ServerName www.example.com:80
改为:
ServerName localhost:80
防火墙开放端口:
firewall-cmd --zone=public --add-port=80/tcp --permanent firewalld-cmd --reload
设置开机自启,添加以下内容到/etc/init.d
vim /etc/init.d/apache
#!/bin/bash
# chkconfig: 12345 80 90
function start_http()
{
/work/installed/apache/bin/apachectl start
}
function stop_http()
{
/work/installed/apache/bin/apachectl stop
}
case "$1" in
start)
start_http
;;
stop)
stop_http
;;
restart)
stop_http
start_http
;;
*)
echo "Usage : start | stop | restart"
;;
esac
添加执行权限
chmod +x /etc/rc.d/init.d/apache
chmod +x /etc/init.d/apache
chkconfig --add apache
chkconfig apache on
启动Apache
service apache start / systemctl start apache chkconfig --add apache / chkconfig apache on / systemctl enable apache
安装PHP
CentOS源不能安装libmcrypt-devel,由于版权的原因没有自带mcrypt的包。
使用php mcrypt 前必须先安装Libmcrypt
libmcrypt源码安装方法:
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz
tar -zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure -prefix=/usr/local
make
make install
echo '/usr/local/lib64 /usr/local/lib /usr/lib /usr/lib64'>>/etc/ld.so.conf&&ldconfig -v
解压PHP压缩包
tar -zxf php-7.1.30.tar.gz
cd php-7.1.30
安装依赖包: yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp \ gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel curl-devel
编译:
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/etc \
--enable-fpm \
--with-fpm-user=apache \
--with-fpm-group=apache \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mcrypt \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir=/usr/lib64/openssl \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-native-ttf \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache=no \
--with-apxs2=/work/installed/apache/bin/apxs
常见错误:
错误:/usr/local/include/zip.h:59:21: fatal error: zipconf.h: No such file or dire
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
错误:configure: error: jpeglib.h not found.
yum -y install libjpeg-devel
错误:configure: error: png.h not found.
yum -y install libpng libpng-devel
错误:configure: error: freetype-config not found.
yum install freetype-devel
错误:Configure: error: Unable to locate gmp.h
yum install gmp-devel
错误:configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
yum -y install libxslt-devel
将以下内容添加到Apache配置文件中,并重启Apache
AddType application/x-httpd-php .php
DirectoryIndex index.php index.htm index.html