在线编辑php.ini并且修改后无需任何操作配置会生效

**1.**下载安装inotify (监控文件)

服务器上安装inotify,执行如下命令
wget https://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
tar xzvf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14
./configure
make
make install
cd ..
安装完毕 建立软连接
ln -s /usr/local/lib/libinotifytools.so.0 /usr/lib64/libinotifytools.so.0

**2.**设置脚本,文件修改时php-fpm自动重启

在代码发布服务器上以root身份创建inotify_rsync.sh脚本
mkdir /root/script
vi /root/script/inotify_rsync.sh 输入如下代码:
#!/bin/sh
SRC=/usr/local/php/etc/php.ini   #代码发布服务器目录
/usr/local/bin/inotifywait -mrq --timefmt '%Y-%m-%d %H:%M' --format '%T %w%f %e' --exclude "(.swp|.swx|.svn)" \
-e create,move,delete,close_write,attrib $SRC | while read files
do
	service php-fpm restart
done

然后赋予脚本可执行权限
chmod +x /root/script/inotify_rsync.sh
设置开机自启动 echo "/root/inotify_rsync.sh &" >> /etc/rc.local
执行脚本/root/script/inotify_rsync.sh &

**3.**给php.ini可执行权限。还要再/usr/local/nginx/conf/fastcgi.conf中加入php.ini的路由或直接加上usr。

**4.**建一个php文件,读取php.ini并展示在文本框中,代码如下:

<?php
$handle = fopen("/usr/local/php/etc/php.ini", "rb");
//$handle = fopen("./hh.php","rb");
$contents = '';
while (!feof($handle)) {
  $contents .= fread($handle, 8192);
}
fclose($handle);
?>
<html>
        <form action="./put.php" method="post"
                <textarea style="width:800px;height:550px;" name="file" ><?php echo $contents; ?> </textarea>
<button type='submit'>
    保存
</button>
        </form>
</html>

**5.**建另一个php文件接受文本框数据,例如put.php如下:


<?php
$file=$_POST['file'];
$res=file_put_contents('/usr/local/php/etc/php.ini',$file);
if($res){
        echo '修改成功';


}else{
        echo '修改失败';
}

猜你喜欢

转载自blog.csdn.net/weixin_43184152/article/details/84031874