通过yum安装lnmp-phpmyadmin
一、安装
# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
# yum install nginx php mysql php-mysql mysql-server php-cli php-curl php-fpm php-intl php-mcrypt php-gd php-mbstring php-xml php-dom -y
二、部署mysql-server
# vi /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
log-bin=/var/lib/mysql/mysqld-bin
log-bin-index=/var/lib/mysql/mysqld-bin
innodb_file_per_table
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
# mysql_install_db --defaults-file=/etc/my.cnf
# service mysqld start
# mysql_secure_installation 注意在这里设置数据库root的密码,注意记录
三、部署php
告诉php,socket的具体路径
# vi /etc/php.ini
mysql.default_socket = /var/lib/mysql/mysql.sock
mysqli.default_socket =/var/lib/mysql/mysql.sock
date.timezone = PRC #在946行 把前面的分号去掉,改为date.timezone = PRC
配置php-fpm
/etc/php-fpm.conf #主配置文件
# vim /etc/php-fpm.d/www.conf #编辑
listen = 127.0.0.1:9000 #默认9000<---让php进程监听本机9000端口
user = nginx #修改用户为nginx
group = nginx #修改组为nginx
启动php-fpm服务(其实就是启动php相关进程,接受nginx的请求)
# service php-fpm start
四、配置nginx
简单配置nginx,能够简单运行静态页面
# vim /etc/nginx/nginx.conf
user nginx; #配置用户或者组
worker_processes 1; #允许生成的进程数,默认为1
error_log /var/log/nginx/error.log; #制定日志路径,级别。这个设置可以放入全局块,http块,server块,级别以此为:debug|info|notice|warn|error|crit|alert|emerg
pid /var/run/nginx.pid; #指定nginx进程运行文件存放地址
events {
worker_connections 1024; #最大连接数
}
http { #http块
include /etc/nginx/mime.types; #文件扩展名与文件类型映射表
default_type application/octet-stream; #默认文件类型,默认为text/plain
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; #允许sendfile方式传输文件,可以在http块,server块,location块。
keepalive_timeout 65; #连接超时时间,可以在http,server,location块。
include /etc/nginx/conf.d/*.conf;
}
# service nginx start
测试:访问IP
五、以虚拟主机的形式创建phpmyadmin
网站目录定义在/web/myadmin
# vim /etc/nginx/conf.d/myadmin.conf
server {
listen 8080; #监听端口
server_name php.senduy.xyz; #监听地址
include /etc/nginx/default.d/*.conf;
location / {
root /web/myadmin; #根目录
index index.html index.htm index.php; #增加index.php
}
location ~ \.php$ {
root /web/myadmin;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#变量改为$document_root$fastcgi_script_name
include fastcgi_params;
}
}
#Nginx是通过本机的9000端口将PHP请求转发给PHP的,PHP自己是从本机的9000端口侦听数据,Nginx与PHP通过本机的9000端口完成了数据请求。
建立测试页面:
# vim /web/myadmin/index.php
<?php
phpinfo();
?>
# service nginx restart
测试:访问IP:8080
然后将phpmyadmin的网页文件放入/web/myadmin内
重启服务后再进行访问
六、错误处理
(1)***Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.***
报此错误或者输入账号密码后扔弹回登陆界面,有可能是/var/lib/php的权限问题
# chown nginx:nginx -R /var/lib/php
# service php-fpm restart
(2)phpmyadmin高级功能尚未完全设置部分功能未激活
# vim /web/myadmin/config.inc.php
/* User used to manipulate with storage */
$cfg['Servers'][$i]['controlhost'] = '';
$cfg['Servers'][$i]['controluser'] = 'root';
$cfg['Servers'][$i]['controlpass'] = '123456';
/* Storage database and tables */
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
$cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
$cfg['Servers'][$i]['relation'] = 'pma__relation';
$cfg['Servers'][$i]['table_info'] = 'pma__table_info';
$cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
$cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
$cfg['Servers'][$i]['column_info'] = 'pma__column_info';
$cfg['Servers'][$i]['history'] = 'pma__history';
$cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
$cfg['Servers'][$i]['tracking'] = 'pma__tracking';
$cfg['Servers'][$i]['designer_coords'] = 'pma__designer_coords';
$cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
$cfg['Servers'][$i]['recent'] = 'pma__recent';
/* Contrib / Swekey authentication */
$cfg['Servers'][$i]['auth_swekey_config'] = '/etc/swekey-pma.conf';
打开这些选项
(3)使用配置文件中定义的控制用户连接失败
# vim /web/myadmin/config.inc.php
$cfg['Servers'][$i]['controluser'] = '';
$cfg['Servers'][$i]['controlpass'] = '';
将其改成你的数据库用户和密码,保存文件;
# chkconfig mysqld on
# chkconfig nginx on
# chkconfig php-fpm on
操作过程中先是忘记关selinux,然后各种权限问题