zoukankan      html  css  js  c++  java
  • PhpPgAdmin

    1. 安装
    2. 配置
    	2.1 php-pgsql
    	2.2 网络服务器
    		2.2.1 Apache
    		2.2.2 nginx
    	2.3 phpPgAdmin 配置
    3. 访问 phpPgAdmin
    4. 异常
    	4.1 phpPgAdmin首页异常(pgsql)
    	4.2 出于安全原因禁止登录
    	4.3 登陆时报错(adodb.inc.php)
    	4.4 apache异常(php_flag)
    5. (重复内容)前3节内容表格形式
    
    https://wiki.archlinux.org/title/PhpPgAdmin
    https://wiki.archlinux.org/title/PostgreSQL
    phpPgAdmin: 是基于 Web 使用 PHP 前端管理 PostgreSQL 数据库的工具.
    本文记录了2种站点服务器(Apache/nginx)访问PhpPgAdmin站点. 
    前提是这2种站点服务器(Apache/nginx)已经具备了php基本支持,可以访问到(<?php phpinfo();)内容的测试文件:test.php.
    https://szosoft.blogspot.com/2021/06/http-server.html

    1. 安装

    $ sudo pacman -Ss php |grep installed
    extra/php 8.0.6-1 [installed]
    extra/php-fpm 8.0.6-1 [installed]
    extra/php-pgsql 8.0.6-1 [installed: 8.0.7-1]
    extra/php7 7.4.18-1 [installed]
    extra/php7-pgsql 7.4.18-1 [installed]
    community/phppgadmin 7.13.0-2 [installed]

    2. 配置

    2.1 php-pgsql

    编辑/etc/php/php.ini 取消以下行注释, 启用PHP中的pgsql扩展:
    extension=pdo_pgsql
    extension=pgsql

    确保php可访问/etc/webapps. 在/etc/php/php.ini的open_basedir添加必要路径: 
    open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps
    * 注释: 这个步骤我没做, 但后续可正常访问主页. 

    2.2 网络服务器

    2.2.1 Apache

    创建以下配置文件
    /etc/httpd/conf/extra/phppgadmin.conf
    Alias /phppgadmin "/usr/share/webapps/phppgadmin"
    <Directory "/usr/share/webapps/phppgadmin">
        DirectoryIndex index.php
        AllowOverride All
        Options FollowSymlinks
        Require all granted
        # phppgadmin raises deprecated warnings that lead
        # to parsing errors in JS
        php_flag display_startup_errors off
        php_flag display_errors off
        php_flag html_errors off
    </Directory>

    包含到文件 /etc/httpd/conf/httpd.conf:
    # phpPgAdmin configuration
    Include conf/extra/phppgadmin.conf

    默认情况下,每个人都可以看到 phpPgAdmin 页面,要更改此设置,请根据自己的喜好编辑 /etc/httpd/conf/extra/phppgadmin.conf。 
    例如,如果您只想能够从同一台机器访问它,请将 Require all 替换为 Require local。
     

    2.2.2 nginx

    新增配置文件: php_fastcgi.conf, 该文件会被include到下面的配置文件中.
    /etc/nginx/php_fastcgi.conf
    location ~ .php$ {
        # 404
        try_files $fastcgi_script_name =404;
        # default fastcgi_params
        include fastcgi_params;
        # fastcgi settings
        fastcgi_pass      unix:/run/php-fpm/php-fpm.sock;
        fastcgi_index      index.php;
        fastcgi_buffers      8 16k;
        fastcgi_buffer_size    32k;
        # fastcgi params
        fastcgi_param DOCUMENT_ROOT   $realpath_root;
        fastcgi_param SCRIPT_FILENAME   $realpath_root$fastcgi_script_name;
        #fastcgi_param PHP_ADMIN_VALUE   "open_basedir=$base/:/usr/lib/php/:/tmp/";
        #include fastcgi.conf;
    }

    多文件管理站点(建议), 主配置文件只需要包含站点目录即可, 需要几个站点就增加几个站点配置到/etc/nginx/sites-available/目录下, 需要启用/关闭站点只需要创建/删除链接即可.
    $ sudo ln -s /etc/nginx/sites-available/xxx.conf /etc/nginx/sites-enabled/xxx.conf
    $ sudo unlink /etc/nginx/sites-enabled/xxx.conf

    主配置文件: /etc/nginx/nginx.conf; 末尾包含站点目录: 
    http {
        ...
        include sites-enabled/*;
    }

    新建站点配置: /etc/nginx/sites-available/phppgadmin.conf
    server {
        listen       8001;
        listen [::]:8001;
        server_name  localhost;
        #server_name     phppgadmin.<localhost>;
        root    /usr/share/webapps/phppgadmin;
        index   index.php;
        include /etc/nginx/php_fastcgi.conf;
    }

    启用站点
    $ sudo ln -s /etc/nginx/sites-available/phppgadmin.conf /etc/nginx/sites-enabled/phppgadmin.conf
    关闭站点
    $ sudo unlink /etc/nginx/sites-enabled/phppgadmin.conf
    使用单独的 PHP 配置文件设置nginx#FastCGI,如nginx#nginx configuration 所示。
    https://wiki.archlinux.org/title/Nginx#nginx_configuration
    但: 使用phppgadmin.<domain>形式. 作为子域访问, 但在本地不会填server_name, (phppgadmin.<localhost>这个无效);
    所以上面的配置没有改变server_name名, 而使用了不同的listen端口.

    另外, 若只是本地测试一个站点, 可直接编辑配置文件: nginx.conf
    /etc/nginx/nginx.conf
            # phppgadmin +- 20210602
            root    /usr/share/webapps/phppgadmin;
            index   index.php;
            include /etc/nginx/php_fastcgi.conf;
            #location / {
            #    root   /usr/share/nginx/html;
            #    index  index.html index.htm;
            #}

    2.3 phpPgAdmin 配置

    phpPgAdmin 的配置文件位于/etc/webapps/phppgadmin/config.inc.php.
    如果您的 PostgreSQL 服务器在 上localhost,您可能需要编辑以下行:
    $conf['servers'][0]['host'] = ;
    $conf['servers'][0]['host'] = 'localhost';

    3. 访问 phpPgAdmin

    重载 reload, 重启 restart 相关服务 service: ( httpd / nginx ), php-fpm, postgresql
    http://127.0.0.1/
    http://127.0.0.1/test.php
    http://localhost/phppgadmin/
    到此, 正确的账户名(不含postgres)+任意密码(不可空)即可登陆...

    4. 异常

    4.1 phpPgAdmin首页异常(pgsql)

    Your PHP installation does not support the pgsql module. You will need to install, enable, or compile it to use phpPgAdmin.
    您的 PHP 安装不支持 pgsql 模块。 您需要安装、启用或编译它才能使用 phpPgAdmin。

    若test.php OK... 则检查php.ini配置文件, 启用相关模块
    $ sudo pacman -S php-pgsql
    /etc/php/php.ini
    extension=pdo_pgsql
    extension=pgsql

    4.2 出于安全原因禁止登录

    如果额外安全登录是true, 那么 phpPgAdmin 会拒绝没有密码或某些用户名(pgsql, postgres, root, administrator)的登录。
    * 阅读FAQ理解如何更改PostgreSQL的pg_hba.conf以启用密码本地连接后, 再将其设置为false。

    编辑/etc/webapps/phppgadmin/config.inc.php并更改以下行: 
    $conf['extra_login_security'] = true;
    至: 
    $conf['extra_login_security'] = false;

    4.3 登陆时报错(adodb.inc.php)

    Virtual Class -- cannot instantiate
    虚拟类——无法实例化

    $ sudo pacman -Fl phppgadmin |grep adodb.inc.php
    phppgadmin usr/share/webapps/phppgadmin/libraries/adodb/adodb.inc.php
    注释掉adodb.inc.php的这一行 (网上搜索到的方法, 但暂无相关解释)
    //    die('Virtual Class -- cannot instantiate');

    4.4 apache异常(php_flag)

    $ sudo apachectl configtest
    AH00526: Syntax error on line 10 of /etc/httpd/conf/extra/phppgadmin.conf:
    Invalid command 'php_flag', perhaps misspelled or defined by a module not included in the server configuration

    [临时处理,待完善...]注释掉/etc/httpd/conf/extra/phppgadmin.conf的这3个php_flag后...
    $ apachectl configtest
    AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
    Syntax OK

    5. (重复内容)前3节内容表格形式

    name Apache Nginx, nginx-mainline
    http config /etc/httpd/conf/httpd.conf /etc/nginx/nginx.conf
    配置验证 $ apachectl configtest $ sudo nginx -t
    root /srv/http ; ~/public_html /usr/share/nginx/html/
    service httpd.service nginx.service
    http:// http://localhost/
    http://localhost/~tom/
    配置工具:
    https://nginxconfig.io/
    php

    FastCGI
    Php-fpm 启用代理模块: /etc/httpd/conf/httpd.conf
    LoadModule proxy_module modules/mod_proxy.so
    LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
     
    新增配置文件 新增配置文件 php-fpm.conf 包含以下内容: 新增配置文件 php_fastcgi.conf 包含以下内容:
    /etc/httpd/conf/extra/php-fpm.conf
    DirectoryIndex index.php index.html
    <FilesMatch .php$>
    SetHandler "proxy:unix:/run/php-fpm/php-fpm.sock|fcgi://localhost/"
    </FilesMatch>
    /etc/nginx/php_fastcgi.conf
    location ~ .php$ {
    # 404
    try_files $fastcgi_script_name =404;
    # default fastcgi_params
    include fastcgi_params;
    # fastcgi settings
    fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_buffers 8 16k;
    fastcgi_buffer_size 32k;

    # fastcgi params
    fastcgi_param DOCUMENT_ROOT $realpath_root;
    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    #fastcgi_param PHP_ADMIN_VALUE "open_basedir=$base/:/usr/lib/php/:/tmp/";
    #include fastcgi.conf;
    }
    注: sock和fcgi之间不允许有空格!localhost可任意
    更多配置/etc/php/php-fpm.d/www.conf, 但默认设置应该可正常工作。
    包含到主配置 包含在主配置/etc/httpd/conf/httpd.conf的底部:
    Include conf/extra/php-fpm.conf
    包含到站点server块中,
    Include /etc/nginx/php_fastcgi.conf;
    service php-fpm.service
    测试文件
    test.php
    在DocumentRoot目录(例如/srv/http/或~tom/public_html/) 中创建文件:test.php包含:
    <?php phpinfo(); ?>
    要测试 FastCGI 实现, 在root目录(server块的root项)下创建包含如下内容的文件: test.php
    <?php phpinfo();
    测试php http://127.0.0.1/~tom/test.php http://127.0.0.1/test.php
    pgsql
    数据库支持
    php-pgsql
    php7-pgsql
    /etc/php/php.ini 取消以下行注释来启用php的pgsql扩展:
    extension=pdo_pgsql
    extension=pgsql
      (注: 未操作) 确保php可访问/etc/webapps. 在/etc/php/php.ini的open_basedir添加必要路径:
    open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps
    PhpPgAdmin PhpPgAdmin 新建站点配置:
    /etc/httpd/conf/extra/phppgadmin.conf
    新建站点配置:
    /etc/nginx/sites-available/phppgadmin.conf
    新配置
    文件内容
    Alias /phppgadmin "/usr/share/webapps/phppgadmin"
    <Directory "/usr/share/webapps/phppgadmin">
    DirectoryIndex index.php
    AllowOverride All
    Options FollowSymlinks
    Require all granted

    # phppgadmin raises deprecated warnings that lead
    # to parsing errors in JS
    php_flag display_startup_errors off
    php_flag display_errors off
    php_flag html_errors off
    </Directory>
    server {
    listen 8001;
    listen [::]:8001;
    server_name localhost;
    #server_name phppgadmin.<localhost>;
    root /usr/share/webapps/phppgadmin;
    index index.php;
    include /etc/nginx/php_fastcgi.conf;
    }
    包含到主配置 并将其包含在/etc/httpd/conf/httpd.conf:
    Include conf/extra/phppgadmin.conf
    在: /etc/nginx/nginx.conf; 末尾包含站点目录:
    include sites-enabled/*;
      默认情况下,每个人都可以看到 phpPgAdmin 页面,要更改此设置,请根据自己的喜好进行编辑/etc/httpd/conf/extra/phppgadmin.conf。
    例如,如果您只想能够从同一台机器访问它,请将其替换Require all granted为Require local。
    启用站点
    $ sudo ln -s /etc/nginx/sites-available/phppgadmin.conf /etc/nginx/sites-enabled/phppgadmin.conf
    关闭站点
    $ sudo unlink /etc/nginx/sites-enabled/phppgadmin.conf
    phpPgAdmin
    配置
    /etc/webapps/phppgadmin/config.inc.php
    如果您的 PostgreSQL 服务在 上localhost,则需要编辑以下行:
    $conf['servers'][0]['host'] = ;
    改为:
    $conf['servers'][0]['host'] = 'localhost';
    访问   http://localhost/phppgadmin/ http://127.0.0.1:8001/
    sztom osoft@qq.com CC-BY-NC-SA
  • 相关阅读:
    团队项目第二阶段冲刺站立会议07
    Alpha阶段项目总结
    团队项目第二阶段冲刺站立会议06
    团队项目第二阶段冲刺站立会议05
    团队项目第二阶段冲刺站立会议04
    团队项目第二阶段冲刺站立会议03
    团队项目第二阶段冲刺站立会议02
    团队项目第二阶段冲刺站立会议01
    软件测试
    针对各小组提出的意见作答
  • 原文地址:https://www.cnblogs.com/sztom/p/14848987.html
Copyright © 2011-2022 走看看