Centos7.4 编译安装php7.2.31 apache篇

:尽量少yum安装。

假定已经安装好了httpd,如果没有就yum install httpd,注意还要安装yum install httpd-devel

以下是步骤:

1. 安装先决条件

yum install -y gcc gcc-c++ make automake autoconf gd file bison patch mlocate flex diffutils 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 libcurl libcurl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers openldap-devellibxslt-devel kernel-devel libtool-libs readline-devel gettext-devel libcap-devel php-mcrypt libmcrypt libmcrypt-devel recode-devel gmp-devel icu libxslt libxslt-devel php-devel

2. 下载php7.2.31.tar.gz,到 /usr/src目录, 解压,进入php源文件目录

cd /usr/src

wget https://www.php.net/distributions/php-7.2.31.tar.gz

tar -xvf php-7.2.31.tar.gz  

cd php-7.2.31/

3. 停止httpd服务

systemctl stop httpd.service

4. 编译配置&安装

./configure --help命令可以列出当前可用的所有参数。

因为要用apache,所以确认一下apxs目录

find / -name apxs

得到 /usr/bin/apxs ,如果没有找到,安装一下httpd-devel:yum intall httpd-devel

执行以下命令进行编译配置:(编译选项说明见文末附件)

./configure --prefix=/usr/local/php --with-apxs2=/usr/bin/apxs --with-config-file-path=/usr/local/php/etc --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-pdo --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir= --enable-xml --enable-session --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --enable-pcntl --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache --enable-maintainer-zts --with-xsl --enable-tokenizer

编译配置完毕:

Build complete.Don't forget to run 'make test'.Installing PHP SAPI module: apache2handler/usr/lib64/httpd/build/instdso.sh SH_LIBTOOL='/usr/lib64/apr-1/build/libtool' libphp7.la /usr/lib64/httpd/modules/usr/lib64/apr-1/build/libtool --mode=install install libphp7.la /usr/lib64/httpd/modules/libtool: install: install .libs/libphp7.so /usr/lib64/httpd/modules/libphp7.solibtool: install: install .libs/libphp7.lai /usr/lib64/httpd/modules/libphp7.lalibtool: install: warning: remember to run `libtool --finish /usr/src/php-7.2.31/libs'chmod 755 /usr/lib64/httpd/modules/libphp7.so[activating module `php7' in /etc/httpd/conf/httpd.conf]Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20170718/Installing PHP CLI binary: /usr/local/php/bin/Installing PHP CLI man page: /usr/local/php/php/man/man1/Installing phpdbg binary: /usr/local/php/bin/Installing phpdbg man page: /usr/local/php/php/man/man1/Installing PHP CGI binary: /usr/local/php/bin/Installing PHP CGI man page: /usr/local/php/php/man/man1/Installing build environment: /usr/local/php/lib/php/build/Installing header files: /usr/local/php/include/php/Installing helper programs: /usr/local/php/bin/ program: phpize program: php-configInstalling man pages: /usr/local/php/php/man/man1/ page: phpize.1 page: php-config.1Installing PEAR environment: /usr/local/php/lib/php/[PEAR] Archive_Tar - installed: 1.4.9[PEAR] Console_Getopt - installed: 1.4.3[PEAR] Structures_Graph- installed: 1.1.1[PEAR] XML_Util - installed: 1.4.5warning: pear/PEAR dependency package "pear/Archive_Tar" installed version 1.4.9 is not the recommended version 1.4.4[PEAR] PEAR - installed: 1.10.12Wrote PEAR system config file at: /usr/local/php/etc/pear.confYou may want to add: /usr/local/php/lib/php to your php.ini include_path/usr/src/php-7.2.31/build/shtool install -c ext/phar/phar.phar /usr/local/php/binln -s -f phar.phar /usr/local/php/bin/pharInstalling PDO headers: /usr/local/php/include/php/ext/pdo/

安装:

make && make install

5. 配置php.ini

将安装包的php.ini.product 复制到php安装目录

cp php.ini-production /usr/local/php/etc/php.ini

配置php.ini

date.timezone = PRC

expose_php=Off

6. 配置apache,支持php

vim /etc/httpd/conf/httpd.conf

检查有没有添加 LoadModule php7_module /usr/lib64/httpd/modules/libphp7.so ,没有就添加。

Apache配置扩展名解析成 PHP

在http.conf文件尾部加入:

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

7. 配置环境变量

新建php环境变量

touch /etc/profile.d/php.sh

打开php.sh文件并写入:

PATH=$PATH:/usr/local/php/bin

导出

export PATH

使配置文件生效

source /etc/profile

查看php 版本,确认已经安装成功

8. 启动apache

service httpd restart

在web目录建phpinfo文件查看。


【PHP编译参数说明】

引自:https://www.cnblogs.com/hubing/p/3735452.html

在Linux下安装PHP,源代码方式安装,总需要配置很多参数。这里列出常用配置参数,并详细用中文解释说明了。给大家一些参考

编译PHP的时候慎用 –with-curlwrappers参数

./configure

--prefix=/usr/local/PHP                                   php 安装目录

--with-apxs2=/usr/local/apache/bin/apxs     表示使用apache2.0以上版本,apxs表示使用的apache1.0版本

--with-config-file-path=/usr/local/PHP/etc               指定php.ini位置

--with-MySQL=/usr/local/mysql                        mysql安装目录,对mysql的支持

--with-MySQLi=/usr/local/mysql/bin/mysql_config            mysqli文件目录,优化支持

--enable-safe-mode                              打开安全模式

--enable-ftp                                 打开ftp的支持

--enable-zip                                 打开对zip的支持

--with-bz2                                    打开对bz2文件的支持                      

--with-jpeg-dir                                 打开对jpeg图片的支持

--with-png-dir                                 打开对png图片的支持

--with-freetype-dir                              打开对freetype字体库的支持

--without-iconv                                 关闭iconv函数,种字符集间的转换

--with-libXML-dir                                 打开libxml2库的支持

--with-XMLrpc                                 打开xml-rpc的c语言

--with-zlib-dir                                 打开zlib库的支持

--with-gd                                    打开gd库的支持

--enable-gd-native-ttf                           支持TrueType字符串函数库

--with-curl                                    打开curl浏览工具的支持

--with-curlwrappers                              运用curl工具打开url流

--with-ttf                                    打开freetype1.*的支持,可以不加了

--with-xsl 打开XSLT 文件支持,扩展了libXML2库 ,需要libxslt软件

--with-gettext                                 打开gnu 的gettext 支持,编码库用到

--with-pear                      打开pear命令的支持,PHP扩展用的

--enable-calendar                  打开日历扩展功能

--enable-mbstring                  多字节,字符串的支持

--enable-bcmath                  打开图片大小调整,用到zabbix监控的时候用到了这个模块

--enable-sockets                  打开 sockets 支持

--enable-exif                      图片的元数据支持

--enable-magic-quotes               魔术引用的支持

--disable-rpath                     关闭额外的运行库文件

--disable-debug                  关闭调试模式

--with-mime-magic=/usr/share/file/magic.mime      魔术头文件位置

CGI方式安装才用的参数

--enable-fpm                     打上PHP-fpm 补丁后才有这个参数,CGI方式安装的启动程序

--enable-fastCGI                  支持fastcgi方式启动PHP

--enable-force-CGI-redirect             同上 ,帮助里没有解释

--with-ncurses                     支持ncurses 屏幕绘制以及基于文本终端的图形互动功能的动态库

--enable-pcntl                     freeTDS需要用到的,可能是链接mssql 才用到

mhash和mcrypt算法的扩展

--with-mcrypt                     算法

--with-mhash                     算法

--with-gmp

--enable-inline-optimization

--with-openssl                     openssl的支持,加密传输时用到的

--enable-dbase

--with-pcre-dir=/usr/local/bin/pcre-config      perl的正则库案安装位置

--disable-dmalloc

--with-gdbm                     dba的gdbm支持

--enable-sigchild

--enable-sysvsem

--enable-sysvshm

--enable-zend-multibyte               支持zend的多字节

--enable-mbregex

--enable-wddx

--enable-shmop

--enable-soap

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,907评论 6 506
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,987评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,298评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,586评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,633评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,488评论 1 302
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,275评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,176评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,619评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,819评论 3 336
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,932评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,655评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,265评论 3 329
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,871评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,994评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,095评论 3 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,884评论 2 354