升级系统
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
下载phpMyAdmin
配置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