兆理大数据工具套装
CentOS 7 安装 php-fpm和phpMyAdmin

安装新版php-fpm仓库

$ yum install epel-release
# Remi Dependency on CentOS 7 and Red Hat (RHEL) 7
$ rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
$ rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

检查php-fpm版本,确保是最新稳定版

$ yum --enablerepo=remi,remi-php73 list php php-fpm

安装php-fpm

$ yum --enablerepo=remi,remi-php73 install php php-fpm

安装php相关组件

$ yum --enablerepo=remi,remi-php73 install php-common php-opcache php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-gd php-mbstring php-mcrypt php-xml

检查phpMyAdmin版本,确保是最新稳定版

$ yum list phpmyadmin

安装phpMyAdmin

$ yum --enablerepo=remi,remi-php73 install phpmyadmin

配置php

编辑/etc/php.ini

# 去掉 cgi.fix_pathinfo 前面的注释,修改值为0
cgi.fix_pathinfo=0
# 修改session保存路径,修改到自己希望的路径
session.save_path = "/data/sessions"

编辑/etc/php-fpm.d/www.conf

user = nginx
group = nginx
# 注释掉 listen = 127.0.0.1:9000
listen = /var/run/php-fpm/php-fpm.sock
access.log = /var/log/$pool.access.log
php_value[session.save_path]    = /data/sessions
# 以下可改可不改
listen.owner = nginx
listen.group = nginx
listen.mode = 0660

配置phpMyAdmin

编辑 /etc/phpMyAdmin/config.inc.php

$cfg['Servers'][$i]['host'] = 数据库IP

创建软链接

$ mkdir -p /data/www
$ ln -s /usr/share/phpMyAdmin /data/www/pma

配置nginx

设置密码认证

$ openssl passwd
# 输出一串字符串,复制好
$ vi /etc/nginx/pma_pass
swk:密码字符串

配置conf文件

server {
    listen       80;
    server_name  test.pma.mygear.ltd;

    charset utf-8;
    access_log  /var/log/nginx/test.pma.access.log  main;
    error_log  /var/log/nginx/test.pma.error.log;

    root   /data/www/pma;
    index  index.php index.html index.htm;

    auth_basic "User Auth";
    auth_basic_user_file /etc/nginx/pma_pass;

    #error_page  404              /404.html;
    location / {
        try_files $uri $uri/ =404;
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        #root           html;
        fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 256 4k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny  all;
    }
}

设置自启动

$ systemctl enable php-fpm
$ systemctl enable nginx

各种可能出现的坑

永恒重点注意

权限!权限!权限!
以下目录的权限必须注意

/etc/phpMyAdmin

$ sudo chgrp -R nginx /etc/phpMyAdmin

/data/www/pma

$ sudo chown -R nginx:nginx /data/www/pma

/data/sessions

$ mkdir -p /data/sessions
$ sudo chown -R nginx:nginx /data/sessions
$ sudo chmod 777 /data/sessions

/var/lib/phpMyadmin

$ sudo chown -R nginx:nginx /var/lib/phpMyAdmin/

确保 /var/run/php-fpm/php-fpm.sock存在

有问题的时候查找log

$ cat /var/log/www.access.log

参考资料

https://www.if-not-true-then-false.com/2011/install-nginx-php-fpm-on-fedora-centos-red-hat-rhel/

https://churrops.io/2018/08/24/nginx-php-fpm-7-2-no-centos-7/

https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-phpmyadmin-with-nginx-on-a-centos-7-server

https://linuxize.com/post/how-to-install-phpmyadmin-with-nginx-on-centos-7/

这篇内容的评论功能已被禁用