Centos7.4 源码搭建LAMP___PHP配置

学习笔记

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

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

 

  https://i-blog.csdnimg.cn/blog_migrate/4bac7a2efa2292a1494470d487819131.png

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     #重新加载

 

验证:

写个错误的来验证

https://i-blog.csdnimg.cn/blog_migrate/c47a38d6298afd7765d5afe40c8592a7.png

https://i-blog.csdnimg.cn/blog_migrate/13c70045b60d92eddb9d8a58c294b905.png

 

4、配置open_basedir

4.1、在配置文件里添加

vim /etc/php.ini

 

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

   https://i-blog.csdnimg.cn/blog_migrate/4ee7ba0a4e8bb93b46190e51de3cdca1.png

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

<VirtualHost *:80>
    ServerAdmin admin@linux.com
    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/

 

测试:

https://i-blog.csdnimg.cn/blog_migrate/d73a530140e3ce1f2bf3d404c866ce26.png

 

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服务

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值