11.32 php扩展模块安装
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了11.32 php扩展模块安装相关的知识,希望对你有一定的参考价值。
- 11.32 php扩展模块安装 - 扩展 - apache rewrite教程 http://coffeelet.blog.163.com/blog/static/13515745320115842755199/ http://www.cnblogs.com/top5/archive/2009/08/12/1544098.html - apache rewrite 出现死循环 http://ask.apelearn.com/question/1043 - php错误日志级别参考 http://ask.apelearn.com/question/6973 - php开启短标签 http://ask.apelearn.com/question/120 - php.ini详解 http://legolas.blog.51cto.com/2682485/493917 # 11.32 PHP扩展模块安装 - /usr/local/php/bin/php -m //查看模块 - 下面安装一个redis的模块 - cd /usr/local/src/ - wget https://codeload.github.com/phpredis/phpredis/zip/develop - mv develop phpredis-develop.zip - unzip phpredis-develop.zip - cd phpredis-develop - /usr/local/php/bin/phpize //生成configure文件 - ./configure --with-php-config=/usr/local/php/bin/php-config - make && make install - /usr/local/php/bin/php -i |grep extension_dir //查看扩展模块存放目录,我们可以在php.ini中去自定义该路径 - vim /usr/local/php/etc/php.ini //增加一行配置(可以放到文件最后一行) extension = redis.so - ``` Last login: Fri Oct 13 20:46:33 2017 [[email protected] ~]# cd /usr/local/src/ [[email protected] src]# ls apr-1.6.2 httpd-2.4.27 php-5.6.30.tar.gz apr-1.6.2.tar.gz httpd-2.4.27.tar.gz php-7.1.6 apr-util-1.6.0 mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz php-7.1.6.tar.bz2 apr-util-1.6.0.tar.gz php-5.6.30 [[email protected] src]# wget https://codeload.github.com/phpredis/phpredis/zip/develop --2017-10-13 21:20:21-- https://codeload.github.com/phpredis/phpredis/zip/develop 正在解析主机 codeload.github.com (codeload.github.com)... 192.30.255.121, 192.30.255.120 正在连接 codeload.github.com (codeload.github.com)|192.30.255.121|:443... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:未指定 [application/zip] 正在保存至: “develop” [ <=> ] 224,195 116KB/s 用时 1.9s 2017-10-13 21:20:24 (116 KB/s) - “develop” 已保存 [224195] [[email protected] src]# du -sh develop 220K develop [[email protected] src]# mv develop phpredis-develop.zip [[email protected] src]# unzip phpredis-develop.zip inflating: phpredis-develop/tests/RedisTest.php inflating: phpredis-develop/tests/TestRedis.php inflating: phpredis-develop/tests/TestSuite.php inflating: phpredis-develop/tests/make-cluster.sh inflating: phpredis-develop/tests/mkring.sh [[email protected] src]# ``` - 进入phpredis-develop 目录下 ``` [[email protected] src]# ls apr-1.6.2 httpd-2.4.27.tar.gz php-7.1.6.tar.bz2 apr-1.6.2.tar.gz mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz phpredis-develop apr-util-1.6.0 php-5.6.30 phpredis-develop.zip apr-util-1.6.0.tar.gz php-5.6.30.tar.gz httpd-2.4.27 php-7.1.6 [[email protected] src]# cd phpredis-develop [[email protected] phpredis-develop]# ls arrays.markdown CREDITS php_redis.h redis_commands.c cluster_library.c debian README.markdown redis_commands.h cluster_library.h debian.control redis_array.c redis_session.c cluster.markdown ISSUE_TEMPLATE.md redis_array.h redis_session.h common.h library.c redis_array_impl.c rpm config.m4 library.h redis_array_impl.h serialize.list config.w32 mkdeb-apache2.sh redis.c tests COPYING mkdeb.sh redis_cluster.c crc16.h package.xml redis_cluster.h [[email protected] phpredis-develop]# ``` - 用php7 /usr/local/php/bin/phpize //生成configure文件 ``` [[email protected] phpredis-develop]# /usr/local/php/bin/phpize Configuring for: PHP Api Version: 20131106 Zend Module Api No: 20131226 Zend Extension Api No: 220131226 Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script. [[email protected] phpredis-develop]# ``` - 显示没有生成 少一个包autoconf ,再继续生成./configure, ``` [[email protected] phpredis-develop]# yum install -y autoconf 已安装: autoconf.noarch 0:2.69-11.el7 作为依赖被安装: m4.x86_64 0:1.4.16-10.el7 完毕! [[email protected] phpredis-develop]# [[email protected] phpredis-develop]# /usr/local/php/bin/phpize Configuring for: PHP Api Version: 20131106 Zend Module Api No: 20131226 Zend Extension Api No: 220131226 [[email protected] phpredis-develop]# [[email protected] phpredis-develop]# ls acinclude.m4 config.h.in debian.control mkinstalldirs redis_cluster.h aclocal.m4 config.m4 install-sh package.xml redis_commands.c arrays.markdown config.sub ISSUE_TEMPLATE.md php_redis.h redis_commands.h autom4te.cache configure library.c README.markdown redis_session.c build configure.in library.h redis_array.c redis_session.h cluster_library.c config.w32 ltmain.sh redis_array.h rpm cluster_library.h COPYING Makefile.global redis_array_impl.c run-tests.php cluster.markdown crc16.h missing redis_array_impl.h serialize.list common.h CREDITS mkdeb-apache2.sh redis.c tests config.guess debian mkdeb.sh redis_cluster.c [[email protected] phpredis-develop]# ``` - ./configure ``` [[email protected] phpredis-develop]# ./configure --with-php-config=/usr/local/php7/bin/php-config 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 for cc... cc checking whether the C compiler works... yes checking for C compiler default ``` - make make install ``` [[email protected] phpredis-develop]# make See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages. ---------------------------------------------------------------------- Build complete. Don‘t forget to run ‘make test‘. [[email protected] phpredis-develop]# [[email protected] phpredis-develop]# make install Installing shared extensions: /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/ [[email protected] phpredis-develop]# ls /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/ opcache.so redis.so [[email protected] phpredis-develop]# ``` - 生成了一个redis.so 这个文件就是我们要的扩展模块 - 现在php还不支持它,没有模块文件,现在还是不支持redis 的 ``` [[email protected] phpredis-develop]# /usr/local/php7/bin/php -m [PHP Modules] bz2 Core ctype date dom exif fileinfo filter gd hash iconv json libxml mbstring mcrypt mysqli openssl pcre PDO pdo_mysql pdo_sqlite Phar posix Reflection session SimpleXML soap sockets SPL sqlite3 standard tokenizer xml xmlreader xmlwriter zlib [Zend Modules] [[email protected] phpredis-develop]# [[email protected] phpredis-develop]# /usr/local/php7/bin/php -m |grep redis [[email protected] phpredis-develop]# ``` - 所以你需要把它配置一下,把它加载一下,需要去编辑配置文件 - 先找一下扩展模块所在的路径在哪里 - /usr/local/php/bin/php -i |grep extension_dir //查看扩展模块存放目录,我们可以在php.ini中去自定义该路径 ``` [[email protected] phpredis-develop]# /usr/local/php7/bin/php -i |grep -i extension_dir extension_dir => /usr/local/php7/lib/php/extensions/no-debug-zts-20160303 => /usr/local/php7/lib/php/extensions/no-debug-zts-20160303 sqlite3.extension_dir => no value => no value [[email protected] phpredis-develop]# ``` - 实际上就是我们刚刚看的目录,这个extension_dir 也可以定义的 ``` [[email protected] phpredis-develop]# ls /usr/local/php7/lib/php/extensions/no-debug-zts-20160303 opcache.so redis.so [[email protected] phpredis-develop]# ``` - 之后需要编辑下vi /usr/local/php7/etc/php.ini ,搜索extension, 在后面加上extension=redis.so ``` [[email protected] phpredis-develop]# vi /usr/local/php7/etc/php.ini [PHP] ;;;;;;;;;;;;;;;;;;; ; About php.ini ; ;extension=php_bz2.dll ;extension=php_curl.dll ;extension=php_fileinfo.dll ;extension=php_ftp.dll ;extension=php_gd2.dll ;extension=php_gettext.dll ;extension=php_gmp.dll ;extension=php_intl.dll ;extension=php_imap.dll ;extension=php_interbase.dll ;extension=php_ldap.dll ;extension=php_mbstring.dll ;extension=php_exif.dll ; Must be after mbstring as it depends on it ;extension=php_mysqli.dll ;extension=php_oci8_12c.dll ; Use with Oracle Database 12c Instant Client ;extension=php_openssl.dll ;extension=php_pdo_firebird.dll ;extension=php_pdo_mysql.dll ;extension=php_pdo_oci.dll ;extension=php_pdo_odbc.dll ;extension=php_pdo_pgsql.dll ;extension=php_pdo_sqlite.dll ;extension=php_pgsql.dll ;extension=php_shmop.dll extension=redis.so ; The MIBS data available in the PHP distribution must be installed. :wq ``` - dll后缀名结尾的,都是Windows使用的模块 - 添加好配置以后查询模块是否存在 - 已经加载了 redis ``` [[email protected] phpredis-develop]# vi /usr/local/php7/etc/php.ini [[email protected] phpredis-develop]# /usr/local/php7/bin/php -m |grep redis redis [[email protected] phpredis-develop]# ``` - 如果你想编译一个模块,而且他自带的源码包目录/usr/local/src/php-5.6.30/ext 下有,那么只需要进行以下一些步骤,就可以完成扩展模块新增 1、在你需要增加的拓展模块的目录下执行 /usr/local/php/bin/phpize ,生成一个configure 文件 2、执行 ./configure –with-php-config=/usr/local/php/bin/php-config 配置php-config文件 3、开始编译 make 4、编译后移动到目录 make install 5、修改配置文件vim /usr/local/php/etc/php.ini ,新增所需extension=xxxx.so 拓展模块 - 这就是php的扩展模块安装 - 当然还要一种方法 redis 和 是属于第三方的 ,它在php源码包里面本身是没有的 ``` [[email protected] phpredis-develop]# cd [[email protected] ~]# cd /usr/local/src/ [[email protected] src]# cd php-7.1.6 [[email protected] php-7.1.6]# ls acinclude.m4 LICENSE README.namespaces aclocal.m4 ltmain.sh README.NEW-OUTPUT-API appveyor main README.PARAMETER_PARSING_API build makedist README.REDIST.BINS buildconf Makefile README.RELEASE_PROCESS buildconf.bat Makefile.frag README.SELF-CONTAINED-EXTENSIONS CODING_STANDARDS Makefile.fragments README.STREAMS config.guess Makefile.gcov README.SUBMITTING_PATCH config.log Makefile.global README.TESTING config.nice Makefile.objects README.TESTING2 config.status makerpm README.UNIX-BUILD-SYSTEM config.sub meta_ccld README.WIN32-BUILD-SYSTEM configure missing run-tests.php configure.in mkinstalldirs sapi CONTRIBUTING.md modules scripts CREDITS netware server-tests-config.php ext NEWS server-tests.php EXTENSIONS pear snapshot footer php7.spec stamp-h.in generated_lists php7.spec.in stub.c genfiles php.gif tests header php.ini-development travis include php.ini-production TSRM INSTALL README.EXT_SKEL UPGRADING install-sh README.GIT-RULES UPGRADING.INTERNALS libphp7.la README.input_filter vcsclean libs README.MAILINGLIST_RULES win32 libtool README.md Zend [[email protected] php-7.1.6]# ``` - 实际上在php源码包里面 有个 ext的目录,这个下面有很多的 这种 所谓的模块 ``` [[email protected] php-7.1.6]# cd ext/ [[email protected] ext]# ls bcmath ext_skel interbase opcache pdo_sqlite skeleton tokenizer bz2 ext_skel_win32.php intl openssl pgsql snmp wddx calendar fileinfo json pcntl phar soap xml com_dotnet filter ldap pcre posix sockets xmlreader ctype ftp libxml pdo pspell spl xmlrpc curl gd mbstring pdo_dblib readline sqlite3 xmlwriter date gettext mcrypt pdo_firebird recode standard xsl dba gmp mysqli pdo_mysql reflection sysvmsg zip dom hash mysqlnd pdo_oci session sysvsem zlib enchant iconv oci8 pdo_odbc shmop sysvshm exif imap odbc pdo_pgsql simplexml tidy [[email protected] ext]# [[email protected] ext]# /usr/local/php7/bin/php -m |grep zip [[email protected] ext]# ``` - 比如说现在没有zip ,假如说没有zip - 那我现在需要编译一个zip,先进入到zip目录下来,然后直接执行 /usr/local/php7/bin/phpize ``` [[email protected] ext]# /usr/local/php7/bin/php -m |grep zip [[email protected] ext]# cd zip/ [[email protected] zip]# ls config.m4 CREDITS lib php_zip.c tests zip_stream.c config.w32 examples LICENSE_libzip php_zip.h TODO [[email protected] zip]# /usr/local/php7/bin/phpize Configuring for: PHP Api Version: 20160303 Zend Module Api No: 20160303 Zend Extension Api No: 320160303 [[email protected] zip]# ``` - 也就是说你想编译一个扩展模块的时候,如果它 自带的源码包里面 ext 目录下有这个目录 ,那你就可以直接在这去编译它 不用去下载了 - /usr/local/php7/bin/phpize 完成之后呢,./configure ``` [[email protected] zip]# ./configure --with-php-config=/usr/local/php7/bin/php-config creating libtool appending configuration tag "CXX" to libtool configure: creating ./config.status config.status: creating config.h [[email protected] zip]# ``` - make ,make install ``` [[email protected] zip]# make Build complete. Don‘t forget to run ‘make test‘. [[email protected] zip]# make install Installing shared extensions: /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/ [[email protected] zip]# [[email protected] zip]# ls /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/ opcache.so redis.so zip.so [[email protected] zip]# ``` - 里面多了一个zip.so ,这个就是怎么去添加一个扩展模块 ### 扩展 - 1. apache rewrite教程 http://coffeelet.blog.163.com/blog/static/13515745320115842755199/ http://www.cnblogs.com/top5/archive/2009/08/12/1544098.html - 2. apache rewrite 出现死循环 http://ask.apelearn.com/question/1043 我的一条规则 RewriteRule ^(.*) /111/$1 [R,L] 使用curl测试,没有问题,但是使用浏览器访问时,出现了无限循环。 本来访问的是 www.111.com 结果变成了 www.111.com/111/111/111/..... 虽然在最后加了 [L] 依然不管用,可能apache还是不够智能,一直满足条件就一直去匹配,一直去跳转。最后没招了只能再加一个条件。 RewriteCond %{REQUEST_URI} !^/111 RewriteRule ^(.*) /111/$1 [R,L] 这样就不再循环了。 - 3. php错误日志级别参考 http://ask.apelearn.com/question/6973 php的错误日志级别 error_report ; E_ALL 所有错误和警告(除E_STRICT外) ; E_ERROR 致命的错误。脚本的执行被暂停。 ; E_RECOVERABLE_ERROR 大多数的致命错误。 ; E_WARNING 非致命的运行时错误,只是警告,脚本的执行不会停止。 ; E_PARSE 编译时解析错误,解析错误应该只由分析器生成。 ; E_NOTICE 脚本运行时产生的提醒(往往是我们写的脚本里面的一些bug,比如某个变量没有定义),这个错误不会导致任务中断。 ; E_STRICT 脚本运行时产生的提醒信息,会包含一些php抛出的让我们要如何修改的建议信息。 ; E_CORE_ERROR 在php启动后发生的致命性错误 ; E_CORE_WARNING 在php启动后发生的非致命性错误,也就是警告信息 ; E_COMPILE_ERROR php编译时产生的致命性错误 ; E_COMPILE_WARNING php编译时产生的警告信息 ; E_USER_ERROR 用户生成的错误 ; E_USER_WARNING 用户生成的警告 ; E_USER_NOTICE 用户生成的提醒 & 表示并且 ~ 表示非 | 表示或者 比如: error_reporting = E_ALL & ~E_NOTICE 表示错误级别为E_ALL 并且除了E_NOTICE - 4. php开启短标签 http://ask.apelearn.com/question/120 控制参数: short_open_tag = On 如果设置为Off,则不能正常解析类似于这样形式的php文件: <? phpinfo() ?> 而只能解析 <?php phpinfo() ?> 这样形式的php文件 所以要想php支持短标签,需要我们把short_open_tag 设置为On. - 5. php.ini详解 http://legolas.blog.51cto.com/2682485/493917
以上是关于11.32 php扩展模块安装的主要内容,如果未能解决你的问题,请参考以下文章