The content introduced in this article is about PHP related configuration, PHP dynamic expansion module, which has certain reference value. Now I share it with you. Friends in need can refer to it
Check the location of the PHP configuration file
[root@shuai-01 111.com]# /usr/local/php/bin/php -i
Or use the phpinfo function to find it (accessed through a browser) (recommended)
[root@shuai-01 111.com]# vim index.php <?php phpinfo(); ?>
This When you access it with a browser, everything will come out
The directory where the configuration file is located, load the configuration file
If the configuration file is not loaded, go to the source code package configuration file Copy the configuration file here
[root@abc php-5.6.30]# cp /usr/local/src/php-5.6.30/php.ini-development /usr/local/php/etc/php.ini 重新加载配置文件 [root@abc php-5.6.30]# /usr/local/apache2.4/bin/apachectl graceful
There are two configuration files here (one for development and one for production environment)
Modify the PHP configuration file:
vim /usr/local/php/etc/php.ini
Dangerous function: (It also includes phpinfo. phpinfo will display all your information, which is very dangerous)
eval,assert,popen,passthru,escapeshellarg,escapeshellcmd,passthru,exec,system,chroot,scandir,chgrp,chown,escapeshellcmd,escapeshellarg,shell_exec,proc_get_status,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,leak,popepassthru,stream_socket_server,popen,proc_open,proc_close
For dangerous functions, we can disable it.
Disable functions:
Search disable_functions
Add disabled functions
disable_functions =eval,assert,popen,passthru,escapeshellarg,escapeshellcmd,passthru,exec,system,chroot ,scandir,chgrp,chown,escapeshellcmd,escapeshellarg,shell_exec,proc_get_status,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,leak,popepassthru,stream_socket_server,popen,proc_open,proc_close,phpinfo
Test at this time:
Visit 111.com/index.php
When there is a business need To use modules that are not installed when PHP is compiled and installed, you can use dynamic expansion to install the required modules.
现在介绍一下redis的安装,redis是一个nosql,在LAMP架构下一般把它当做缓存来使用。
要安装redis模块就要先下载redis这个包
下载地址:
https://codeload.github.com/phpredis/phpredis/zip/develop
[root@shuai-01 src]# wget https://codeload.github.com/phpredis/phpredis/zip/develop
改名为phpredis-develop.zip:
[root@shuai-01 src]# mv develop phpredis-develop.zip
解压这个包:
[root@shuai-01 src]# unzip phpredis-develop.zip
到phpredis-develo目录下进行编译安装:
[root@shuai-01 src]# cd phpredis-develop [root@shuai-01 phpredis-develop]# ls arrays.markdown ISSUE_TEMPLATE.md redis_array_impl.h cluster_library.c liblzf redis.c cluster_library.h library.c redis_cluster.c cluster.markdown library.h redis_cluster.h common.h mkdeb-apache2.sh redis_commands.c config.m4 mkdeb.sh redis_commands.h config.w32 package.xml redis_session.c COPYING php_redis.h redis_session.h crc16.h README.markdown rpm CREDITS redis_array.c serialize.list debian redis_array.h tests debian.control redis_array_impl.c
编译安装是要有configure文件的,这个没有,就要先生成configure文件:
生成configure文件:
[root@shuai-01 phpredis-develop]# /usr/local/php/bin/phpize Configuring for: PHP Api Version: 20131106 Zend Module Api No: 20131226 Zend Extension Api No: 220131226 [root@shuai-01 phpredis-develop]# ls acinclude.m4 crc16.h README.markdown aclocal.m4 CREDITS redis_array.c arrays.markdown debian redis_array.h autom4te.cache debian.control redis_array_impl.c build install-sh redis_array_impl.h cluster_library.c ISSUE_TEMPLATE.md redis.c cluster_library.h liblzf redis_cluster.c cluster.markdown library.c redis_cluster.h common.h library.h redis_commands.c config.guess ltmain.sh redis_commands.h config.h.in Makefile.global redis_session.c config.m4 missing redis_session.h config.sub mkdeb-apache2.sh rpm configure mkdeb.sh run-tests.php configure.in mkinstalldirs serialize.list config.w32 package.xml tests COPYING php_redis.h
编译:
[root@shuai-01 phpredis-develop]# ./configure --with-php-config=/usr/local/php/bin/php-config [root@shuai-01 phpredis-develop]# echo $? 0
make:
[root@shuai-01 phpredis-develop]# make [root@shuai-01 phpredis-develop]# echo $? 0
make install:
[root@shuai-01 phpredis-develop]# make install Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20131226/ [root@shuai-01 phpredis-develop]# echo $? 0
查看有没有生成redis.so文件:
[root@shuai-01 phpredis-develop]# ls /usr/local/php/lib/php/extensions/no-debug-zts-20131226/ opcache.so redis.so
这个时候PHP还是不支持的
[root@shuai-01 phpredis-develop]# /usr/local/php/bin/php -m |grep redis [root@shuai-01 phpredis-develop]#
通过编辑配置文件在PHP中加载redis
先找扩展模块的目录路径:
[root@shuai-01 phpredis-develop]# /usr/local/php/bin/php -i |grep -i extension_dir extension_dir => /usr/local/php/lib/php/extensions/no-debug-zts-20131226 => /usr/local/php/lib/php/extensions/no-debug-zts-20131226 sqlite3.extension_dir => no value => no value
发现在/usr/local/php/lib/php/extensions/no-debug-zts-20131226
这个extension_dir是可以自定义路径的,不过一般不会去定义它,安装的扩展模块会默认放在个目录下
编辑php.ini:
[root@shuai-01 phpredis-develop]# vim /usr/local/php/etc/php.ini
将redis.so文件加入进去
;extension=php_xmlrpc.dll ;extension=php_xsl.dll extension=redis.so
保存退出
这时就加载了:
[root@shuai-01 phpredis-develop]# /usr/local/php/bin/php -m |grep redis redis
问题1:
生成configure文件时出现:
[root@shuai-01 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.
少了autoconf这个包
安装:
[root@shuai-01 phpredis-develop]# yum install -y autoconf
安装完了之后再生成文件。
有些第三方扩展模块是要通过下载源码包来安装,有些模块是PHP源码包中自带的(在ext目录下)。
[root@shuai-01 php-5.6.30]# cd ext/ [root@shuai-01 ext]# ls bcmath ftp mysqli pgsql standard bz2 gd mysqlnd phar sybase_ct calendar gettext oci8 posix sysvmsg com_dotnet gmp odbc pspell sysvsem ctype hash opcache readline sysvshm curl iconv openssl recode tidy date imap pcntl reflection tokenizer dba interbase pcre session wddx dom intl pdo shmop xml enchant json pdo_dblib simplexml xmlreader ereg ldap pdo_firebird skeleton xmlrpc exif libxml pdo_mysql snmp xmlwriter ext_skel mbstring pdo_oci soap xsl ext_skel_win32.php mcrypt pdo_odbc sockets zip fileinfo mssql pdo_pgsql spl zlib filter mysql pdo_sqlite sqlite3
如果想安装里面的模块,直接进入模块目录下,执行phpize进行生成configure文件。
例如我现在要安装zip模块:
进入zip目录:
[root@shuai-01 ext]# cd zip/ [root@shuai-01 zip]# ls config.m4 CREDITS lib php_zip.c tests zip_stream.c config.w32 examples LICENSE_libzip php_zip.h TODO
生成configure文件:
[root@shuai-01 zip]# /usr/local/php/bin/phpize Configuring for: PHP Api Version: 20131106 Zend Module Api No: 20131226 Zend Extension Api No: 220131226
编译安装:
[root@shuai-01 zip]# ./configure --with-php-config=/usr/local/php/bin/php-config [root@shuai-01 zip]# echo $? 0
make:
[root@shuai-01 zip]# make [root@shuai-01 zip]# echo $? 0
make install:
[root@shuai-01 zip]# make install Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20131226/
查看有没有生成redis.so文件
[root@shuai-01 zip]# ls /usr/local/php/lib/php/extensions/no-debug-zts-20131226/ opcache.so redis.so zip.so
这个时候PHP还是不支持的
[root@shuai-01 zip]# /usr/local/php/bin/php -m |grep zip [root@shuai-01 zip]#
编辑php.ini:
[root@shuai-01 phpredis-develop]# vim /usr/local/php/etc/php.ini
将zip.so文件加入进去
;extension=php_xsl.dll extension=redis.so extension=zip.so
保存退出
这时就加载了:
[root@shuai-01 zip]# /usr/local/php/bin/php -m |grep zip zip
扩展
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
相关推荐:
The above is the detailed content of PHP related configuration, PHP dynamic extension module. For more information, please follow other related articles on the PHP Chinese website!