php的官网:http://php.net
php5版本的对Discuz这个论坛支持解析,有较好的兼容性,不过在php7及以后的版本对discuz这个论坛不兼容,php7可能也对某些相关软件兼容性不是很好

安装php5
环境:安装了http和mysql服务,安装php时必须指定http和mysql的服务安装路径
首先下载对应的php版本,这里下载的是php5.6.37
解压php,并在解压目录下执行编译参数
关于编译参数解释:

./configure --prefix=/usr/local/php5 \            指定php安装目录
--with-apxs2=/usr/local/httpd/bin/apxs \         指定http目录,编译中可向http配置文件中添加php
--with-config-file-path=/usr/local/php/etc \     指定php的配置文件目录
--with-mysql=/usr/local/mysql \                  指定mysql的安装目录和mysql的库路径
--with-pdo-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-libxml-dir \                                以下是指定php需要编译支持的函数库
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir \
--with-bz2 \
--with-openssl \
--with-mcrypt \
--enable-soap \
--enable-gd-native-ttf \
--enable-sockets \
--enable-exif\

在php解压目录下的编译参数,对于编译中出现的错误,笔记结尾有解答

[root@localhost php-5.6.37]# ./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/httpd/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-sockets --enable-exif-------------------------编译过程忽略-----------------------

make过程后的结果

-----------------------make开头信息省略------------------------
Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
clicommand.inc
directorytreeiterator.inc
invertedregexiterator.inc
directorygraphiterator.inc
pharcommand.inc
phar.incBuild complete.
Don't forget to run 'make test'.[root@localhost php-5.6.37]# echo $?
0

make install 过程,其中有警告,提示libtool这个模块未正常加载,这里忽略

[root@localhost php-5.6.37]# make install
Installing PHP SAPI module: apache2handler
/usr/local/httpd/build/instdso.sh SH_LIBTOOL='/usr/local/apr/build-1/libtool' libphp5.la /usr/local/httpd/modules
/usr/local/apr/build-1/libtool --mode=install install libphp5.la /usr/local/httpd/modules/
libtool: install: install .libs/libphp5.so /usr/local/httpd/modules/libphp5.so
libtool: install: install .libs/libphp5.lai /usr/local/httpd/modules/libphp5.la
libtool: warning: remember to run 'libtool --finish /usr/local/src/php-5.6.37/libs'
chmod 755 /usr/local/httpd/modules/libphp5.so
[activating module `php5' in /usr/local/httpd/conf/httpd.conf]
Installing shared extensions: /usr/local/php5/lib/php/extensions/no-debug-zts-20131226/
Installing PHP CLI binary: /usr/local/php5/bin/
Installing PHP CLI man page: /usr/local/php5/php/man/man1/
Installing PHP CGI binary: /usr/local/php5/bin/
Installing PHP CGI man page: /usr/local/php5/php/man/man1/
Installing build environment: /usr/local/php5/lib/php/build/
Installing header files: /usr/local/php5/include/php/
Installing helper programs: /usr/local/php5/bin/program: phpizeprogram: php-config
Installing man pages: /usr/local/php5/php/man/man1/page: phpize.1page: php-config.1
Installing PEAR environment: /usr/local/php5/lib/php/
[PEAR] Archive_Tar - installed: 1.4.3
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util - installed: 1.4.2
[PEAR] PEAR - installed: 1.10.5
Wrote PEAR system config file at: /usr/local/php5/etc/pear.conf
You may want to add: /usr/local/php5/lib/php to your php.ini include_path
/usr/local/src/php-5.6.37/build/shtool install -c ext/phar/phar.phar /usr/local/php5/bin
ln -s -f phar.phar /usr/local/php5/bin/phar
Installing PDO headers: /usr/local/php5/include/php/ext/pdo/
[root@localhost php-5.6.37]# echo $?
0

在结合apache安装php中,php只是编译一个模块给apache使用,php模块是/usr/local/httpd/modules/libphp5.so

[root@localhost php-5.6.37]# ll -h /usr/local/httpd/modules/libphp5.so
-rwxr-xr-x 1 root root 34M 7月 29 08:27 /usr/local/httpd/modules/libphp5.so

查看php加载的模块,使用php目录下的一个可执行文件查看,php在apache中是以模块来进行加载的,php模块就是/usr/local/httpd/modules/libphp5.so 文件, apache在解析php时会自动加载php模块文件跟数据库进行交互

[root@localhost php-5.6.37]# /usr/local/php5/bin/php -m
[PHP Modules]
bz2
Core
ctype
date
dom
ereg
exif
fileinfo
filter
gd
hash
iconv
json
libxml
mcrypt
mysql
mysqli
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter[Zend Modules]

拷贝php的配置文件,并查看是否加载配置文件

[root@localhost ]# cp /usr/local/src/php-5.6.37/php.ini-production /usr/local/php5/etc/php.ini
[root@localhost php-5.6.37]# /usr/local/php5/bin/php -i |lessphpinfo()
PHP Version => 5.6.37System => Linux localhost.localdomain 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64
Build Date => Jul 29 2018 08:17:07
Configure Command => './configure' '--prefix=/usr/local/php5' '--with-apxs2=/usr/local/httpd/bin/apxs' '--with-config-file-path=/usr/local/php/etc' '--with-mysql=/usr/local/mysql' '--with-pdo-mysql=/usr/local/mysql' '--with-mysqli=/usr/local/mysql/bin/mysql_config' '--with-libxml-dir' '--with-gd' '--with-jpeg-dir' '--with-png-dir' '--with-freetype-dir' '--with-iconv-dir' '--with-bz2' '--with-openssl' '--with-mcrypt' '--enable-soap' '--enable-gd-native-ttf' '--enable-sockets' '--enable-exif'
Server API => Command Line Interface
Virtual Directory Support => enabled
Configuration File (php.ini) Path => /usr/local/php/etc           <-------加载的php配置文件
Loaded Configuration File => (none)
Scan this dir for additional .ini files => (none)

查看apache配置文件中加载php配置项,注释表示不在apache启动时启动该模块

[root@localhost ]# vim /usr/local/httpd/conf/httpd.conf
~
#LoadModule rewrite_module modules/mod_rewrite.so
LoadModule php5_module modules/libphp5.so

php7安装

安装php7,编译过程和php5基本一致,需要修改php5安装时指定的安装目录和配置文件目录,否则安装php7时会覆盖掉php5

[root@localhost php-7.2.8]# ./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/httpd/bin/apxs --with-config-file-path=/usr/local/php7/etc --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-sockets --enable-exif
configure: WARNING: unrecognized options: --with-mysql, --with-mcrypt, --enable-gd-native-ttf
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
-----------------------过程省略----------------------
Thank you for using PHP.config.status: creating php7.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
configure: WARNING: unrecognized options: --with-mysql, --with-mcrypt, --enable-gd-native-ttf
编译的函数库有警告,忽略警告执行make继续编译

make继续编译php7,make install 完成安装


[root@localhost php-7.2.8]# make
/bin/sh /usr/local/src/php-7.2.8/libtool --silent --preserve-dup-deps --mode=compile /usr/local/src/php-7.2.8/meta_ccld -Iext/date/lib -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -DHAVE_TIMELIB_CONFIG_H=1 -Iext/date/ -I/usr/local/src/php-7.2.8/ext/date/ -DPHP_ATOM_INC -I/usr/local/src/php-7.2.8/include -I/usr/local/src/php-7.2.8/main -I/usr/local/src/php-7.2.8 -I/usr/local/src/php-7.2.8/ext/date/lib -I/usr/include/libxml2 -I/usr/include/freetype2 -I/usr/local/mysql/include -I/usr/local/src/php-7.2.8/ext/sqlite3/libsqlite -I/usr/local/src/php-7.2.8/TSRM -I/usr/local/src/php-7.2.8/Zend -D_REENTRANT -I/usr/include -g -O2 -fvisibility=hidden -pthread -DZTS -DZEND_SIGNALS -c /usr/local/src/php-7.2.8/ext/date/php_date.c -o ext/date/php_date.lo
-----------------------省略过程------------------------------
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
directorygraphiterator.inc
clicommand.inc
directorytreeiterator.inc
invertedregexiterator.inc
pharcommand.inc
phar.incBuild complete.
Don't forget to run 'make test'.[root@localhost php-7.2.8]# echo $?
0[root@localhost php-7.2.8]# make install                      make install编译安装最后步骤
Installing PHP SAPI module:       apache2handler
/usr/local/httpd/build/instdso.sh SH_LIBTOOL='/usr/local/apr/build-1/libtool' libphp7.la /usr/local/httpd/modules
/usr/local/apr/build-1/libtool --mode=install install libphp7.la /usr/local/httpd/modules/
libtool: install: install .libs/libphp7.so /usr/local/httpd/modules/libphp7.so
libtool: install: install .libs/libphp7.lai /usr/local/httpd/modules/libphp7.la
libtool: warning: remember to run 'libtool --finish /usr/local/src/php-7.2.8/libs'
chmod 755 /usr/local/httpd/modules/libphp7.so
[activating module `php7' in /usr/local/httpd/conf/httpd.conf]
Installing shared extensions:     /usr/local/php7/lib/php/extensions/no-debug-zts-20170718/
Installing PHP CLI binary:        /usr/local/php7/bin/
Installing PHP CLI man page:      /usr/local/php7/php/man/man1/
Installing phpdbg binary:         /usr/local/php7/bin/
Installing phpdbg man page:       /usr/local/php7/php/man/man1/
Installing PHP CGI binary:        /usr/local/php7/bin/
Installing PHP CGI man page:      /usr/local/php7/php/man/man1/
Installing build environment:     /usr/local/php7/lib/php/build/
Installing header files:          /usr/local/php7/include/php/
Installing helper programs:       /usr/local/php7/bin/program: phpizeprogram: php-config
Installing man pages:             /usr/local/php7/php/man/man1/page: phpize.1page: php-config.1
Installing PEAR environment:      /usr/local/php7/lib/php/
[PEAR] Archive_Tar    - installed: 1.4.3
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util       - installed: 1.4.2
[PEAR] PEAR           - installed: 1.10.5
Wrote PEAR system config file at: /usr/local/php7/etc/pear.conf
You may want to add: /usr/local/php7/lib/php to your php.ini include_path
/usr/local/src/php-7.2.8/build/shtool install -c ext/phar/phar.phar /usr/local/php7/bin
ln -s -f phar.phar /usr/local/php7/bin/phar
Installing PDO headers:           /usr/local/php7/include/php/ext/pdo/

同一台机器可以运行两个php,只不过在其他程序在调用时指定好需要使用的php模块
拷贝php7的配置文件

[root@localhost php-7.2.8]# cp /usr/local/src/php-7.2.8/php.ini-production /usr/local/php7/etc/php.ini
[root@localhost php-7.2.8]# /usr/local/php7/bin/php -i
phpinfo()
PHP Version => 7.2.8System => Linux localhost.localdomain 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64
Build Date => Jul 29 2018 09:54:15
Configure Command => './configure' '--prefix=/usr/local/php7' '--with-apxs2=/usr/local/httpd/bin/apxs' '--with-config-file-path=/usr/local/php7/etc' '--with-mysql=/usr/local/mysql' '--with-pdo-mysql=/usr/local/mysql' '--with-mysqli=/usr/local/mysql/bin/mysql_config' '--with-libxml-dir' '--with-gd' '--with-jpeg-dir' '--with-png-dir' '--with-freetype-dir' '--with-iconv-dir' '--with-bz2' '--with-openssl' '--with-mcrypt' '--enable-soap' '--enable-gd-native-ttf' '--enable-sockets' '--enable-exif'
Server API => Command Line Interface
Virtual Directory Support => enabled
Configuration File (php.ini) Path => /usr/local/php7/etc   <---显示了php7的配置文件
Loaded Configuration File => /usr/local/php7/etc/php.ini
Scan this dir for additional .ini files => (none)

让apache使用指定的php程序,只需要修改apache的配置文件,找到配置文件中php模块的配置项,把不需要加载的php配置注释掉即可

[root@localhost ]# vim /usr/local/httpd/conf/httpd.conf
~
LoadModule php5_module modules/libphp5.so
#LoadModule php7_module modules/libphp7.so         <------注释掉php7模块,不让它被apache动态加载

php编译中出现的问题

问题一:
php编译安装中有安装库报错,根据报错信息查找对应安装包,安装包软件一般是以devel结尾的,使用yum install 安装库名称-devel 可以正常安装该支持库

问题二:
解决:error: Cannot find libmysqlclient_r under /usr/local/mysql.
配置php的时候出现以下问题解决方案

checking for MySQL support... yes
checking for specified location of the MySQL UNIX socket...no
checking for MySQL UNIX socket location... no
configure: error: Cannot find libmysqlclient_r under/usr/local/mysql. Note that the MySQL client library is not bundledanymore!

其实这跟PHP没有关系,那是因为在编译APACHE的时候,使用--with-mpm模块,所以就必须在编译MYSQL的时候加上--enable-thread-safe-client.参数
这是PHP5.2的一个改进,在PHP5.2.0之前的版本都不需要MYSQL启用安全线程。关于--enable-thread-safe-client项的官方介绍如下:如何生成线程式客户端库总是线程安全的。最大的问题在于从套接字读取的net.c中的子程序并不是中断安全的。或许你可能希望用自己的告警中断对服务器的长时间读取,以此来解决问题。如果为SIGPIPE中断安装了中断处理程序,套接字处理功能应是线程安全的。SupeSite/X-为了避免连接中断时放弃程序,MySQL将在首次调用mysql_server_init()、mysql_init()或mysql_connect()时屏蔽SIGPIPE。如果你打算使用自己的SIGPIPE处理程序,首先应调用mysql_server_init(),然后安装你的处理程序.

还有第二种解决方法比较方便:编译之前,先处理一下mysql的库,默认查找libmysqlclient_r.so,可是mysql默认为libmysqlclient.so,内容完全一样,做个链接即可

# cd /usr/local/mysql/lib/mysql/
# ln -s libmysqlclient.so.20.0.0 libmysqlclient_r.so

转载于:https://blog.51cto.com/8844414/2152787

apache中的php模块安装相关推荐

  1. apache cgi 模块安装

    apache安装,请参照:http://httpd.apache.org/docs/2.4/ 安装系统: Fedora release 21 (Twenty One)  (x64) 版本:Server ...

  2. apache php 工作模式,PHP Apache中两种工作方式区别(CGI模式、Apache 模块DLL)

    搜索热词 对PHP在Apache中两种工作方式的区别(CGI模式.Apache 模块DLL)感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编两巴掌来看看吧! Windows 下有两种方法使 ...

  3. apache添加php语言模块,在apache中添加php处理模块-Go语言中文社区

    事先准备好一个文件夹,用来装apache和php. 步骤一 下载apache,官方:https://www.apachehaus.com/cgi-bin/download.plx 上面的是X86,下面 ...

  4. php模块是什么,apache php模块安装方法是什么

    apache php模块安装方法是什么 发布时间:2020-07-28 09:17:41 来源:亿速云 阅读:107 作者:Leah apache php模块安装方法是什么?针对这个问题,这篇文章详细 ...

  5. php rewrite模块安装,Linux_Linux下Apache安装/增加mod_rewrite模块,如果你的服务器apache还没有安 - phpStudy...

    Linux下Apache安装/增加mod_rewrite模块 如果你的服务器apache还没有安装,那很简单,在编译apache时将mod_rewrite模块编译进去就可以,相关文档可以在http:/ ...

  6. linux中默认安装php,Linux系统中Apache PHP MySQL的默认安装路径

    一直都是用一键安装包,今天帮朋友弄一Linux主机,发现原来主机商是帮用光盘安装的,很多都不一样. apache: 如果采用RPM包安装,安装路径应在 /etc/httpd目录下 apache配置文件 ...

  7. EBS R12: 通过FND_PRODUCT_INSTALLATIONS中字段STATUS确认安装使用了哪些产品(或模块)

    EBS R12.1.3 我们可以通过表  FND_PRODUCT_INSTALLATIONS 中的  STATUS 字段来确认产品是否有安装并使用 (其实在rapid install的时候产品都会 被 ...

  8. Opencv中3D显示模块viz安装

    Opencv中3D显示模块viz安装 文章目录 前言 安装cmake 编译viz 编译opencv 3.4.4 4.0.0 VS2015测试 前言    最近工作需要在VS2105中调用opencv的 ...

  9. Ubuntu20.04中fastdfs,nginx的安装和配置(apt-get安装nginx添加fastdfs-nginx-module模块)

    Ubuntu20.04中fastdfs,nginx的安装和配置 环境准备: 编译环境: Ubuntu20.04 使用的系统软件: fastdfs-6.07 fastdfs-nginx-module-1 ...

最新文章

  1. MySQL基础篇:单行函数
  2. python3精简笔记——开篇
  3. python在日常工作处理中的应用-记 Python 在实际工作中的第一次应用
  4. 常见的权限访问控制模型
  5. 数据类型和运算符_月隐学python第3课
  6. 【转载】Windwos CE 跨进程内存注入
  7. 薪资不逊NLP算法岗,边缘AI火了!
  8. juypter 不省略_常用pandas清洗数据命令
  9. 【2019杭电多校第七场1001=HDU6646】A+B=C(思维+多细节)
  10. MDF文件查看器(SQL MDF Viewer) 1.0 绿色版
  11. ssh 免密配置、修改hadoop配置文件
  12. 在配置Hive的时候出现以下错误:Error: Duplicate key name 'PCS_STATS_IDX' (state=42000,code=1061)
  13. 基于微信小程序的人脸分析学生课堂状态监测系统 文档+项目源码
  14. python抢票脚本github_春运买不到票?程序员喊你来GitHub上用抢票神器!
  15. NetApp Storage MetroCluster 双活解析
  16. Python课堂笔记之判断一个数组中是否含有数字0
  17. [安装fastfds中的nginx执行make命令报错]src/core/ngx_murmurhash.c:37:11: error
  18. win10:mingw-w64安装教程
  19. linux混合命令_十多个命令行混合
  20. 蓝牙技术|伦茨科技带你了解蓝牙智能门禁

热门文章

  1. 谷歌浏览器开启并行下载
  2. 图像处理------图像加噪
  3. C语言编写一个函数,实现计算并返回一个整数的平方(或立方)
  4. 脚手架vue-cli系列二:vue-cli的工程模板与构建工具
  5. java 数组的行数和列数
  6. 学校更换门窗计算机桌椅,学校机房建设中需要注意的细节
  7. 超硬核!MySQL优化从执行计划开始(explain超详细)
  8. 别再说自己不会了!2021年教你增加拿到BAT等大厂offer几率,醍醐灌顶!
  9. 计算机网络复习 ---- IP地址分类
  10. 计算机专业大学排名(全168所学校)