PHP相关配置
1.查找php配置文件/usr/local/php/bin/php -i或者phpinfo()
[root@bogon admin]# /usr/local/php/bin/php -i|grep -i "loaded configuration file" PHP Warning: Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function.
In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now,
but please set date.timezone to select your timezone. in Unknown on line 0 Loaded Configuration File => /usr/local/php/etc/php.ini [root@bogon admin]#
2.如果没有配置文件需要将源码包中的php配置文件拷贝进来
cp -r /usr/local/src/php-5.6.30/php.ini-production /usr/local/php/etc/php.ini
3.disable_functions 安全函数(禁止掉这些比较危险的函数)
在生产环境中会把phpinfo禁掉。因为有时候不小心写了一个phpinfo文件,上传上去被黑客发现。能够看到系统的目录。不安全
eval:一句话木马使用了该函数如果把这个函数禁了,即使上传了木马也没办法解析
[root@bogon 111.com]# vim /usr/local/php/etc/php.ini [root@bogon 111.com]#
4.date.timezone //定义时区
date.timezone =Asia/shanghai
5.display_errors = On //会把错误信息直接显示在浏览器上改成Off(生产环境该参数改成Off,为了避免暴露信息)但是有一个问题,就是页面什么都不显示(白页)。那么还需要配置错误日志。
log_errors = On //表示错误日志打开状态
6.error_log = /tmp/php_errors.log //定义错误日志所在位置
7.error_reporting //定义日志的级别,还需要定义error_log的级别。如果级别很高的话,很严谨的话,只会记录一些比较严峻的错误,不太严峻的就不记录,比如警告等、所以放松些
生产环境使用
E_ALL & ~E_NOTICE (Show all errors, except for notices)
模拟:把phpinfo函数禁掉。
1.phpinfo放入disable_functions里
2.display_errors = Off
3.log_errors = On
4.error_log = /tmp/php_errors.log
5./usr/local/apache2.4/bin/apachectl -t && graceful
6.ll /tmp/
7.cat /tmp/php_errors.log
[11-Dec-2017 21:23:49 Asia/shanghai] PHP Warning: phpinfo() has been disabled for security reasons in /data/wwwroot/discuz2/lsx/1.php on line 2
php_errors.log的属主实际是httpd的属主daemon。因为这个日志是以daemon这个进程的身份创建的。当你定义了一个日志,但是日志始终没有生成,就要看一下定义的目录有没写权限,而且写文件的进程是这个进程。
为了保守起见,可以把这个文件创建好/tmp/php_errors.log,在授权777权限
[root@bogon 111.com]# touch /tmp/php_errors.log; chmod 777 /tmp/php_errors.log
[root@bogon 111.com]# grep error_log /usr/local/php/etc/php.ini ; server-specific log, STDERR, or a location specified by the error_log ; Set maximum length of log_errors. In error_log information about the source is ;error_log = php_errors.log ;error_log = syslog ; OPcache error_log file name. Empty string assumes "stderr". ;opcache.error_log= [root@bogon 111.com]#
open_basedir 将php所能打开的文件限制在指定的目录树中,包括文件本身。当程序要使用例如fopen()或file_get_contents()打开一个文件时,这个文件的位置将会被检查。当文件在指定的目录树之外,程序将拒绝打开。
1.在php.ini 加入
open_basedir="指定目录"
2.在程序中使用
ini_set('open_basedir', '指定目录');
改php.ini有个问题,假如有多个虚拟主机这样做是不可行的,可以在虚拟主机配置文件中配置
3.httpd.conf中的VritualHost
php_admin_value open_basedir "指定目录"
<VirtualHost *:80> ServerAdmin webmaster@dummy-host.example.com DocumentRoot "/data/wwwroot/abc.com" ServerName abc.com ServerAlias www.abc.com www.123.com php_admin_value open_basedir "/data/wwwroot/abc.com:/tmp/" ErrorLog "logs/abc.com-error_log" CustomLog "logs/abc.com-access_log" common </VirtualHost>
[root@bogon tmp]# /usr/local/apache2.4/bin/apachectl graceful [root@bogon tmp]# [root@bogon tmp]# !curl curl -x127.0.0.1:80 http://111.com -I HTTP/1.1 200 OK Date: Wed, 07 Feb 2018 06:05:58 GMT Server: Apache/2.4.28 (Unix) PHP/5.6.30 X-Powered-By: PHP/5.6.30 Cache-Control: max-age=0 Expires: Wed, 07 Feb 2018 06:05:58 GMT Content-Type: text/html; charset=UTF-8 [root@bogon tmp]#
PHP扩展模块安装
http://blog.sina.com.cn/s/blog_3dbab2840100uo5l.html
1.php编译后想增加模块怎么办,下面娓娓道来,以增加redis模块为例
https://codeload.github.com/phpredis/phpredis/zip/develop
2.解压phpredis包
[root@bogon src]# wget https://codeload.github.com/phpredis/phpredis/zip/develop
[root@bogon src]# mv develop phpredis-develop.zip
[root@bogon src]# unzip phpredis-develop.zip
3.使用phpize命令生成./configure文件,报错autoconf not find,需要安装autoconf包
[root@bogon src]# cd phpredis-develop/ [root@bogon phpredis-develop]# /usr/local/php php/ php7/ [root@bogon 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. [root@bogon phpredis-develop]# yum install -y autoconf
4.再次执行命令成功
[root@bogon phpredis-develop]# /usr/local/php/bin/phpize Configuring for: PHP Api Version: 20131106 Zend Module Api No: 20131226 Zend Extension Api No: 220131226 [root@bogon phpredis-develop]#
5.编译
[root@bogon phpredis-develop]# ./configure --with-php-config=/usr/local/php/bin/php-config
6.make && make install 生成redis.so模块
[root@bogon phpredis-develop]# make install Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20131226/ [root@bogon phpredis-develop]# ls /usr/local/php/lib/php/extensions/no-debug-zts-20131226/ opcache.so redis.so [root@bogon phpredis-develop]#
7.查看php支持的全部扩展模块
[root@bogon phpredis-develop]# /usr/local/php/bin/php -m|grep redis
8.查看下php的扩展模块放在哪里,默认存放路径不用改。
[root@bogon 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 [root@bogon phpredis-develop]#
9.将redis.so模块添加到php.ini配置文件中
[root@bogon phpredis-develop]# vim /usr/local/php/etc/php.ini
10.加载成功
[root@bogon phpredis-develop]# /usr/local/php/bin/php -m |grep redis redis [root@bogon phpredis-develop]#
11.编译的php本身自带的模块(php源码包中ext文件夹下的)zip
[root@bogon /]# cd /usr/local/src/php-5.6.30/ext/ [root@bogon ext]# ls bcmath ext_skel intl opcache pgsql soap xml bz2 ext_skel_win32.php json openssl phar sockets xmlreader calendar fileinfo ldap pcntl posix spl xmlrpc com_dotnet filter libxml pcre pspell sqlite3 xmlwriter ctype ftp mbstring pdo readline standard xsl curl gd mcrypt pdo_dblib recode sybase_ct zip date gettext mssql pdo_firebird reflection sysvmsg zlib dba gmp mysql pdo_mysql session sysvsem dom hash mysqli pdo_oci shmop sysvshm enchant iconv mysqlnd pdo_odbc simplexml tidy ereg imap oci8 pdo_pgsql skeleton tokenizer exif interbase odbc pdo_sqlite snmp wddx [root@bogon ext]#
[root@bogon ext]# /usr/local/php/bin/php -m |grep zip #查看是否有zip模块 [root@bogon ext]# cd zip/ [root@bogon zip]# ls config.m4 CREDITS lib php_zip.c tests zip_stream.c config.w32 examples LICENSE_libzip php_zip.h TODO [root@bogon zip]# /usr/local/php/bin/phpize Configuring for: PHP Api Version: 20131106 Zend Module Api No: 20131226 Zend Extension Api No: 220131226 [root@bogon zip]#
[root@bogon zip]# ./configure --with-php-config=/usr/local/php/bin/php-config
[root@bogon zip]# ls /usr/local/php/lib/php/extensions/no-debug-zts-20131226/ opcache.so redis.so zip.so [root@bogon zip]#