phpMyAdmin配置与安装 (适用于CentOS7)

一、LNMP或LAMP的配置(phpMyAdmin运行在该架构中)

   注:php-fpm出厂默认使用者和拥有者为apache ,所以相比较来说LAMP更适合。本例以LNMP为架构。

 (1)nginx安装 ,并设置开机自启动

[root@cy-ed03-lvs ~]# yum install nginx -y
[root@cy-ed03-lvs ~]# systemctl enable nginx
[root@cy-ed03-lvs ~]# systemctl start nginx

(2)mysql安装 。

    参考https://blog.csdn.net/Romanticn_chu/article/details/116132816

(3)php安装

[root@cy-ed03-lvs ~]# yum install php php-fpm php-mysql -y

 CentOS7.6安装php版本为5.4.16  而这里php版本必须要在7.0以上,涉及版本升级问题。

   ①、查看当前php版本

[root@cy-ed03-lvs ~]# php -v
PHP 5.4.16 (cli) (built: Apr  1 2020 04:07:17) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

   ②、查看当前 PHP 相关的安装包

[root@cy-ed03-lvs ~]# yum list installed | grep php
php.x86_64                            5.4.16-48.el7                  @base      
php-cli.x86_64                        5.4.16-48.el7                  @base      
php-common.x86_64                     5.4.16-48.el7                  @base      
php-fpm.x86_64                        5.4.16-48.el7                  @base      
php-mysql.x86_64                      5.4.16-48.el7                  @base      
php-pdo.x86_64                        5.4.16-48.el7                  @base 

   ③、更换 RPM 源   (此处只适用于CentOS7。其他版本更新RPM源方法不一致)

[root@cy-ed03-lvs ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
Retrieving https://mirror.webtatic.com/yum/el7/epel-release.rpm
warning: /var/tmp/rpm-tmp.sPIfq2: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY
Preparing...                          ################################# [100%]
	package epel-release-7-13.noarch (which is newer than epel-release-7-5.noarch) is already installed
[root@cy-ed03-lvs ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
Retrieving https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
warning: /var/tmp/rpm-tmp.olTJiE: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:webtatic-release-7-3             ################################# [100%]

  ④、停止相关服务(nginx和php-fpm)

[root@cy-ed03-lvs ~]# systemctl stop nginx
[root@cy-ed03-lvs ~]# systemctl stop php-fpm

  ⑤、删除已经安装的 PHP 相关包

[root@cy-ed03-lvs ~]# yum remove php*
[root@cy-ed03-lvs ~]# yum list installed | grep php
[root@cy-ed03-lvs ~]# 

  ⑥、安装新版本 PHP

[root@cy-ed03-lvs ~]# yum install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml php72w-ldap php72w-mcrypt

  ⑦、重新启动相关服务

[root@cy-ed03-lvs ~]# systemctl restart nginx
[root@cy-ed03-lvs ~]# systemctl restart php-fpm
[root@cy-ed03-lvs ~]# php -v
PHP 7.2.34 (cli) (built: Oct  1 2020 13:37:37) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.34, Copyright (c) 1999-2018, by Zend Technologies

至此,LNMP简易版已搭建完成。

二、phpMyAdmin搭建配置

(1)下载安装包

[root@cy-ed03-lvs ~]# wget https://files.phpmyadmin.net/phpMyAdmin/4.8.3/phpMyAdmin-4.8.3-all-languages.zip -P /tmp
[root@cy-ed03-lvs ~]# cd /tmp
[root@cy-ed03-lvs ~]# unzip phpMyAdmin-* -d /usr/share/nginx/html
[root@cy-ed03-lvs tmp]# cd /usr/share/nginx/html/
[root@cy-ed03-lvs html]# mv phpMyAdmin-* /etc/phpMyAdmin
[root@cy-ed03-lvs html]# cp -r /etc/phpMyAdmin /var/www/html/phpMyAdmin

(2)修改/var/lib/php/session的拥有者和用户组  最后一个/必须存在,不存在会出现访问不了页面的情况

chown -R nginx:nginx /var/lib/php/session/

(3)修改php-fpm配置文件 (vim /etc/php-fpm.d/www.conf) 此处所有选项文件中都存在 ,查找即可

        user = nginx
        group = nginx
        listern = 127.0.0.1:9000
        listern.owner = nginx
        listern.group = nginx

(4)修改phpMyAdmin的拥有者和用户组

[root@cy-ed03-lvs ~]# chown -R nginx:nginx /var/www/html/phpMyAdmin
[root@cy-ed03-lvs ~]# chown -R nginx:nginx /etc/phpMyAdmin

(5)修改nginx配置文件(/etc/nginx/nginx.conf)

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

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

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    #include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /var/www/html/phpMyAdmin;
        # Load configuration files for the default server block.
        #include /etc/nginx/default.d/*.conf;

        location / {
                index   index.php;
        }
        location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
                access_log        off;
                expires           30d;
        }

        location ~ /\.ht {
                deny  all;
        }

        location ~ /(libraries|setup/frames|setup/libs) {
                deny all;
                return 404;
        }

        location ~ \.php$ {
                include /etc/nginx/fastcgi_params;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /var/www/html/phpMyAdmin$fastcgi_script_name;
        }

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }
}

三、成功

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值