1. # /usr/local/php/bin/php -i |grep -i "loaded configuration file"
  2. // 查看PHP配置文件所在位置的命令
  3. // 如果出现PHP warning:的警告信息,就是需要php.ini,找到data.timezone设置
  4. // 将data.timezone = 配置成 data.timezone = Asia/shanghai
  5. # /usr/local/php/bin/php -i |grep -i "loaded configuration file"
  6. Loaded Configuration File => /usr/local/php/etc/php.ini // 加载配置布

1、PHP的disable_functions

image.png

  1. # vim /usr/local/php/etc/php.ini //搜索disable_functions进行编译
  2. 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
  3. # /usr/local/apache2.4/bin/apachectl graceful //重新加载配置服务

2、配置error_log


image.png

  1. # vim /usr/local/php/etc/php.ini
  2. //搜索log_errors修改
  3. log_errors = On
  4. //搜索error_log修改
  5. error_log = /var/log/php/php_errors.log
  6. //搜索error_reporting修改
  7. error_reporing = E_ALL & ~E_NOTICE
  8. // 搜索display_errors修改
  9. display_errors = Off
  10. # mkdir /var/log/php //
  11. # chmod 777 /var/log/php //需要保证PHP的错误日志所在目录存在,并且权限为可写
  12. # /usr/local/apache2.4/bin/apachectl graceful // 重新加载配置服务
  13. // 测试
  14. # vim /data/wwwroot/ww.123.com/test.php //写入内容,故意把结尾去掉
  15. <?php
  16. echo 111
  17. # curl -A "123" -I -x127.0.0.1:80 www.123.com/test.php
  18. HTTP/1.0 500 Internal Server Error
  19. Date: Sat, 22 May 2021 16:10:47 GMT
  20. Server: Apache/2.4.33 (Unix) PHP/5.6.39
  21. X-Powered-By: PHP/5.6.39
  22. Connection: close
  23. Content-Type: text/html; charset=UTF-8
  24. // 出现了状态码500 ,说明我们访问的页面是存在错误的,需要查看php 的错误日志
  25. # cat /var/log/php/php_errors.log //查看错误日志
  26. [26-Nov-2021 11:10:47 Asia/Shanghai] PHP Parse error: syntax error, unexpected end of file, expecting ',' or ';' in /data/wwwroot/www.123.com/test.php on line 3
  27. // 通过日志可以判断是test.php第三行少了分号

3、配置 open_basedir


image.png

  1. # vim /usr/local/php/etc/php.ini //搜索open_basedir 修改
  2. open_basedir = /tmp:/data/wwwroot/www.123.com
  3. # /usr/local/apache2.4/bin/apachectl graceful //重新加载配置服务
  4. # cp /usr/local/apache2.4/htdocs/1.php /data/wwwroot/aming.com/
  5. # curl -x127.0.0.1:80 -I aming.com/1.php
  6. HTTP/1.0 500 Internal Server Error
  7. Date: Sat, 22 May 2021 16:18:42 GMT
  8. Server: Apache/2.4.33 (Unix) PHP/5.6.39
  9. X-Powered-By: PHP/5.6.39
  10. Connection: close
  11. Content-Type: text/html; charset=UTF-8
  12. // 发现aming.com/1.php不能访问,状态码为500,所以查看一下错误日志
  13. # cat /var/log/php/php_errors.log //查看错误日志
  14. [23-May-2021 00:10:47 Asia/Shanghai] PHP Parse error: syntax error, unexpected end of file, expecting ',' or ';' in /data/wwwroot/www.123.com/test.php on line 3
  15. [23-May-2021 00:18:42 Asia/Shanghai] PHP Warning: Unknown: open_basedir restriction in effect. File(/data/wwwroot/aming.com/1.php) is not within the allowed path(s): (/tmp:/data/wwwroot/www.123.com) in Unknown on line 0
  16. [23-May-2021 00:18:42 Asia/Shanghai] PHP Warning: Unknown: failed to open stream: Operation not permitted in Unknown on line 0
  17. [23-May-2021 00:18:42 Asia/Shanghai] PHP Fatal error: Unknown: Failed opening required '/data/wwwroot/aming.com/1.php' (include_path='.:/usr/local/php/lib/php') in Unknown on line 0

4、PHP动态扩展模块安装

image.png

  1. # /usr/local/php/bin/php -m //查看PHP的加载功能模块
  2. [PHP Modules]
  3. bz2
  4. Core
  5. ctype
  6. date
  7. dom
  8. ereg
  9. exif
  10. fileinfo
  11. filter
  12. hash
  13. iconv
  14. json
  15. libxml
  16. mysql
  17. pcre
  18. PDO
  19. pdo_sqlite
  20. Phar
  21. posix
  22. Reflection
  23. session
  24. SimpleXML
  25. SPL
  26. sqlite3
  27. standard
  28. tokenizer
  29. xml
  30. xmlreader
  31. xmlwriter
  32. [Zend Modules]
  33. # cd /usr/local/src/ //进入安装包目录
  34. //下载安装包
  35. # tar zxf redis-2.2.3.tgz //解压安装包
  36. # ls //查看安装包
  37. # cd redis-2.2.3 //进入解压完的文件
  38. # ls
  39. arrays.markdown config.m4 COPYING library.c php_redis.h r
  40. common.h config.w32 CREDITS library.h README.markdown r
  41. # /usr/local/php/bin/phpize //生成configure文件
  42. Configuring for:
  43. PHP Api Version: 20131106
  44. Zend Module Api No: 20131226
  45. Zend Extension Api No: 220131226
  46. \\ 如果报错,yum install -y autoconf
  47. 然后用# /usr/local/php/bin/phpize再次执行
  48. # ./configure --with-php-config=/usr/local/php/bin/php-config //配置php路径
  49. # make && make install //编译和安装
  50. # /usr/local/php/bin/php -i |grep extension_dir //查看扩展模块存放目录
  51. sqlite3.extension_dir => no value => no value //在php.ini中自定义该路径
  52. # ls /usr/local/php/lib/php/extensions/no-debug-zts-20131226
  53. opcache.so redis.so
  54. # vim /usr/local/php/etc/php.ini //增加一行配置 (可以放到文件最后一行)
  55. extension = redis.so
  56. # /usr/local/php/bin/php -m |grep redis //查看是否加载了redis模块
  57. redis
  58. # /usr/local/apache2.4/bin/apachectl graceful //重新加载配置httpd服务