码迷,mamicode.com
首页 > Web开发 > 详细

apache中的php模块安装

时间:2018-07-31 19:23:46      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:sha   edr   文件中   serve   structure   一个   long   efault   client   

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.inc

Build 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: 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/
[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 |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启动时启动该模块

[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.inc

Build 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: 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的配置文件

[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.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配置注释掉即可

[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

apache中的php模块安装

标签:sha   edr   文件中   serve   structure   一个   long   efault   client   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!