编译安装PHP
官网下载地址:https://www.php.net/downloads.php#gpg-7.2
PHP扩展源:
- rpm -ivh http://mirror.webtatic.com/yum/el7/webtatic-release.rpm
- yum -y localinstall http://mirror.webtatic.com/yum/el7/webtatic-release.rpm
首先先卸载系统自带的PHP
[root@apache-web /]# yum remove php-mysql php php-fom php-common -y
安装PHP扩展源
[root@apache-web /]# yum -y localinstall http://mirror.webtatic.com/yum/el7/webtatic-release.rpm
PHP各版本相关依赖
PHP5.3
yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses curl openssl-devel gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel readline-devel libxslt-devel expat-devel xmlrpc-c xmlrpc-c-devel
PHP5.4
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-devel openssl openssl-devel openldap openldap-devel openldap-clients openldap-servers libmcrypt libmcrypt-devel libaio libaio-devel
PHP5.6
yum install -y gcc gcc-c++ make zlib-devel libxm12-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel libpng-devel gd-devel libcurl-devel libxslt-devel -y
PHP7.1
yum -y install gcc gcc-c++ make 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
PHP7.2(包含nginx依赖)
yum -y install pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel
不含:
yum -y install gcc gcc-c++ libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel libxslt libicu-devel libxslt-devel openldap openldap-devel
PHP7.3
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
今天的主角是PHP7.2
[root@apache-web tools]# tar xf php-7.2.28.tar.gz
[root@apache-web tools]# cd php-7.2.28/
[root@apache-web tools]#cp -frp /usr/lib64/libldap* /usr/lib/
[root@apache-web php-7.2.28]# ./configure --prefix=/server/php72 --with-apxs2=/usr/local/apache/bin/apxs --with-config-file-path=/server/php72/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mysqlnd-compression-support --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --with-mcrypt --with-libmbfl --enable-ftp --with-gd --enable-gd-jis-conv --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache --with-pear --enable-maintainer-zts --with-ldap=shared --without-gdbm --with-mysql-sock=/server/mysql/mysql.sock
./configure --prefix=/usr/local/php \
--with-apxs2=/usr/local/apache/bin/apxs
- 编译 Apache 模块。DIR 是 Apache 源程序的最高一级目录。默认为 /usr/local/apache
--with-config-file-path=/usr/local/php/etc \
- 指定php.ini位置
--enable-fpm \
- 打开ftp的支持
--with-fpm-user=www \
- 指定 fpm的用户
--with-fpm-group=www \
- 指定 fpm的用户组
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-mysqlnd-compression-support \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--enable-intl \
--with-mcrypt \
--with-libmbfl \
--enable-ftp \
--with-gd \
--enable-gd-jis-conv \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext \
--disable-fileinfo \
--enable-opcache \
--with-pear \
--enable-maintainer-zts \
--with-ldap=shared \
--without-gdbm \
-----------------------------------------------------------------
错误一:
configure: error: Cannot find ldap libraries in /usr/lib.
解决办法:
cp -frp /usr/lib64/libldap* /usr/lib/
错误二:
configure: WARNING: unrecognized options: --with-mcrypt, --enable-gd-native-ttf
解决办法:
php7+版本不支持 --with-mcrypt, --enable-gd-native-ttf,把这两个选项删除掉。也不支持 --with-mysql
因为根分区满了,根分区设定的标准分区没有用LVM扩容卡住了,换了台服务器继续肝
进行编译和编译安装
[root@kk php-7.2.28]# make -j 4
提示进行测试:(时间有些长)
Build complete. Don't forget to run 'make test'.
直接安装
[root@kk php-7.2.28]# make install
生成PHP的配置文件
还是在安装目录
[root@kk php-7.2.28]# ls php.*
php.gif php.ini-development php.ini-production
php.ini-development(开发环境)
php.ini-production(生成环境)
把这个配置文件拷贝过去
[root@kk php-7.2.28]# cp -a php.ini-production /server/php72/etc/php.ini
Apache关联PHP
在httpd的主配置文件中添加一行,随便找个地方,不要再功能模块里,最下面也行
[root@kk php-7.2.28]# vim /usr/local/apache/conf/httpd.conf
Addtype application/x-httpd-php .php .phtml
配置好,测试一下是否关联成功
[root@kk apache]# ll htdocs/ total 4 -rw-r--r-- 1 www www 45 Jun 12 2007 index.html [root@kk apache]# echo hehe > htdocs/a.php [root@kk apache]# ll htdocs/ total 8 -rw-r--r-- 1 root www 5 Mar 1 03:13 a.php -rw-r--r-- 1 www www 45 Jun 12 2007 index.html
再LAMP里PHP关联好不需要启动,修改PHP只需重启apache就可以生效,和LNMP还不一样
在/htdocs/写一个测试文件
[root@kk apache]# cat htdocs/a.php
<?php
phpinfo();
?>
在主配置文件中,禁止显示索引目录功能
<Directory ""> Options Indexes FollowSymLinks # 修改为: Options FollowSymLinks AllowOverride None Allow from all </Directory>
进行测试

评论