编译安装php7.1 和httpd

1.linux环境下,先通过yum安装httpd:

yum update
yum install -y httpd

修改配置文件监听8080端口,此时访问IP:8080可以打开apache2的欢迎页,无法打开php文件。
2.安装php
先安装依赖

yum install -y gcc gcc-c++  make zlib zlib-devel pcre pcre-devel  libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

PHP官网上php7.1可以找到中国的安装包地址,使用命令:

wget http://cn2.php.net/distributions/php-7.1.6.tar.gz

下载好php-7.1.6压缩包后,使用命令:

tar -zxvf php-7.1.6.tar.gz

解压,cd进入解压后的文件夹,使用命令(此时命令没有没有把apache编译进来)

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --enable-mbstring --enable-ftp --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pear --enable-sockets --with-freetype-dir=/usr --with-zlib --with-libxml-dir=/usr --with-xmlrpc --enable-zip --enable-fpm --enable-xml --enable-sockets --with-gd --with-zlib --with-iconv --enable-zip --with-freetype-dir=/usr/lib/ --enable-soap --enable-pcntl --enable-cli --with-curl

安装

make && make install

由于没有把apache模块编译进来(也可以通过:find / -name apxs查看是否有apxs文件,这个文件是编译apache必须的),所以在apache的配置文件里找不到php7_module模块,apache还是无法读取php的,要把php7_module编译进来则需要:
3.通过yum下载httpd-devel:

yum install -y httpd-devel.x86_64

装好以后会提示
编译安装php7.1 和httpd
这样

之后重新进入php7.1源码包中,执行命令:

./configure --with-apxs2=/usr/bin/apxs

路径/usr/bin/apxs是服务器本地的apxs文件路径,编译运行后安装:

make && make install

安装完以后可以看到httpd的配置文件/etc/httpd/conf/httpd.conf中有php7_module模块了
编译安装php7.1 和httpd
同时在文件搜索DirectoryIndex,添加上index.php
编译安装php7.1 和httpd
搜索AddType,添加AddType application/x-httpd-php .php
编译安装php7.1 和httpd
以及监听端口和工作目录的配置,之后重启httpd服务

systemctl restart httpd.service

这样在工作目录建立index.php,并

echo -e "<?php\nphpinfo();\n?>" > index.php

就可以看到phpinfo页面了