LAMP环境搭建与配置(九)
二十 PHP相关配置
1)在/data/wwwroot/111.com/目录下写index.php文件,里面写入phpinfo()函数。
<?php
phpinfo();
2)PHP配置文件位置查看命令
[[email protected] /usr/local/src/php-7.1.6]# /usr/local/php/bin/php -i|grep -i "loaded configuration file"
Loaded Configuration File => /usr/local/php/etc/php.ini
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
3)拷贝配置文件,浏览器重新打开页面,发现loaded configuration。
[[email protected] ~]# cd /usr/local/src/php-7.1.6/
[[email protected] /usr/local/src/php-7.1.6]# cp php.ini-development /usr/local/php7/etc/php.ini
[[email protected] /usr/local/src/php-7.1.6]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[[email protected] /usr/local/src/php-7.1.6]# /usr/local/apache2.4/bin/apachectl graceful
3)disable_functions
PHP有诸多内置函数,有些函数比如(exec)会直接调取Linux系统命令,如果开放将会非常危险。因此,基于安全考虑应该把一些存在安全风险的函数禁掉
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
改为off后,warning不再显示。
4)date.timezone
5)error_log,
log_errors=on
display_errors=Off
error_reporting=E_ALL & ~E_NOTICE
6)open_basedir
vim /usr/local/php7/etc/php.ini
open_basedir =/data/wwwroot/111.com:/tmp/
由于限制了只能在/tmp和/data/wwwroot/1111.com下活动,所以状态码为500
错误日志为:
[10-Nov-2017 10:14:53 UTC] PHP Fatal error: Unknown: Failed opening required '/data/wwwroot/111.com/123.php' (include_path='.:/usr/local/php7/lib/php') in Unknown on line 0
7)php_admin_value
二十一 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文件
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
报错 解决:yum install –y autoconf
再次执行/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
[[email protected] /usr/local/src/phpredis-develop]# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20131226/
[[email protected] /usr/local/src/phpredis-develop]# ls /usr/local/php/lib/php/extensions/no-debug-zts-20131226/
opcache.so redis.so
/usr/local/php/bin/php -i |grep extension_dir //查看扩展模块存放目录,我们可以在php.ini中去自定义该路径
vim /usr/local/php/etc/php.ini //增加一行配置(可以放到文件最后一行)
extension = redis.so
也可以在ext里面查找模块进行安装,安装步骤同上,只不过不用下载了。