Centos7安装phpMyAdmin(nginx+php-fpm)

11 篇文章 0 订阅

升级系统

sudo yum update -y

安装高版本的nginx

参考:Install nginx 1.8 on Centos 7

wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install nginx

安装高版本的mysql

安装步骤参考:How To Install MySQL on CentOS 7,具体版本根据最新版本确定

安装高版本的PHP

参考:CentOS7安装高版本的php

下载phpMyAdmin

phpMyAdmin - Downloads

配置nginx

如果你拥有很多域名,可以放在根目录下,使用下面的配置就可以了

    location / {
        location ~ ^/(.+\.php)$
        {
            root /usr/share/nginx/phpMyAdmin-5.0.4;
            index index.php;
            fastcgi_pass unix:/run/php-fpm/www.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
        location ~* ^/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
            root /usr/share/nginx/phpMyAdmin-5.0.4;
        }
    }

如果你域名不多,主站已经使用其他用途,需要把网站放在子目录下,使用如下配置

    location /phpmyadmin {
        root /usr/share/nginx/;
        index index.php index.html index.htm;
        location ~ ^/phpmyadmin/(.+\.php)$ {
            try_files $uri =404;
            fastcgi_pass unix:/run/php-fpm/www.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include /etc/nginx/fastcgi_params;
        }

        location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
            root /usr/share/nginx/;
        }
    }

一个非常重要的技巧

如果你的文件目录由于打错字或其他原因,没放对正确的目录,会导致nginx报错,而且你又不知道错误的目录是哪里弄错了,比方说出现如下错误:

 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream

这时想通过nginx的access.log查看访问路径,里面的内容是

 *1 open() "/usr/share/nginx/phpmyadmin" failed (2: No such file or directory)

这时感觉知道原因,但不知道错误在哪里,那解决方法来了!!!!我们需要修改access.log访问的输出格式,以便了解错误在哪里,修改nginx.conf文件,重要就是添加 'script: d o c u m e n t r o o t document_root documentrootfastcgi_script_name ’ 这一段,使访问日志添加脚本的详细位置

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      'script:$document_root$fastcgi_script_name '
                      '"$http_user_agent" "$http_x_forwarded_for"';
   .....
}

如果这时候你还查不出问题在哪里,那老天保佑了

附加的一个技巧

由于你下载的phpMyAdmin版本比较多,想多个测试,如果每个都要拷贝进/usr/share/nginx/phpmyadmin这个目录里面,这是比较麻烦的,这时可以用软链接来解决,请参考:centos7 软链接的创建,删除,修改,我的链接路径是:

ln -s /usr/share/nginx/phpMyAdmin-5.0.4 /usr/share/nginx/phpmyadmin
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值