Home > Backend Development > PHP Tutorial > Nginx服务器上安装并配置PHPMyAdmin的教程_PHP

Nginx服务器上安装并配置PHPMyAdmin的教程_PHP

WBOY
Release: 2016-05-30 08:47:01
Original
903 people have browsed it

一、 准备工作:

1. 如果mysql的root账号为空,需要设置root密码
CentOS下默认安装的mysql服务器,里面的root账号默认密码为空,首先为root设置一个密码
#mysqladmin -u root password yourpassword

*注: 虽然通过一些特殊配置,可以使phpmyadmin允许空密码登录,但是不推荐这样做,尤其是公网的服务器。

2. 设置php.ini正确配置session.save_path

1). 首先检查php.ini配置文件

#grep session.save_path /etc/php.ini

Copy after login

如果不存在以下设置,增加该配置。如果被注释了话,去掉注释

session.save_path = “/var/lib/php/session”
Copy after login

2). 查看该目录是否存在:

#ls /var/lib/php/session

Copy after login

如果不存在,则手工创建

#mkdir /var/lib/php/session
Copy after login

# 修改目录属主为nginx

chown nginx:nginx session/ -R
Copy after login

# 重启启动php-fpm

service php-fpm restart
Copy after login

二、安装配置phpmyadmin

1. 下载并解压到phpmyadmin
官方下载页面:http://www.phpmyadmin.net/home_page/downloads.php
(中文用户应该选择下载all-languages版本)

下载完成后,解压:

unzip phpMyAdmin-4.1.12-all-languages.zip
Copy after login

移动到相应的目录位置,并改成容易访问的名称:

mv phpMyAdmin-4.1.12-all-languages /www/phpmyadmin
Copy after login

2. 配置phpmyadmin

复制一份配置文件:

#cd /www/phpmyadmin
#cp config.sample.inc.php config.inc.php

Copy after login

配置config.inc.php

#vi config.inc.php
Copy after login

设置一个内部使用的秘钥(和内部加密有关,与页面登录没有直接关系)

$cfg['blowfish_secret'] = ‘www.tudaxia.com';
Copy after login

三、配置Nignx下的站点

vi /etc/nginx/conf.d/phpmyadmin.conf

Copy after login

server {
 listen 8081;
 server_name localhost;
 access_log /var/log/nginx/phpmyadmin-access.log main;

 location / {
  root /www/phpmyadmin;
  index index.php;
 }

 location ~ \.php$ {
  root /www/phpmyadmin;
  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;
 }

 location ~ /\.ht {
  deny all;
 }
}

Copy after login

重启nginx:

#service nginx restart
Copy after login

完成安装,访问http://yourserver:8081/,测试phpmyadmin。

四、phpmyadmin加载缓慢的解决方法


phpmyadmin4.0系列通通加载缓慢的最终原因是最近phpmyadmin的官网经常打不开,而phpmyadmin页面会自动检查官网上的程序 版本更新,所以当你进入phpmyadmin管理页面点击数据库的时候phpmyadmin一直在尝试连接官网从而把整个打开过程拖得很慢。

最终的解决办法是不让phpmyadmin检查更新,找到phpmyadmin目录下version_check.php文件,具体修改如下:

if (isset($_SESSION['cache']['version_check'])
  && time() < $_SESSION['cache']['version_check']['timestamp'] + 3600 * 6
) {
  $save = false;
  $response = $_SESSION['cache']['version_check']['response'];
} else {
//  $save = true;
//  $file = 'http://www.phpmyadmin.net/home_page/version.json';
//  if (ini_get('allow_url_fopen')) {
//    $response = file_get_contents($file);
//  } else if (function_exists('curl_init')) {
//    $curl_handle = curl_init($file);
//    curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
//    $response = curl_exec($curl_handle);
//  }
}

Copy after login

上面代码是通过注释掉else{......}中间这段来取消phpmyadmin连接官网version.json来检查更新

修改完后phpmyadmin马上又回到秒开了。

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template