centos7.4 源码搭建LAMP___PHP配置

学习笔记

1、PHP配置文件所在位置的命令

/usr/local/php/bin/php -i|grep -i "loaded configuration file"

  

2、PHP的disable_functions

2.1、php有许多内置的函数,处于安全把一些存在风险的函数禁掉

vim /etc/php.ini         #这是我php配置文件的位置

搜索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

注:重启httpd服务使其生效

3、配置error_log

vim /etc/php.ini

  搜索log_errors  改成log_errors = On

  搜索error_log    改为error_log = /var/log/php/php_errors.log

  搜索error_reporting 改为 error_reporting = E_ALL & ~E_NOTICE

  搜索display_errors 改为  display_errors = Off

  保存退出


log_errors可以设置on或者off,想让php记录错误日志为on

error_log设定错误日志路径

error_reporting设定错误日志的级别,E_ALL为所有类型的日志,在开发环境下面设置为E_ALL,&为并且,~表示排除

display_errors设置为on 会把错误日志显示在浏览器里,这样不怎么好,所以为off


设置完毕后,要创建错误日志的路径文件

mkdir /var/log/php                            #路径要存在
chmod 777 /var/log/php/                       #给权限
/usr/local/apache2/bin/apachectl graceful     #重新加载

验证:

写个错误的来验证

4、配置open_basedir

4.1、在配置文件里添加

vim /etc/php.ini

   找到open_basedir,改成下面这样(open_basedir可以是多个目录,用 ":" 分隔,限制只在/tmp和/www.cheese.com下)

   

   在配置一台虚拟主机来测试

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/data/wwwroot/shcheese.com"
    ServerName shcheese.com
    ServerAlias www.shcheese.com
    ErrorLog "logs/shcheese.com-error_log"
    CustomLog "logs/shcheese.com-access_log" common
</VirtualHost>
cp /usr/local/apache2/htdocs/1.php /data/wwwroot/shcheese.com/

测试:

4.2、给单个虚拟主机设置open_basedir

vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
    DocumentRoot "/data/wwwroot/www.cheese.com"
    ServerName www.cheese.com
    ServerAlias cheese.com
    php_admin_value open_basedir "/data/wwwroot/www.cheese.com/:/tmp/"
    CustomLog "logs/cheese.com-access_log" common
</VirtualHost>

5、PHP动态扩展模块安装

5.1、首先查看PHP加载理科哪些功能模块

/usr/local/php/bin/php -m

5.2、安装redis扩展模块

下载地址:https://pan.baidu.com/s/1QJP6MBDs_T2-mtD9I1fcMQ 提取码: up28 

传到/usr/local/src/目录下

cd /usr/local/src/                                                #进入目录
unzip phpredis-develop.zip                                        #解压
cd phpredis-develop                                               
/usr/local/php/bin/phpize                                         #生成configure文件
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install

如果/usr/local/php/bin/phpize这步有报错:cannot find autoconf,需要安装autoconf

yum install autoconf -y

查看扩展模块存放目录,可以在php.ini中自定义该路径

/usr/local/php/bin/php -i | grep extension_dir

增加一行配置

vi /etc/php.ini          #根据自己的php.ini路径

  在最后一行添加 extension = redis.so

查看是否加载了redis模块

/usr/local/php/bin/php -m |grep redis

如果需要PHP网站使用redis模块,还需要重启一下httpd服务

以后要增加扩展模块的需求,都可以按照这个方法安装

猜你喜欢

转载自blog.csdn.net/uuicon/article/details/89311126
今日推荐