• 周五. 10月 7th, 2022

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

LAMP架构三

admin

11月 28, 2021

PHP相关配置

1.查找php配置文件/usr/local/php/bin/php -i或者phpinfo()

[[email protected] 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 [[email protected] 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:一句话木马使用了该函数如果把这个函数禁了,即使上传了木马也没办法解析

[[email protected]n 111.com]# vim /usr/local/php/etc/php.ini 
[[email protected] 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权限

[[email protected] 111.com]# touch /tmp/php_errors.log; chmod 777 /tmp/php_errors.log 

  

[[email protected] 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=
[[email protected] 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 [email protected]
    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>
[[email protected] tmp]# /usr/local/apache2.4/bin/apachectl graceful                 [[email protected] tmp]# 
[[email protected] 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

[[email protected] tmp]# 

PHP扩展模块安装

http://blog.sina.com.cn/s/blog_3dbab2840100uo5l.html

 1.php编译后想增加模块怎么办,下面娓娓道来,以增加redis模块为例

 https://codeload.github.com/phpredis/phpredis/zip/develop

2.解压phpredis包

[[email protected] src]# wget  https://codeload.github.com/phpredis/phpredis/zip/develop
[[email protected] src]# mv develop phpredis-develop.zip
[[email protected] src]# unzip phpredis-develop.zip

3.使用phpize命令生成./configure文件,报错autoconf not find,需要安装autoconf包

[[email protected] src]# cd phpredis-develop/
[[email protected] phpredis-develop]# /usr/local/php
php/  php7/ 
[[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]# yum install -y autoconf

4.再次执行命令成功

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

5.编译

[[email protected] phpredis-develop]# ./configure --with-php-config=/usr/local/php/bin/php-config

6.make && make install 生成redis.so模块

[[email protected] phpredis-develop]# make install
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20131226/
[[email protected] phpredis-develop]# ls /usr/local/php/lib/php/extensions/no-debug-zts-20131226/
opcache.so  redis.so    
[[email protected] phpredis-develop]# 

7.查看php支持的全部扩展模块

[[email protected] phpredis-develop]# /usr/local/php/bin/php -m|grep redis

8.查看下php的扩展模块放在哪里,默认存放路径不用改。

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

9.将redis.so模块添加到php.ini配置文件中

[[email protected] phpredis-develop]# vim /usr/local/php/etc/php.ini

10.加载成功

[[email protected] phpredis-develop]# /usr/local/php/bin/php -m |grep redis
redis
[[email protected] phpredis-develop]#

11.编译的php本身自带的模块(php源码包中ext文件夹下的)zip

[[email protected] /]# cd /usr/local/src/php-5.6.30/ext/
[[email protected] 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
[[email protected] ext]# 
[[email protected] ext]# /usr/local/php/bin/php -m |grep zip #查看是否有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/php/bin/phpize
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
[[email protected] zip]# 
[[email protected] zip]# ./configure --with-php-config=/usr/local/php/bin/php-config
[[email protected] zip]# ls /usr/local/php/lib/php/extensions/no-debug-zts-20131226/
opcache.so  redis.so  zip.so
[[email protected] zip]# 

发表回复

您的电子邮箱地址不会被公开。