apache中的php模块安装

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解压目录下的编译参数,对于编译中出现的错误,笔记结尾有解答

[[email protected] 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.inc

Build complete.
Don‘t forget to run ‘make test‘.

[[email protected] php-5.6.37]# echo $?
0


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

[[email protected] 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: phpize
  program: php-config
Installing man pages: /usr/local/php5/php/man/man1/
  page: phpize.1
  page: 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/
[[email protected] php-5.6.37]# echo $?
0


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

[[email protected] 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模块文件跟数据库进行交互

[[email protected] 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的配置文件,并查看是否加载配置文件

[[email protected] ]# cp /usr/local/src/php-5.6.37/php.ini-production /usr/local/php5/etc/php.ini
[[email protected] php-5.6.37]# /usr/local/php5/bin/php -i |less

phpinfo()
PHP Version => 5.6.37

System => 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启动时启动该模块

[[email protected] ]# 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

[[email protected] 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 完成安装


[[email protected] 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.inc

Build complete.
Don‘t forget to run ‘make test‘.

[[email protected] php-7.2.8]# echo $?
0

[[email protected] 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: phpize
  program: php-config
Installing man pages:             /usr/local/php7/php/man/man1/
  page: phpize.1
  page: 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的配置文件

[[email protected] php-7.2.8]# cp /usr/local/src/php-7.2.8/php.ini-production /usr/local/php7/etc/php.ini
[[email protected] php-7.2.8]# /usr/local/php7/bin/php -i
phpinfo()
PHP Version => 7.2.8

System => 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配置注释掉即可

[[email protected] ]# 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

原文地址:http://blog.51cto.com/8844414/2152787

时间: 2024-10-10 08:44:48

apache中的php模块安装的相关文章

在Apache中使用mod_rewrite模块重写URL

如果有使用第三方框架做项目时,url路径是可以同过框架给的方法来设定的(如thinkphp),但如果使用原生php写的项目又想重写url,则可通过apache的一些设置来达到想要的效果. 在更改apache的配置之前,应该先了解一些apache的知识:apache中的Directory标签的作用是用于标记我们如何在特定目录订制apache的行为.该标签里会有一个绝对路径,该路径就是你想订制行为的目录. 总体通过apache修改URL的思路就是,在.htaccess文来中对你想要重写的url地址进

在apache中增加SSL模块

首先,使用 whereis openssl 命令获取lib和include的路径, 然后 在apache 源码的modules/ssl文件夹下,使用命令apxs  -i -a  -D HAVE_OPENSSL=1 -I/usr/include/openssl/ -L/usr/lib64/openssl/ -c *.c -lcrypto -lssl -ldl

wdlinux中apache配置反向代理模块

想要在.htaccess中开启反向代理功能都不行[apache中没有mod_proxy模块] .htaccess 文件内容如下 RewriteEngine On RewriteBase / RewriteRule ^(.*)$ http://sogou.weixin.com/$1 [P] "proxy|P"(强制为代理) 此标记使替换成分被内部地强制作为代理请求发送,并立即中断重写处理,然后把处理移交给mod_proxy模块.你必须确保此替换串是一个能够被mod_proxy处理的有效U

apache中若干模块的安装

第一次手动安装apache,由于在./configure -prefix=/usr/local/apache2 -enable-module=so这样配置,导致后来不得不手动安装一些模块,遇到了一些坑,上网查的资料各种形式的都有,但是实际可用不多,有的根据自己的安装方式还需更改一下配置,以下总结几个常用动态模块的安装: 1.proxy,proxy_http 进入apache源码的模块目录进行编译cd httpd-2.0.63/modules/proxy//usr/local/apache/bin

apache中配置php支持模块模式、cgi模式和fastcgi模式

apache中配置php支持模块模式.cgi模式和fastcgi模式 首先安装apache.MySQL和PHP,依次顺序安装. 1.apache.mysql的安装比较简单,略过 2. php的安装,我安装的是php5.3.6内置了php-fpm,所以不需要再单独下补丁了. ./configure –prefix=/usr/local/php5 /--with-mysql=/usr/local/mysql /--enable-fpm--with-apxs2=/usr/local/apache/bi

php在apache中一共有三种工作方式:CGI模式、FastCGI模式、Apache 模块DLL

php在apache中一共有三种工作方式:CGI模式.FastCGI .FastCGI是什么? FastCGI是语言无关的.可伸缩架构的CGI开放扩展,其主要行 为是将CGI解释器进程保持在内存中并因此获得较高的性能.众所周知,CGI解释器的反复加载是CGI性能低下的主要原因,如果CGI解释器保持在内存中 并接受FastCGI进程管理器调度,则可以提供良好的性能.伸缩性.Fail-Over特性等等. FastCGI的官方站点在http://www.fastcgi.com 1.Web Server

python中如何使用pip安装自己的第三方模块

系统:CentOS6.8    python版本:python3.5 文本编辑器:vim python中我们很多时候,需要将自己的py文件导入到python路径中,但是我们自己的文件自身并不在python默认的库文件路径下,这时候就需要我们自己将我们的py文件import进入了 下面示例怎么导入自己的第三方模块,我们首先需要自己创建一个.py文件,名字随意明名了,但是不要和python内部模块重命,内部模块路径在/usr/lib/python3.5/site-packages.要不然使用pyth

express模块安装后cmd中不能运行

在各种关于NodeJS的教材中,必定会有关于express的介绍.express本身是一个很赞的库. 在之前的express版本中,在全局模式安装(npm -g install express)之后,在cmd命令行中,都可以使用express命令进行各种操作(创建简单的网站模板等). 但是,现在安装后,发现cmd中不再支持express命令. 解决:再安装一个express-generator模块即可. npm -g install express-generator 以下是express官方关

修改WAMPServer(Apache+PHP+MySQL一键式安装)中mysql默认空密码

WampServer: Apache+PHP+MySQL一键式安装 WAMP安装好后,mysql密码是为空的,那么要如何修改呢?其实很简单,通过几条指令就行了,下面我就一步步来操作. 首先,通过WAMP打开mysql控制台. 提示输入密码,因为现在是空,所以直接按回车. 然后输入"use mysql",意思是使用mysql这个数据库,提示"Database changed"就行. 然后输入要修改的密码的sql语句"update user set passw